@yuneta/gobj-ui 7.31.1 → 7.31.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -658,7 +658,7 @@ SDATA(data_type_t.DTP_BOOLEAN, "with_treedb_tables", 0, false, "Include tre
658
658
  SDATA(data_type_t.DTP_BOOLEAN, "with_gridline", 0, true, "Use gridline plugin"),
659
659
  SDATA(data_type_t.DTP_BOOLEAN, "with_fullscreen", 0, true, "Use fullscreen plugin"),
660
660
  SDATA(data_type_t.DTP_BOOLEAN, "with_toolbar", 0, true, "Use toolbar plugin"),
661
- SDATA(data_type_t.DTP_INTEGER, "minimap_min_nodes", 0, 30, "Show the minimap from this many nodes on (0 = never). A minimap of a graph that fits on screen is decoration; one of two hundred cards is the only way to know where you are"),
661
+ SDATA(data_type_t.DTP_INTEGER, "minimap_min_nodes", 0, 10, "Show the minimap from this many nodes on (0 = never). A minimap of a graph that fits on screen is decoration; one of two hundred cards is the only way to know where you are. 10, not 30: a row of 26 cards already runs off both sides of the screen"),
662
662
  SDATA(data_type_t.DTP_STRING, "toolbar_position", 0, "right-top",
663
663
  "Toolbar position: top-left, top-right, bottom-left, bottom-right, left-top, right-top"),
664
664
  SDATA(data_type_t.DTP_LIST, "layout_names", sdata_flag_t.SDF_RD,
@@ -765,6 +765,8 @@ let PRIVATE_DATA = {
765
765
  _link_saved_styles: [], // saved port styles to restore on cancel
766
766
  _focus_topic: null, // topic currently focused (EV_FOCUS_TOPIC)
767
767
  _focus_ids: [], // node ids carrying the focus 'active' state
768
+ _lit_edge_id: null, // the edge lit by a click (not in edition)
769
+ _lit_ids: [], // ...and its two ends, painted like a find match
768
770
  _on_pointerdown_focus: null, // listener keeping the keyboard on the canvas
769
771
  _on_native_contextmenu: null, // listener keeping the browser's menu out
770
772
  _uninstall_long_press: null, // touch door to the context menu
@@ -1237,6 +1239,18 @@ function build_graph(gobj)
1237
1239
  startArrow: true, // HACK target/source interchanged
1238
1240
  endArrow: false,
1239
1241
  },
1242
+ /* An edge lit by a click (light_edge): the amber of a find
1243
+ * match, its two ends painted with it. A callback, so a
1244
+ * theme switch repaints it in the other scheme's amber. */
1245
+ state: {
1246
+ lit: () => ({
1247
+ stroke: highlight_color(priv.theme),
1248
+ lineWidth: 3,
1249
+ halo: true,
1250
+ haloStroke: highlight_halo(priv.theme),
1251
+ haloLineWidth: 8,
1252
+ }),
1253
+ },
1240
1254
  },
1241
1255
 
1242
1256
  plugins: [],
@@ -2081,6 +2095,7 @@ function configure_behaviour(gobj)
2081
2095
  break;
2082
2096
  case "edition":
2083
2097
  priv.edit_mode = true;
2098
+ unlight_edge(gobj); /* edition SELECTS an edge instead */
2084
2099
  behaviors = [
2085
2100
  /* Panning gives way while Shift is held: that is the
2086
2101
  * marquee's gesture, and G6 binds drag-canvas straight
@@ -8190,6 +8205,97 @@ function node_innerHTML_of(nd, theme, highlight, selected, anchored, pills_html)
8190
8205
  return null;
8191
8206
  }
8192
8207
 
8208
+ /************************************************************
8209
+ * The cards painted with the highlight: a find or topic focus
8210
+ * (`_focus_ids`) and the two ends of a lit edge (`_lit_ids`).
8211
+ * Kept apart so that lighting an edge does not erase a find,
8212
+ * and a find does not put out an edge.
8213
+ ************************************************************/
8214
+ function highlighted_ids(gobj)
8215
+ {
8216
+ let priv = gobj.priv;
8217
+ return new Set([...(priv._focus_ids || []), ...(priv._lit_ids || [])]);
8218
+ }
8219
+
8220
+ /************************************************************
8221
+ * Light an edge: the edge itself and its two ends, so a click
8222
+ * on a line says which two records it joins. A second click on
8223
+ * the same edge, or a click on the canvas, puts it out.
8224
+ *
8225
+ * Not in edition: there a click SELECTS the edge, with its own
8226
+ * ring and its affordances (select_edge).
8227
+ ************************************************************/
8228
+ function light_edge(gobj, edge_id)
8229
+ {
8230
+ let priv = gobj.priv;
8231
+ let graph = priv.graph;
8232
+
8233
+ if(!graph || !edge_id) {
8234
+ return;
8235
+ }
8236
+ let same = (priv._lit_edge_id === edge_id);
8237
+ unlight_edge(gobj);
8238
+ if(same) {
8239
+ return;
8240
+ }
8241
+
8242
+ let ed;
8243
+ try {
8244
+ ed = graph.getEdgeData(edge_id);
8245
+ } catch(e) {
8246
+ log_error(`${gobj_short_name(gobj)}: cannot light the edge ${edge_id}: ${e}`);
8247
+ return;
8248
+ }
8249
+ priv._lit_edge_id = edge_id;
8250
+ priv._lit_ids = [ed.source, ed.target];
8251
+
8252
+ /* The state as data, and ONE draw (repaint_cards'):
8253
+ * setElementState() draws on its own, and two draws race. */
8254
+ try {
8255
+ graph.updateData({edges: [{id: edge_id, states: ['lit']}]});
8256
+ } catch(e) {
8257
+ log_error(`${gobj_short_name(gobj)}: edge state not set: ${e}`);
8258
+ }
8259
+ repaint_cards(gobj, new Set(priv._lit_ids));
8260
+ }
8261
+
8262
+ function unlight_edge(gobj)
8263
+ {
8264
+ let priv = gobj.priv;
8265
+ let graph = priv.graph;
8266
+ let edge_id = priv._lit_edge_id;
8267
+ let ids = priv._lit_ids || [];
8268
+
8269
+ priv._lit_edge_id = null;
8270
+ priv._lit_ids = [];
8271
+
8272
+ if(!graph) {
8273
+ return;
8274
+ }
8275
+ if(edge_id) {
8276
+ let exists = false;
8277
+ try {
8278
+ exists = !!graph.getEdgeData(edge_id);
8279
+ } catch(e) {
8280
+ exists = false; /* folded away since it was lit */
8281
+ }
8282
+ if(exists) {
8283
+ try {
8284
+ graph.updateData({edges: [{id: edge_id, states: []}]});
8285
+ } catch(e) {
8286
+ log_error(`${gobj_short_name(gobj)}: edge state not cleared: ${e}`);
8287
+ }
8288
+ }
8289
+ }
8290
+ if(ids.length) {
8291
+ repaint_cards(gobj, new Set(ids));
8292
+ } else if(edge_id) {
8293
+ graph.draw().catch((e) => {
8294
+ log_error(`${gobj_short_name(gobj)}: redraw failed: ${e}`);
8295
+ });
8296
+ }
8297
+ }
8298
+
8193
8299
  /************************************************************
8194
8300
  * Repaint these cards with the flags they carry RIGHT NOW.
8195
8301
  *
@@ -8208,7 +8314,7 @@ function repaint_cards(gobj, ids)
8208
8314
  return;
8209
8315
  }
8210
8316
 
8211
- let focus = new Set(priv._focus_ids || []);
8317
+ let focus = highlighted_ids(gobj);
8212
8318
  let selected = new Set(priv._selected_paint_ids || []);
8213
8319
 
8214
8320
  let updates = [];
@@ -8285,7 +8391,7 @@ function refresh_html_nodes_theme(gobj, theme)
8285
8391
  /* The highlight is part of the card's html, so a theme switch that
8286
8392
  * rebuilt every card without it would silently CLEAR the focus or the
8287
8393
  * find that is on screen. Carry it across. */
8288
- let highlighted = new Set(priv._focus_ids || []);
8394
+ let highlighted = highlighted_ids(gobj);
8289
8395
  let selected = new Set(priv._selected_paint_ids || []);
8290
8396
  let updates = [];
8291
8397
  for(let i = 0; i < nodes.length; i++) {
@@ -10537,6 +10643,11 @@ async function reconcile_fold_apply(gobj, opts, visible)
10537
10643
  hide_node_detail(gobj);
10538
10644
  }
10539
10645
  priv._focus_ids = (priv._focus_ids || []).filter((id) => !gone.has(id));
10646
+ if((priv._lit_ids || []).some((id) => gone.has(id))) {
10647
+ /* an edge whose end is gone is gone too */
10648
+ priv._lit_edge_id = null;
10649
+ priv._lit_ids = (priv._lit_ids || []).filter((id) => !gone.has(id));
10650
+ }
10540
10651
  priv._selected_paint_ids = (priv._selected_paint_ids || []).filter((id) => !gone.has(id));
10541
10652
  if(priv.anchor_state === "on" && gone.has(priv.anchor_id)) {
10542
10653
  priv.anchor_id = "";
@@ -12311,6 +12422,8 @@ function ac_edge_click(gobj, event, kw, src)
12311
12422
  if(priv.edit_mode) {
12312
12423
  deselect_node(gobj);
12313
12424
  select_edge(gobj, edge_id);
12425
+ } else {
12426
+ light_edge(gobj, edge_id);
12314
12427
  }
12315
12428
  }
12316
12429
  } catch(e) {
@@ -12858,6 +12971,7 @@ function ac_canvas_click(gobj, event, kw, src)
12858
12971
  let priv = gobj.priv;
12859
12972
 
12860
12973
  hide_node_detail(gobj);
12974
+ unlight_edge(gobj);
12861
12975
 
12862
12976
  if(priv._linking_mode) {
12863
12977
  exit_linking_mode(gobj);
@@ -179,7 +179,7 @@ SDATA(data_type_t.DTP_STRING, "yuno_name", 0, "", "remote: the nam
179
179
  SDATA(data_type_t.DTP_STRING, "wide", 0, "40px", "Height of header. 40px and not 36: it is what an untouched Bulma control measures, so the find box stood 4px taller than every button beside it, and it is what the third graph of the family (C_YUI_TREEDB_GRAPH) uses"),
180
180
  SDATA(data_type_t.DTP_STRING, "layout", 0, "vertical-compact", "Current layout key"),
181
181
  SDATA(data_type_t.DTP_INTEGER, "collapse_threshold", 0, 10, "Auto-collapse a node whose direct children exceed this number. 0 disables auto-collapse."),
182
- SDATA(data_type_t.DTP_INTEGER, "minimap_min_nodes", 0, 20, "Show the minimap from this many cards on (0 = never). Lower than the treedb graph's 30: this tree opens at actual size, not fitted, so the reader is past its edge sooner"),
182
+ SDATA(data_type_t.DTP_INTEGER, "minimap_min_nodes", 0, 20, "Show the minimap from this many cards on (0 = never). The treedb graph shows it from 10"),
183
183
 
184
184
  SDATA_END()
185
185
  ];
@@ -122,7 +122,7 @@ SDATA(data_type_t.DTP_INTEGER, "fold_page_size", 0, 24, "Children of one
122
122
  * creates the child, so an option it does not forward is an option that
123
123
  * does not exist. The defaults repeat the child's -- a host that says
124
124
  * nothing gets exactly what it got before. */
125
- SDATA(data_type_t.DTP_INTEGER, "minimap_min_nodes", 0, 30, "Show the minimap from this many nodes on (0 = never). Forwarded to the G6 child"),
125
+ SDATA(data_type_t.DTP_INTEGER, "minimap_min_nodes", 0, 10, "Show the minimap from this many nodes on (0 = never). Forwarded to the G6 child"),
126
126
  SDATA(data_type_t.DTP_BOOLEAN, "with_gridline", 0, true, "Draw the grid under the graph. Forwarded to the G6 child"),
127
127
  SDATA(data_type_t.DTP_BOOLEAN, "with_fullscreen", 0, true, "Offer the full-screen button. Forwarded to the G6 child"),
128
128
  SDATA(data_type_t.DTP_BOOLEAN, "with_toolbar", 0, true, "Float the camera toolbar over the canvas. Forwarded to the G6 child"),
@@ -25,6 +25,14 @@
25
25
  * via the host-supplied `node_route`). An alternate landing to the
26
26
  * topic cards, in the spirit of "every treedb is a graph".
27
27
  *
28
+ * A click on an EDGE lights it: the line in amber, its two cards
29
+ * ringed and the hook row and the fkey row it joins washed, so a
30
+ * line says which two fields it ties. A second click on it, or a
31
+ * click on the canvas, puts it out. The amber is the node graph's
32
+ * find (C_G6_NODES_TREE). And the drawing always carries a
33
+ * MINIMAP (yui_graph_minimap.js): a schema of more cards than the
34
+ * screen holds is the usual case.
35
+ *
28
36
  * The CAMERA is the family's (yui_graph_camera.js): the same
29
37
  * toolbar cluster -- zoom in/out, readout, fit, 1:1 -- and the
30
38
  * same wheel: it SCROLLS, and Ctrl + wheel zooms, over the cards
@@ -58,7 +66,7 @@ import {
58
66
  refresh_language,
59
67
  } from "@yuneta/gobj-js";
60
68
 
61
- import {Graph, NodeEvent} from "@antv/g6";
69
+ import {Graph, NodeEvent, EdgeEvent, CanvasEvent} from "@antv/g6";
62
70
 
63
71
  import {yui_toolbar} from "./yui_toolbar.js";
64
72
  import {
@@ -67,6 +75,7 @@ import {
67
75
  yui_graph_forward_wheel,
68
76
  yui_graph_update_zoom,
69
77
  } from "./yui_graph_camera.js";
78
+ import {yui_graph_minimap_options, yui_graph_minimap_block} from "./yui_graph_minimap.js";
70
79
  import {ensure_drag_canvas_patch} from "./g6_drag_canvas_touch.js";
71
80
  import {ensure_pinch_zoom_patch} from "./g6_touch_gestures.js";
72
81
  import {keep_canvas_tab_order} from "./g6_canvas_tab_order.js";
@@ -108,6 +117,14 @@ const topic_colors = [
108
117
  ];
109
118
  const SYSTEM_TOPIC_COLOR = 'rgb(148, 163, 184)';
110
119
 
120
+ /* The mark of a lit edge and its two ends: the amber of the node
121
+ * graph's find and topic focus (C_G6_NODES_TREE), one per scheme --
122
+ * the dark one is 2.15:1 on white, the burnt one 5.02. */
123
+ const LIT_COLOR_DARK = "#f0a020";
124
+ const LIT_COLOR_LIGHT = "#b45309";
125
+ const LIT_HALO_DARK = "rgba(240,160,32,0.35)";
126
+ const LIT_HALO_LIGHT = "rgba(180,83,9,0.35)";
127
+
111
128
  /***************************************************************
112
129
  * Data
113
130
  ***************************************************************/
@@ -128,6 +145,7 @@ let PRIVATE_DATA = {
128
145
  graph: null,
129
146
  theme_observer: null, // MutationObserver on <html data-theme>
130
147
  unforward_wheel: null, // removes the wheel forwarding of the cards
148
+ lit_edge_id: null, // the edge lit by a click, with its two ends
131
149
  };
132
150
 
133
151
  let __gclass__ = null;
@@ -368,7 +386,7 @@ function row_placement(index, height)
368
386
  * The card itself. Header = topic name on its topic colour;
369
387
  * body = one line per field, in schema order.
370
388
  ************************************************************/
371
- function build_card_innerHTML(topic, rows, color, dark)
389
+ function build_card_innerHTML(topic, rows, color, dark, lit_rows)
372
390
  {
373
391
  let surface = dark? "#1b2230" : "#ffffff";
374
392
  let bg = dark
@@ -389,17 +407,34 @@ function build_card_innerHTML(topic, rows, color, dark)
389
407
  let shadow = dark
390
408
  ? "0 1px 3px rgba(0,0,0,0.45), 0 1px 2px rgba(0,0,0,0.30)"
391
409
  : "0 1px 3px rgba(15,23,42,0.12), 0 1px 2px rgba(15,23,42,0.06)";
410
+ let border_w = "1.5px";
411
+
412
+ /* One end of a lit edge: the card in amber, and the row the edge
413
+ * leaves or lands on washed with it. */
414
+ let lit = lit_rows instanceof Set;
415
+ let lit_color = dark? LIT_COLOR_DARK : LIT_COLOR_LIGHT;
416
+ if(lit) {
417
+ border = lit_color;
418
+ border_w = "3px";
419
+ shadow = `0 0 0 4px ${dark? LIT_HALO_DARK : LIT_HALO_LIGHT}`;
420
+ }
392
421
 
393
422
  let rows_html = "";
394
423
  for(let row of rows) {
395
424
  let lead = row.is_pkey? "#" : (row.required? "*" : "");
396
425
  let name_weight = (row.is_pkey || row.is_pkey2)? "700" : (row.required? "600" : "400");
397
426
  let name_color = (row.is_hook || row.is_fkey)? title_color : text_color;
427
+ let row_bg = "transparent";
428
+ if(lit && lit_rows.has(row.name)) {
429
+ row_bg = `color-mix(in srgb, ${lit_color} ${dark? 35 : 22}%, transparent)`;
430
+ name_weight = "700";
431
+ }
398
432
  rows_html +=
399
433
  ` <div class="TREEDB_SCHEMA_FIELD" style="
400
434
  display: flex; align-items: center; gap: 6px;
401
435
  height: ${CARD_ROW_H}px; line-height: ${CARD_ROW_H}px;
402
436
  padding: 0 10px; border-top: 1px solid ${rule_color};
437
+ background: ${row_bg};
403
438
  ">
404
439
  <span style="
405
440
  width: 8px; flex: 0 0 8px; text-align: center;
@@ -424,7 +459,7 @@ function build_card_innerHTML(topic, rows, color, dark)
424
459
  width: 100%;
425
460
  height: 100%;
426
461
  background: ${bg};
427
- border: 1.5px solid ${border};
462
+ border: ${border_w} solid ${border};
428
463
  border-radius: 8px;
429
464
  box-shadow: ${shadow};
430
465
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
@@ -613,6 +648,176 @@ function edge_style(dark)
613
648
  };
614
649
  }
615
650
 
651
+ /************************************************************
652
+ * The edge options: the style, and the `lit` state of an edge
653
+ * a click lit (light_edge). Both together, because setEdge()
654
+ * REPLACES the options: a theme switch that set only the style
655
+ * would drop the state.
656
+ ************************************************************/
657
+ function edge_options(dark)
658
+ {
659
+ return {
660
+ style: edge_style(dark),
661
+ state: {
662
+ lit: {
663
+ stroke: dark? LIT_COLOR_DARK : LIT_COLOR_LIGHT,
664
+ lineWidth: 3,
665
+ halo: true,
666
+ haloStroke: dark? LIT_HALO_DARK : LIT_HALO_LIGHT,
667
+ haloLineWidth: 8,
668
+ },
669
+ },
670
+ };
671
+ }
672
+
673
+ /************************************************************
674
+ * The rows of `topic` the lit edge touches, as a Set (empty
675
+ * rows still mark the card), or null when the card is not one
676
+ * of its ends.
677
+ ************************************************************/
678
+ function lit_rows_of(gobj, topic)
679
+ {
680
+ let priv = gobj.priv;
681
+ if(!priv.graph || !priv.lit_edge_id) {
682
+ return null;
683
+ }
684
+ let ed;
685
+ try {
686
+ ed = priv.graph.getEdgeData(priv.lit_edge_id);
687
+ } catch(e) {
688
+ return null;
689
+ }
690
+ let style = ed.style || {};
691
+ let rows = null;
692
+ if(ed.source === topic) {
693
+ rows = rows || new Set();
694
+ rows.add(style.sourcePort);
695
+ }
696
+ if(ed.target === topic) {
697
+ rows = rows || new Set();
698
+ rows.add(style.targetPort);
699
+ }
700
+ return rows;
701
+ }
702
+
703
+ /************************************************************
704
+ * Repaint the cards of these topics, lit or not as they are now.
705
+ ************************************************************/
706
+ function repaint_cards(gobj, topics)
707
+ {
708
+ let graph = gobj.priv.graph;
709
+ let dark = yui_is_dark();
710
+ let updates = [];
711
+ for(let topic of topics) {
712
+ let nd;
713
+ try {
714
+ nd = graph.getNodeData(topic);
715
+ } catch(e) {
716
+ continue;
717
+ }
718
+ let data = nd && nd.data;
719
+ if(!is_object(data) || !Array.isArray(data.rows)) {
720
+ continue;
721
+ }
722
+ updates.push({
723
+ id: topic,
724
+ style: {
725
+ innerHTML: build_card_innerHTML(
726
+ data.topic_name, data.rows, data.color, dark,
727
+ lit_rows_of(gobj, topic)
728
+ )
729
+ }
730
+ });
731
+ }
732
+ if(updates.length > 0) {
733
+ graph.updateNodeData(updates);
734
+ }
735
+ }
736
+
737
+ /************************************************************
738
+ * Light an edge: the line, its two cards and the two rows it
739
+ * joins -- a click on a line says which hook it is and which
740
+ * fkey it lands on. A second click on it, or a click on the
741
+ * canvas, puts it out.
742
+ ************************************************************/
743
+ function light_edge(gobj, edge_id)
744
+ {
745
+ let priv = gobj.priv;
746
+ let graph = priv.graph;
747
+ if(!graph) {
748
+ return;
749
+ }
750
+ let same = (priv.lit_edge_id === edge_id);
751
+ unlight_edge(gobj, false);
752
+ if(!same && edge_id) {
753
+ let ed;
754
+ try {
755
+ ed = graph.getEdgeData(edge_id);
756
+ } catch(e) {
757
+ log_error(`${gobj_short_name(gobj)}: cannot light the edge ${edge_id}: ${e}`);
758
+ ed = null;
759
+ }
760
+ if(ed) {
761
+ priv.lit_edge_id = edge_id;
762
+ graph.updateData({edges: [{id: edge_id, states: ["lit"]}]});
763
+ repaint_cards(gobj, new Set([ed.source, ed.target]));
764
+ }
765
+ }
766
+ graph.draw().catch((e) => {
767
+ log_error(`${gobj_short_name(gobj)}: schema graph redraw failed: ${e}`);
768
+ });
769
+ }
770
+
771
+ function unlight_edge(gobj, draw)
772
+ {
773
+ let priv = gobj.priv;
774
+ let graph = priv.graph;
775
+ let edge_id = priv.lit_edge_id;
776
+ if(!graph || !edge_id) {
777
+ priv.lit_edge_id = null;
778
+ return;
779
+ }
780
+ let ed = null;
781
+ try {
782
+ ed = graph.getEdgeData(edge_id);
783
+ } catch(e) {
784
+ ed = null;
785
+ }
786
+ priv.lit_edge_id = null;
787
+ if(!ed) {
788
+ return;
789
+ }
790
+ graph.updateData({edges: [{id: edge_id, states: []}]});
791
+ repaint_cards(gobj, new Set([ed.source, ed.target]));
792
+ if(draw) {
793
+ graph.draw().catch((e) => {
794
+ log_error(`${gobj_short_name(gobj)}: schema graph redraw failed: ${e}`);
795
+ });
796
+ }
797
+ }
798
+
799
+ /************************************************************
800
+ * A card in the minimap: a block of its size in its topic's
801
+ * colour, darkened on the light scheme so a yellow topic does
802
+ * not vanish on the white panel. G6 clones a node's key shape,
803
+ * and the key shape of an html card is a DOM element, which
804
+ * clones into nothing (see yui_graph_minimap.js).
805
+ ************************************************************/
806
+ function minimap_shape(gobj, id, element_type, element)
807
+ {
808
+ if(element_type !== "node") {
809
+ return element; /* edges clone themselves fine */
810
+ }
811
+ try {
812
+ let nd = gobj.priv.graph.getNodeData(id);
813
+ let color = (nd && nd.data && nd.data.color) || SYSTEM_TOPIC_COLOR;
814
+ return yui_graph_minimap_block(nd, yui_is_dark()? color : getStrokeColor(color));
815
+ } catch(e) {
816
+ log_error(`${gobj_short_name(gobj)}: minimap shape failed: ${e}`);
817
+ return element;
818
+ }
819
+ }
820
+
616
821
  /************************************************************
617
822
  * Build the G6 schema graph.
618
823
  ************************************************************/
@@ -644,9 +849,7 @@ function build_graph(gobj)
644
849
  autoResize: true,
645
850
  animation: false,
646
851
  data: data,
647
- edge: {
648
- style: edge_style(dark),
649
- },
852
+ edge: edge_options(dark),
650
853
  layout: {
651
854
  type: "antv-dagre",
652
855
  rankdir: "LR",
@@ -655,6 +858,14 @@ function build_graph(gobj)
655
858
  },
656
859
  /* The family's camera: the wheel scrolls, Ctrl + wheel zooms. */
657
860
  behaviors: ["drag-canvas", ...yui_graph_camera_behaviors(), "drag-element"],
861
+ /* Always: a schema whose cards run off the screen is the
862
+ * common case, and it is the minimap that says where the
863
+ * rest of them are. */
864
+ plugins: [
865
+ {key: "minimap", type: "minimap", ...yui_graph_minimap_options(
866
+ (id, element_type, element) => minimap_shape(gobj, id, element_type, element)
867
+ )},
868
+ ],
658
869
  });
659
870
  } catch(e) {
660
871
  log_error(`${gobj_short_name(gobj)}: schema graph create failed: ${e}`);
@@ -686,6 +897,15 @@ function build_graph(gobj)
686
897
  gobj_send_event(gobj, "EV_NODE_CLICK", {node_id: node_id}, gobj);
687
898
  });
688
899
 
900
+ graph.on(EdgeEvent.CLICK, (evt) => {
901
+ let edge_id = evt && evt.target && evt.target.id;
902
+ gobj_send_event(gobj, "EV_EDGE_CLICK", {edge_id: edge_id}, gobj);
903
+ });
904
+
905
+ graph.on(CanvasEvent.CLICK, () => {
906
+ gobj_send_event(gobj, "EV_CANVAS_CLICK", {}, gobj);
907
+ });
908
+
689
909
  /* No fitView: the diagram is drawn at its own scale and stays there.
690
910
  * Zooming it to the container the moment it appears rewrites the size
691
911
  * the reader just saw, and does it differently for every treedb. */
@@ -702,6 +922,7 @@ function build_graph(gobj)
702
922
  function destroy_graph(gobj)
703
923
  {
704
924
  let priv = gobj.priv;
925
+ priv.lit_edge_id = null;
705
926
  if(priv.unforward_wheel) {
706
927
  priv.unforward_wheel();
707
928
  priv.unforward_wheel = null;
@@ -773,6 +994,28 @@ function ac_node_click(gobj, event, kw, src)
773
994
  return 0;
774
995
  }
775
996
 
997
+ /************************************************************
998
+ * An edge was clicked: light it, or put it out if it was lit.
999
+ ************************************************************/
1000
+ function ac_edge_click(gobj, event, kw, src)
1001
+ {
1002
+ let edge_id = kw && kw.edge_id;
1003
+ if(!edge_id) {
1004
+ return 0;
1005
+ }
1006
+ light_edge(gobj, edge_id);
1007
+ return 0;
1008
+ }
1009
+
1010
+ /************************************************************
1011
+ * A click on the empty canvas puts the lit edge out.
1012
+ ************************************************************/
1013
+ function ac_canvas_click(gobj, event, kw, src)
1014
+ {
1015
+ unlight_edge(gobj, true);
1016
+ return 0;
1017
+ }
1018
+
776
1019
  /************************************************************
777
1020
  * Shown by the host: match the canvas to the container now it
778
1021
  * is visible and sized (G6 renders at 0×0 while display:none).
@@ -814,7 +1057,7 @@ function ac_theme(gobj, event, kw, src)
814
1057
  let dark = (kw && kw.theme) ? (kw.theme === "dark") : yui_is_dark();
815
1058
  try {
816
1059
  graph.setTheme(dark ? "dark" : "light");
817
- graph.setEdge({style: edge_style(dark)});
1060
+ graph.setEdge(edge_options(dark));
818
1061
 
819
1062
  /* A card is HTML, so its colours live in its markup: repaint
820
1063
  * each one from the rows kept in its node data. */
@@ -828,7 +1071,8 @@ function ac_theme(gobj, event, kw, src)
828
1071
  id: node.id,
829
1072
  style: {
830
1073
  innerHTML: build_card_innerHTML(
831
- data.topic_name, data.rows, data.color, dark
1074
+ data.topic_name, data.rows, data.color, dark,
1075
+ lit_rows_of(gobj, node.id)
832
1076
  )
833
1077
  }
834
1078
  });
@@ -939,6 +1183,8 @@ function create_gclass(gclass_name)
939
1183
  const states = [
940
1184
  ["ST_IDLE", [
941
1185
  ["EV_NODE_CLICK", ac_node_click, null],
1186
+ ["EV_EDGE_CLICK", ac_edge_click, null],
1187
+ ["EV_CANVAS_CLICK", ac_canvas_click, null],
942
1188
  ["EV_SHOW", ac_show, null],
943
1189
  ["EV_THEME", ac_theme, null],
944
1190
  ["EV_REBUILD", ac_rebuild, null],
@@ -953,6 +1199,8 @@ function create_gclass(gclass_name)
953
1199
  /* Sent to itself by the graph, and published to the host when no
954
1200
  * `node_route` was given: optional there, so no warning. */
955
1201
  ["EV_NODE_CLICK", event_flag_t.EVF_OUTPUT_EVENT|event_flag_t.EVF_NO_WARN_SUBS],
1202
+ ["EV_EDGE_CLICK", 0],
1203
+ ["EV_CANVAS_CLICK", 0],
956
1204
  ["EV_SHOW", 0],
957
1205
  ["EV_THEME", 0],
958
1206
  ["EV_REBUILD", 0],
@@ -1358,3 +1358,53 @@ describe("a rebuilt toolbar shows what its items were told (fourth pass)", () =>
1358
1358
  expect(shown(drawn, "toolbar-edit", "undo")).toEqual(DARK);
1359
1359
  });
1360
1360
  });
1361
+
1362
+ describe("a click on an edge lights it and its two ends (not in edition)", () => {
1363
+ async function reading()
1364
+ {
1365
+ const b = await build("reading");
1366
+ b.states = [];
1367
+ b.graph.updateData = (data) => {
1368
+ for(const u of (data.edges || [])) {
1369
+ b.states.push([u.id, u.states]);
1370
+ }
1371
+ };
1372
+ return b;
1373
+ }
1374
+
1375
+ test("the edge takes the lit state, its ends are painted, the host still hears the click", async () => {
1376
+ const {tree, states} = await reading();
1377
+ gobj_send_event(tree, "EV_EDGE_CLICK", {id: "e1"}, tree);
1378
+ expect(tree.priv._lit_edge_id).toBe("e1");
1379
+ expect(tree.priv._lit_ids).toEqual(["n1", "n1"]);
1380
+ expect(states).toEqual([["e1", ["lit"]]]);
1381
+ expect(published.map((p) => p.event)).toContain("EV_EDGE_CLICKED");
1382
+ });
1383
+
1384
+ test("a second click on it, or a canvas click, puts it out", async () => {
1385
+ const {tree, states} = await reading();
1386
+ gobj_send_event(tree, "EV_EDGE_CLICK", {id: "e1"}, tree);
1387
+ gobj_send_event(tree, "EV_EDGE_CLICK", {id: "e1"}, tree);
1388
+ expect(tree.priv._lit_edge_id).toBe(null);
1389
+ expect(tree.priv._lit_ids).toEqual([]);
1390
+
1391
+ gobj_send_event(tree, "EV_EDGE_CLICK", {id: "e1"}, tree);
1392
+ gobj_send_event(tree, "EV_CANVAS_CLICK", {}, tree);
1393
+ expect(tree.priv._lit_edge_id).toBe(null);
1394
+ expect(states).toEqual([["e1", ["lit"]], ["e1", []], ["e1", ["lit"]], ["e1", []]]);
1395
+ });
1396
+
1397
+ test("in edition the click SELECTS the edge and lights nothing", async () => {
1398
+ const b = await build("edition");
1399
+ gobj_send_event(b.tree, "EV_EDGE_CLICK", {id: "e1"}, b.tree);
1400
+ expect(b.tree.priv._selected_edge_id).toBe("e1");
1401
+ expect(b.tree.priv._lit_edge_id).toBe(null);
1402
+ });
1403
+
1404
+ test("entering edition puts a lit edge out", async () => {
1405
+ const {tree} = await reading();
1406
+ gobj_send_event(tree, "EV_EDGE_CLICK", {id: "e1"}, tree);
1407
+ gobj_send_event(tree, "EV_SET_OPERATION_MODE", {operation_mode: "edition"}, tree);
1408
+ expect(tree.priv._lit_edge_id).toBe(null);
1409
+ });
1410
+ });