Skip to content

Agregar grafo interactivo de previas en planificador y menú#980

Draft
RenzoMinelli wants to merge 5 commits intomasterfrom
rm/add-graphs
Draft

Agregar grafo interactivo de previas en planificador y menú#980
RenzoMinelli wants to merge 5 commits intomasterfrom
rm/add-graphs

Conversation

@RenzoMinelli
Copy link
Copy Markdown
Collaborator

@RenzoMinelli RenzoMinelli commented Jan 25, 2026

Qué se hizo?

Se agregó una visualización interactiva de grafos de dependencias de materias usando Cytoscape.js, accesible desde dos lugares:

  1. Menú principal → "Grafo de Dependencias" (muestra la malla curricular sugerida agrupada por semestre)
  2. Planificador → Ícono de grafo en el header (muestra las materias planificadas agrupadas por semestre del plan)

Funcionalidad

Interacciones:

  • Click/tap en una materia: selecciona el nodo y resalta visualmente toda la cadena de previas (borde ámbar) y dependientes (borde violeta), atenuando los nodos no relacionados. Muestra un tooltip con link a "Ver detalles"
  • Segundo click/tap: navega a la página de detalle de la materia
  • Click en fondo: deselecciona
  • Hover (desktop): borde sutil y resaltado leve de nodos conectados

Visual:

  • Nodos coloreados por estado: no disponible (gris), disponible (azul), completada (verde)
  • Flechas entre nodos indicando relaciones de previas
  • Transiciones animadas en cambios de estado
  • Headers de semestre que se reposicionan con pan/zoom
  • Leyenda con colores de estado e indicadores de resaltado (Previa/Dependiente)

Responsive:

  • Desktop: columnas por semestre con zoom y pan
  • Mobile: grilla de 2 columnas con scroll vertical
  • Recalcula layout al cambiar de breakpoint (resize)

Arquitectura

  • SubjectGraphComponent (ViewComponent): construye nodos, aristas y labels desde el modelo de datos
  • subject_graph_controller.js (Stimulus): renderiza el grafo con Cytoscape.js
  • Planner::GraphsController: materias planificadas del usuario
  • Subjects::GraphsController: materias de la malla curricular filtradas por categoría
  • CSS para tooltip y headers en application.css

Tests (24 specs)

  • Component specs (11): serialización de nodos, extracción de aristas desde previas (subject, logical/AND, externas), generación de labels de semestre, estado vacío
  • System specs - Planner Graph (6): renderizado con materias planificadas, aristas, estado vacío, leyenda, instrucciones, marcado de disponibilidad
  • System specs - Subjects Graph (7): filtrado por categoría (simple, múltiple), aristas, estado vacío, leyenda completa, instrucciones, disponibilidad por aprobaciones

Por qué?

Visualizar las previas como un grafo interactivo es una forma más intuitiva de entender las cadenas de dependencias entre materias. El click para resaltar la cadena completa de previas y dependientes facilita la planificación de la carrera.

Fix incluido

  • Corregido current_degreecurrent_degree_plan en Subjects::GraphsController (método no existía)

Copy link
Copy Markdown
Member

@nicolastemciuc nicolastemciuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Es una buena oportunidad para poner el grafo de dependencias en el show de las subjects, tal vez reemplazando el que tenemos:

Image

Comment thread config/importmap.rb Outdated
Comment on lines +18 to +19
pin "cytoscape", to: "https://esm.sh/cytoscape@3.30.4"
pin "cytoscape-dagre", to: "https://esm.sh/cytoscape-dagre@2.5.0?deps=cytoscape@3.30.4"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mejor utilizar bin/importmap pin para que lo guarde en vendor/javascript

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lo hice en 890c6a8, ejecute:

bin/importmap pin cytoscape
bin/importmap pin cytoscape-dagre

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tuve que revertir los cambios porque ya no funcionaba el renderizado. Charlando con claude me dijo esto:

The vendored dagre.js has relative imports to internal chunk files that don't exist:

  - dagre.js line 3: import{_ as o,a as r,b as a,c as t}from"./_/1113443d.js"
  - graphlib.js line 3: import{_ as e,a as r}from"./_/75cd5a64.js" and import a from"./lib/index.js" and import o from"./lib/alg/index.js"

  These are internal jspm chunk files that were not downloaded by bin/importmap pin. The vendor/javascript/_/ and vendor/javascript/lib/ directories don't exist. So the browser fails to resolve these imports,
   the dagre layout never registers with cytoscape, and nodes aren't rendered (cytoscape can't lay them out).

  Phase 2: Pattern Analysis - The previous approach using esm.sh CDN worked because esm.sh bundles all dependencies together. The bin/importmap pin approach downloads from jspm.io, which splits packages into
  chunks with relative imports that importmap-rails can't resolve.

  This is a known limitation of bin/importmap pin with complex packages that have deep dependency trees. The dagre/graphlib ecosystem has too many internal modules for importmap to handle cleanly.

Y es verdad, en los archivos que se generaron en vendor hay dependencias a archivos que no se instalaron

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Termine sacando la dependencia a dagre asi que podemos usar importmaps, lo actualice en 6d4bb60

Comment thread app/views/planner/graphs/show.html.erb Outdated
Comment on lines +4 to +7
<%= link_to subject_plans_path, class: "text-gray-500 hover:text-primary flex items-center gap-1 text-sm" do %>
<%= material_icon("arrow_back", "text-base") %>
Volver al planificador
<% end %>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Siento que este botón no encaja con el resto de la app, no tenemos botones de navegación por lo general :\

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decis que mejor lo saco nomas?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lo saque en e511be6

Comment thread app/views/subjects/graphs/show.html.erb Outdated
Comment on lines +4 to +7
<%= link_to root_path, class: "text-gray-500 hover:text-primary flex items-center gap-1 text-sm" do %>
<%= material_icon("arrow_back", "text-base") %>
Volver
<% end %>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lo mismo aca

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lo saque en e511be6

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creo que estaría bueno aclarar que es el grafo de la curricula sugerida

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actualize el titulo en 1dfd16e

@RenzoMinelli
Copy link
Copy Markdown
Collaborator Author

Es una buena oportunidad para poner el grafo de dependencias en el show de las subjects, tal vez reemplazando el que tenemos:

Image

Para mi esto se puede hacer como otro esfuerzo, el grafo que generamos en este PR es solo dependencies de subject y no include creditos y negaciones como la data que mostramos en el show.

@RenzoMinelli RenzoMinelli force-pushed the rm/add-graphs branch 4 times, most recently from dc3dd5d to 6d4bb60 Compare February 16, 2026 03:08
RenzoMinelli and others added 5 commits March 8, 2026 16:18
Pin cytoscape@3.33.1 via importmaps for rendering subject
dependency graphs with interactive nodes and edges.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- SubjectGraphComponent builds nodes (with availability/completion
  status), edges (from prerequisite trees), and semester labels
- Planner::GraphsController shows planned subjects grouped by
  user-defined semesters
- Subjects::GraphsController shows curriculum subjects filtered
  by category
- Add routes: planner/graph and subjects/graph

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Stimulus controller renders subject dependency graphs using Cytoscape.js
with semester-grouped columns (desktop) or 2-column grid (mobile).

Interactions:
- Click a subject to highlight its prerequisite chain (amber) and
  dependents (violet), dimming unrelated nodes
- Click again to navigate to the subject detail page
- Hover (desktop) shows subtle border and connected edges
- Click background to deselect
- Tooltip with "Ver detalles" link appears on selection
- Debounced resize handler rebuilds layout on breakpoint change

Visual:
- Three-state nodes: unavailable (gray), available (blue), completed (green)
- Animated transitions on node/edge state changes
- Semester headers that reposition on pan/zoom
- Legend with state colors and highlight indicators

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add "Grafo de Dependencias" to the drawer menu (first 9 semesters)
- Add graph icon link in the planner header

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Component specs (11):
- Node data serialization (id, code, name, url, availability)
- Edge extraction from prerequisites (subject, logical/AND, external)
- Semester label generation (curriculum categories, planner map)
- Empty state handling

System specs - Planner Graph (6):
- Graph rendering with planned subjects and edges
- Empty state with link to add subjects
- Legend with highlight indicators (Previa, Dependiente)
- Interaction instructions text
- Available subject marking

System specs - Subjects Graph (7):
- Category filtering (single, multiple)
- Edge rendering within filtered subjects
- Empty state when no categories
- Full legend display (all 5 indicators)
- Interaction instructions text
- Available subjects based on user approvals

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@RenzoMinelli RenzoMinelli changed the title Agregar grafo de previas en planer y menu Agregar grafo interactivo de previas en planificador y menú Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants