@yuneta/gobj-ui 7.31.1 → 7.31.3

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
@@ -1236,6 +1238,21 @@ function build_graph(gobj)
1236
1238
  style: {
1237
1239
  startArrow: true, // HACK target/source interchanged
1238
1240
  endArrow: false,
1241
+ /* A line of 2px is a 2px target: answer a click
1242
+ * some px around it (G6's default adds 2). */
1243
+ increasedLineWidthForHitTesting: 14,
1244
+ },
1245
+ /* An edge lit by a click (light_edge): the amber of a find
1246
+ * match, its two ends painted with it. A callback, so a
1247
+ * theme switch repaints it in the other scheme's amber. */
1248
+ state: {
1249
+ lit: () => ({
1250
+ stroke: highlight_color(priv.theme),
1251
+ lineWidth: 4,
1252
+ halo: true,
1253
+ haloStroke: highlight_halo(priv.theme),
1254
+ haloLineWidth: 8,
1255
+ }),
1239
1256
  },
1240
1257
  },
1241
1258
 
@@ -2081,6 +2098,7 @@ function configure_behaviour(gobj)
2081
2098
  break;
2082
2099
  case "edition":
2083
2100
  priv.edit_mode = true;
2101
+ unlight_edge(gobj); /* edition SELECTS an edge instead */
2084
2102
  behaviors = [
2085
2103
  /* Panning gives way while Shift is held: that is the
2086
2104
  * marquee's gesture, and G6 binds drag-canvas straight
@@ -8190,6 +8208,97 @@ function node_innerHTML_of(nd, theme, highlight, selected, anchored, pills_html)
8190
8208
  return null;
8191
8209
  }
8192
8210
 
8211
+ /************************************************************
8212
+ * The cards painted with the highlight: a find or topic focus
8213
+ * (`_focus_ids`) and the two ends of a lit edge (`_lit_ids`).
8214
+ * Kept apart so that lighting an edge does not erase a find,
8215
+ * and a find does not put out an edge.
8216
+ ************************************************************/
8217
+ function highlighted_ids(gobj)
8218
+ {
8219
+ let priv = gobj.priv;
8220
+ return new Set([...(priv._focus_ids || []), ...(priv._lit_ids || [])]);
8221
+ }
8222
+
8223
+ /************************************************************
8224
+ * Light an edge: the edge itself and its two ends, so a click
8225
+ * on a line says which two records it joins. A second click on
8226
+ * the same edge, or a click on the canvas, puts it out.
8227
+ *
8228
+ * Not in edition: there a click SELECTS the edge, with its own
8229
+ * ring and its affordances (select_edge).
8230
+ ************************************************************/
8231
+ function light_edge(gobj, edge_id)
8232
+ {
8233
+ let priv = gobj.priv;
8234
+ let graph = priv.graph;
8235
+
8236
+ if(!graph || !edge_id) {
8237
+ return;
8238
+ }
8239
+ let same = (priv._lit_edge_id === edge_id);
8240
+ unlight_edge(gobj);
8241
+ if(same) {
8242
+ return;
8243
+ }
8244
+
8245
+ let ed;
8246
+ try {
8247
+ ed = graph.getEdgeData(edge_id);
8248
+ } catch(e) {
8249
+ log_error(`${gobj_short_name(gobj)}: cannot light the edge ${edge_id}: ${e}`);
8250
+ return;
8251
+ }
8252
+ priv._lit_edge_id = edge_id;
8253
+ priv._lit_ids = [ed.source, ed.target];
8254
+
8255
+ /* The state as data, and ONE draw (repaint_cards'):
8256
+ * setElementState() draws on its own, and two draws race. */
8257
+ try {
8258
+ graph.updateData({edges: [{id: edge_id, states: ['lit']}]});
8259
+ } catch(e) {
8260
+ log_error(`${gobj_short_name(gobj)}: edge state not set: ${e}`);
8261
+ }
8262
+ repaint_cards(gobj, new Set(priv._lit_ids));
8263
+ }
8264
+
8265
+ function unlight_edge(gobj)
8266
+ {
8267
+ let priv = gobj.priv;
8268
+ let graph = priv.graph;
8269
+ let edge_id = priv._lit_edge_id;
8270
+ let ids = priv._lit_ids || [];
8271
+
8272
+ priv._lit_edge_id = null;
8273
+ priv._lit_ids = [];
8274
+
8275
+ if(!graph) {
8276
+ return;
8277
+ }
8278
+ if(edge_id) {
8279
+ let exists = false;
8280
+ try {
8281
+ exists = !!graph.getEdgeData(edge_id);
8282
+ } catch(e) {
8283
+ exists = false; /* folded away since it was lit */
8284
+ }
8285
+ if(exists) {
8286
+ try {
8287
+ graph.updateData({edges: [{id: edge_id, states: []}]});
8288
+ } catch(e) {
8289
+ log_error(`${gobj_short_name(gobj)}: edge state not cleared: ${e}`);
8290
+ }
8291
+ }
8292
+ }
8293
+ if(ids.length) {
8294
+ repaint_cards(gobj, new Set(ids));
8295
+ } else if(edge_id) {
8296
+ graph.draw().catch((e) => {
8297
+ log_error(`${gobj_short_name(gobj)}: redraw failed: ${e}`);
8298
+ });
8299
+ }
8300
+ }
8301
+
8193
8302
  /************************************************************
8194
8303
  * Repaint these cards with the flags they carry RIGHT NOW.
8195
8304
  *
@@ -8208,7 +8317,7 @@ function repaint_cards(gobj, ids)
8208
8317
  return;
8209
8318
  }
8210
8319
 
8211
- let focus = new Set(priv._focus_ids || []);
8320
+ let focus = highlighted_ids(gobj);
8212
8321
  let selected = new Set(priv._selected_paint_ids || []);
8213
8322
 
8214
8323
  let updates = [];
@@ -8285,7 +8394,7 @@ function refresh_html_nodes_theme(gobj, theme)
8285
8394
  /* The highlight is part of the card's html, so a theme switch that
8286
8395
  * rebuilt every card without it would silently CLEAR the focus or the
8287
8396
  * find that is on screen. Carry it across. */
8288
- let highlighted = new Set(priv._focus_ids || []);
8397
+ let highlighted = highlighted_ids(gobj);
8289
8398
  let selected = new Set(priv._selected_paint_ids || []);
8290
8399
  let updates = [];
8291
8400
  for(let i = 0; i < nodes.length; i++) {
@@ -9282,7 +9391,7 @@ function edge_inherited_style_of(gobj, d)
9282
9391
  {
9283
9392
  let priv = gobj.priv;
9284
9393
  let style = {
9285
- lineWidth: d.is_tree ? 2 : 1.6,
9394
+ lineWidth: d.is_tree ? 2.5 : 2,
9286
9395
  stroke: default_edge_stroke(gobj, d, priv.theme),
9287
9396
  themed_default: true,
9288
9397
  };
@@ -10537,6 +10646,11 @@ async function reconcile_fold_apply(gobj, opts, visible)
10537
10646
  hide_node_detail(gobj);
10538
10647
  }
10539
10648
  priv._focus_ids = (priv._focus_ids || []).filter((id) => !gone.has(id));
10649
+ if((priv._lit_ids || []).some((id) => gone.has(id))) {
10650
+ /* an edge whose end is gone is gone too */
10651
+ priv._lit_edge_id = null;
10652
+ priv._lit_ids = (priv._lit_ids || []).filter((id) => !gone.has(id));
10653
+ }
10540
10654
  priv._selected_paint_ids = (priv._selected_paint_ids || []).filter((id) => !gone.has(id));
10541
10655
  if(priv.anchor_state === "on" && gone.has(priv.anchor_id)) {
10542
10656
  priv.anchor_id = "";
@@ -12311,6 +12425,8 @@ function ac_edge_click(gobj, event, kw, src)
12311
12425
  if(priv.edit_mode) {
12312
12426
  deselect_node(gobj);
12313
12427
  select_edge(gobj, edge_id);
12428
+ } else {
12429
+ light_edge(gobj, edge_id);
12314
12430
  }
12315
12431
  }
12316
12432
  } catch(e) {
@@ -12858,6 +12974,7 @@ function ac_canvas_click(gobj, event, kw, src)
12858
12974
  let priv = gobj.priv;
12859
12975
 
12860
12976
  hide_node_detail(gobj);
12977
+ unlight_edge(gobj);
12861
12978
 
12862
12979
  if(priv._linking_mode) {
12863
12980
  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,18 @@ 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
+
128
+ /* The width an edge answers a click on, in px: a line drawn 2px
129
+ * wide is a 2px target, and G6's default adds only 2 more. */
130
+ const EDGE_HIT_WIDTH = 14;
131
+
111
132
  /***************************************************************
112
133
  * Data
113
134
  ***************************************************************/
@@ -128,6 +149,7 @@ let PRIVATE_DATA = {
128
149
  graph: null,
129
150
  theme_observer: null, // MutationObserver on <html data-theme>
130
151
  unforward_wheel: null, // removes the wheel forwarding of the cards
152
+ lit_edge_id: null, // the edge lit by a click, with its two ends
131
153
  };
132
154
 
133
155
  let __gclass__ = null;
@@ -368,7 +390,7 @@ function row_placement(index, height)
368
390
  * The card itself. Header = topic name on its topic colour;
369
391
  * body = one line per field, in schema order.
370
392
  ************************************************************/
371
- function build_card_innerHTML(topic, rows, color, dark)
393
+ function build_card_innerHTML(topic, rows, color, dark, lit_rows)
372
394
  {
373
395
  let surface = dark? "#1b2230" : "#ffffff";
374
396
  let bg = dark
@@ -389,17 +411,34 @@ function build_card_innerHTML(topic, rows, color, dark)
389
411
  let shadow = dark
390
412
  ? "0 1px 3px rgba(0,0,0,0.45), 0 1px 2px rgba(0,0,0,0.30)"
391
413
  : "0 1px 3px rgba(15,23,42,0.12), 0 1px 2px rgba(15,23,42,0.06)";
414
+ let border_w = "1.5px";
415
+
416
+ /* One end of a lit edge: the card in amber, and the row the edge
417
+ * leaves or lands on washed with it. */
418
+ let lit = lit_rows instanceof Set;
419
+ let lit_color = dark? LIT_COLOR_DARK : LIT_COLOR_LIGHT;
420
+ if(lit) {
421
+ border = lit_color;
422
+ border_w = "3px";
423
+ shadow = `0 0 0 4px ${dark? LIT_HALO_DARK : LIT_HALO_LIGHT}`;
424
+ }
392
425
 
393
426
  let rows_html = "";
394
427
  for(let row of rows) {
395
428
  let lead = row.is_pkey? "#" : (row.required? "*" : "");
396
429
  let name_weight = (row.is_pkey || row.is_pkey2)? "700" : (row.required? "600" : "400");
397
430
  let name_color = (row.is_hook || row.is_fkey)? title_color : text_color;
431
+ let row_bg = "transparent";
432
+ if(lit && lit_rows.has(row.name)) {
433
+ row_bg = `color-mix(in srgb, ${lit_color} ${dark? 35 : 22}%, transparent)`;
434
+ name_weight = "700";
435
+ }
398
436
  rows_html +=
399
437
  ` <div class="TREEDB_SCHEMA_FIELD" style="
400
438
  display: flex; align-items: center; gap: 6px;
401
439
  height: ${CARD_ROW_H}px; line-height: ${CARD_ROW_H}px;
402
440
  padding: 0 10px; border-top: 1px solid ${rule_color};
441
+ background: ${row_bg};
403
442
  ">
404
443
  <span style="
405
444
  width: 8px; flex: 0 0 8px; text-align: center;
@@ -424,7 +463,7 @@ function build_card_innerHTML(topic, rows, color, dark)
424
463
  width: 100%;
425
464
  height: 100%;
426
465
  background: ${bg};
427
- border: 1.5px solid ${border};
466
+ border: ${border_w} solid ${border};
428
467
  border-radius: 8px;
429
468
  box-shadow: ${shadow};
430
469
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
@@ -607,12 +646,183 @@ function edge_style(dark)
607
646
  {
608
647
  return {
609
648
  stroke: dark ? "#7a8593" : "#9aa4b2",
610
- lineWidth: 1.2,
649
+ lineWidth: 2,
650
+ increasedLineWidthForHitTesting: EDGE_HIT_WIDTH,
611
651
  startArrow: true,
612
652
  endArrow: false,
613
653
  };
614
654
  }
615
655
 
656
+ /************************************************************
657
+ * The edge options: the style, and the `lit` state of an edge
658
+ * a click lit (light_edge). Both together, because setEdge()
659
+ * REPLACES the options: a theme switch that set only the style
660
+ * would drop the state.
661
+ ************************************************************/
662
+ function edge_options(dark)
663
+ {
664
+ return {
665
+ style: edge_style(dark),
666
+ state: {
667
+ lit: {
668
+ stroke: dark? LIT_COLOR_DARK : LIT_COLOR_LIGHT,
669
+ lineWidth: 4,
670
+ halo: true,
671
+ haloStroke: dark? LIT_HALO_DARK : LIT_HALO_LIGHT,
672
+ haloLineWidth: 8,
673
+ },
674
+ },
675
+ };
676
+ }
677
+
678
+ /************************************************************
679
+ * The rows of `topic` the lit edge touches, as a Set (empty
680
+ * rows still mark the card), or null when the card is not one
681
+ * of its ends.
682
+ ************************************************************/
683
+ function lit_rows_of(gobj, topic)
684
+ {
685
+ let priv = gobj.priv;
686
+ if(!priv.graph || !priv.lit_edge_id) {
687
+ return null;
688
+ }
689
+ let ed;
690
+ try {
691
+ ed = priv.graph.getEdgeData(priv.lit_edge_id);
692
+ } catch(e) {
693
+ return null;
694
+ }
695
+ let style = ed.style || {};
696
+ let rows = null;
697
+ if(ed.source === topic) {
698
+ rows = rows || new Set();
699
+ rows.add(style.sourcePort);
700
+ }
701
+ if(ed.target === topic) {
702
+ rows = rows || new Set();
703
+ rows.add(style.targetPort);
704
+ }
705
+ return rows;
706
+ }
707
+
708
+ /************************************************************
709
+ * Repaint the cards of these topics, lit or not as they are now.
710
+ ************************************************************/
711
+ function repaint_cards(gobj, topics)
712
+ {
713
+ let graph = gobj.priv.graph;
714
+ let dark = yui_is_dark();
715
+ let updates = [];
716
+ for(let topic of topics) {
717
+ let nd;
718
+ try {
719
+ nd = graph.getNodeData(topic);
720
+ } catch(e) {
721
+ continue;
722
+ }
723
+ let data = nd && nd.data;
724
+ if(!is_object(data) || !Array.isArray(data.rows)) {
725
+ continue;
726
+ }
727
+ updates.push({
728
+ id: topic,
729
+ style: {
730
+ innerHTML: build_card_innerHTML(
731
+ data.topic_name, data.rows, data.color, dark,
732
+ lit_rows_of(gobj, topic)
733
+ )
734
+ }
735
+ });
736
+ }
737
+ if(updates.length > 0) {
738
+ graph.updateNodeData(updates);
739
+ }
740
+ }
741
+
742
+ /************************************************************
743
+ * Light an edge: the line, its two cards and the two rows it
744
+ * joins -- a click on a line says which hook it is and which
745
+ * fkey it lands on. A second click on it, or a click on the
746
+ * canvas, puts it out.
747
+ ************************************************************/
748
+ function light_edge(gobj, edge_id)
749
+ {
750
+ let priv = gobj.priv;
751
+ let graph = priv.graph;
752
+ if(!graph) {
753
+ return;
754
+ }
755
+ let same = (priv.lit_edge_id === edge_id);
756
+ unlight_edge(gobj, false);
757
+ if(!same && edge_id) {
758
+ let ed;
759
+ try {
760
+ ed = graph.getEdgeData(edge_id);
761
+ } catch(e) {
762
+ log_error(`${gobj_short_name(gobj)}: cannot light the edge ${edge_id}: ${e}`);
763
+ ed = null;
764
+ }
765
+ if(ed) {
766
+ priv.lit_edge_id = edge_id;
767
+ graph.updateData({edges: [{id: edge_id, states: ["lit"]}]});
768
+ repaint_cards(gobj, new Set([ed.source, ed.target]));
769
+ }
770
+ }
771
+ graph.draw().catch((e) => {
772
+ log_error(`${gobj_short_name(gobj)}: schema graph redraw failed: ${e}`);
773
+ });
774
+ }
775
+
776
+ function unlight_edge(gobj, draw)
777
+ {
778
+ let priv = gobj.priv;
779
+ let graph = priv.graph;
780
+ let edge_id = priv.lit_edge_id;
781
+ if(!graph || !edge_id) {
782
+ priv.lit_edge_id = null;
783
+ return;
784
+ }
785
+ let ed = null;
786
+ try {
787
+ ed = graph.getEdgeData(edge_id);
788
+ } catch(e) {
789
+ ed = null;
790
+ }
791
+ priv.lit_edge_id = null;
792
+ if(!ed) {
793
+ return;
794
+ }
795
+ graph.updateData({edges: [{id: edge_id, states: []}]});
796
+ repaint_cards(gobj, new Set([ed.source, ed.target]));
797
+ if(draw) {
798
+ graph.draw().catch((e) => {
799
+ log_error(`${gobj_short_name(gobj)}: schema graph redraw failed: ${e}`);
800
+ });
801
+ }
802
+ }
803
+
804
+ /************************************************************
805
+ * A card in the minimap: a block of its size in its topic's
806
+ * colour, darkened on the light scheme so a yellow topic does
807
+ * not vanish on the white panel. G6 clones a node's key shape,
808
+ * and the key shape of an html card is a DOM element, which
809
+ * clones into nothing (see yui_graph_minimap.js).
810
+ ************************************************************/
811
+ function minimap_shape(gobj, id, element_type, element)
812
+ {
813
+ if(element_type !== "node") {
814
+ return element; /* edges clone themselves fine */
815
+ }
816
+ try {
817
+ let nd = gobj.priv.graph.getNodeData(id);
818
+ let color = (nd && nd.data && nd.data.color) || SYSTEM_TOPIC_COLOR;
819
+ return yui_graph_minimap_block(nd, yui_is_dark()? color : getStrokeColor(color));
820
+ } catch(e) {
821
+ log_error(`${gobj_short_name(gobj)}: minimap shape failed: ${e}`);
822
+ return element;
823
+ }
824
+ }
825
+
616
826
  /************************************************************
617
827
  * Build the G6 schema graph.
618
828
  ************************************************************/
@@ -644,9 +854,7 @@ function build_graph(gobj)
644
854
  autoResize: true,
645
855
  animation: false,
646
856
  data: data,
647
- edge: {
648
- style: edge_style(dark),
649
- },
857
+ edge: edge_options(dark),
650
858
  layout: {
651
859
  type: "antv-dagre",
652
860
  rankdir: "LR",
@@ -655,6 +863,14 @@ function build_graph(gobj)
655
863
  },
656
864
  /* The family's camera: the wheel scrolls, Ctrl + wheel zooms. */
657
865
  behaviors: ["drag-canvas", ...yui_graph_camera_behaviors(), "drag-element"],
866
+ /* Always: a schema whose cards run off the screen is the
867
+ * common case, and it is the minimap that says where the
868
+ * rest of them are. */
869
+ plugins: [
870
+ {key: "minimap", type: "minimap", ...yui_graph_minimap_options(
871
+ (id, element_type, element) => minimap_shape(gobj, id, element_type, element)
872
+ )},
873
+ ],
658
874
  });
659
875
  } catch(e) {
660
876
  log_error(`${gobj_short_name(gobj)}: schema graph create failed: ${e}`);
@@ -686,6 +902,15 @@ function build_graph(gobj)
686
902
  gobj_send_event(gobj, "EV_NODE_CLICK", {node_id: node_id}, gobj);
687
903
  });
688
904
 
905
+ graph.on(EdgeEvent.CLICK, (evt) => {
906
+ let edge_id = evt && evt.target && evt.target.id;
907
+ gobj_send_event(gobj, "EV_EDGE_CLICK", {edge_id: edge_id}, gobj);
908
+ });
909
+
910
+ graph.on(CanvasEvent.CLICK, () => {
911
+ gobj_send_event(gobj, "EV_CANVAS_CLICK", {}, gobj);
912
+ });
913
+
689
914
  /* No fitView: the diagram is drawn at its own scale and stays there.
690
915
  * Zooming it to the container the moment it appears rewrites the size
691
916
  * the reader just saw, and does it differently for every treedb. */
@@ -702,6 +927,7 @@ function build_graph(gobj)
702
927
  function destroy_graph(gobj)
703
928
  {
704
929
  let priv = gobj.priv;
930
+ priv.lit_edge_id = null;
705
931
  if(priv.unforward_wheel) {
706
932
  priv.unforward_wheel();
707
933
  priv.unforward_wheel = null;
@@ -773,6 +999,28 @@ function ac_node_click(gobj, event, kw, src)
773
999
  return 0;
774
1000
  }
775
1001
 
1002
+ /************************************************************
1003
+ * An edge was clicked: light it, or put it out if it was lit.
1004
+ ************************************************************/
1005
+ function ac_edge_click(gobj, event, kw, src)
1006
+ {
1007
+ let edge_id = kw && kw.edge_id;
1008
+ if(!edge_id) {
1009
+ return 0;
1010
+ }
1011
+ light_edge(gobj, edge_id);
1012
+ return 0;
1013
+ }
1014
+
1015
+ /************************************************************
1016
+ * A click on the empty canvas puts the lit edge out.
1017
+ ************************************************************/
1018
+ function ac_canvas_click(gobj, event, kw, src)
1019
+ {
1020
+ unlight_edge(gobj, true);
1021
+ return 0;
1022
+ }
1023
+
776
1024
  /************************************************************
777
1025
  * Shown by the host: match the canvas to the container now it
778
1026
  * is visible and sized (G6 renders at 0×0 while display:none).
@@ -814,7 +1062,7 @@ function ac_theme(gobj, event, kw, src)
814
1062
  let dark = (kw && kw.theme) ? (kw.theme === "dark") : yui_is_dark();
815
1063
  try {
816
1064
  graph.setTheme(dark ? "dark" : "light");
817
- graph.setEdge({style: edge_style(dark)});
1065
+ graph.setEdge(edge_options(dark));
818
1066
 
819
1067
  /* A card is HTML, so its colours live in its markup: repaint
820
1068
  * each one from the rows kept in its node data. */
@@ -828,7 +1076,8 @@ function ac_theme(gobj, event, kw, src)
828
1076
  id: node.id,
829
1077
  style: {
830
1078
  innerHTML: build_card_innerHTML(
831
- data.topic_name, data.rows, data.color, dark
1079
+ data.topic_name, data.rows, data.color, dark,
1080
+ lit_rows_of(gobj, node.id)
832
1081
  )
833
1082
  }
834
1083
  });
@@ -939,6 +1188,8 @@ function create_gclass(gclass_name)
939
1188
  const states = [
940
1189
  ["ST_IDLE", [
941
1190
  ["EV_NODE_CLICK", ac_node_click, null],
1191
+ ["EV_EDGE_CLICK", ac_edge_click, null],
1192
+ ["EV_CANVAS_CLICK", ac_canvas_click, null],
942
1193
  ["EV_SHOW", ac_show, null],
943
1194
  ["EV_THEME", ac_theme, null],
944
1195
  ["EV_REBUILD", ac_rebuild, null],
@@ -953,6 +1204,8 @@ function create_gclass(gclass_name)
953
1204
  /* Sent to itself by the graph, and published to the host when no
954
1205
  * `node_route` was given: optional there, so no warning. */
955
1206
  ["EV_NODE_CLICK", event_flag_t.EVF_OUTPUT_EVENT|event_flag_t.EVF_NO_WARN_SUBS],
1207
+ ["EV_EDGE_CLICK", 0],
1208
+ ["EV_CANVAS_CLICK", 0],
956
1209
  ["EV_SHOW", 0],
957
1210
  ["EV_THEME", 0],
958
1211
  ["EV_REBUILD", 0],
@@ -1358,3 +1358,58 @@ 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("an edge answers a click well around its line", async () => {
1376
+ const {graph} = await reading();
1377
+ expect(graph.options.edge.style.increasedLineWidthForHitTesting).toBeGreaterThanOrEqual(10);
1378
+ });
1379
+
1380
+ test("the edge takes the lit state, its ends are painted, the host still hears the click", async () => {
1381
+ const {tree, states} = await reading();
1382
+ gobj_send_event(tree, "EV_EDGE_CLICK", {id: "e1"}, tree);
1383
+ expect(tree.priv._lit_edge_id).toBe("e1");
1384
+ expect(tree.priv._lit_ids).toEqual(["n1", "n1"]);
1385
+ expect(states).toEqual([["e1", ["lit"]]]);
1386
+ expect(published.map((p) => p.event)).toContain("EV_EDGE_CLICKED");
1387
+ });
1388
+
1389
+ test("a second click on it, or a canvas click, puts it out", async () => {
1390
+ const {tree, states} = await reading();
1391
+ gobj_send_event(tree, "EV_EDGE_CLICK", {id: "e1"}, tree);
1392
+ gobj_send_event(tree, "EV_EDGE_CLICK", {id: "e1"}, tree);
1393
+ expect(tree.priv._lit_edge_id).toBe(null);
1394
+ expect(tree.priv._lit_ids).toEqual([]);
1395
+
1396
+ gobj_send_event(tree, "EV_EDGE_CLICK", {id: "e1"}, tree);
1397
+ gobj_send_event(tree, "EV_CANVAS_CLICK", {}, tree);
1398
+ expect(tree.priv._lit_edge_id).toBe(null);
1399
+ expect(states).toEqual([["e1", ["lit"]], ["e1", []], ["e1", ["lit"]], ["e1", []]]);
1400
+ });
1401
+
1402
+ test("in edition the click SELECTS the edge and lights nothing", async () => {
1403
+ const b = await build("edition");
1404
+ gobj_send_event(b.tree, "EV_EDGE_CLICK", {id: "e1"}, b.tree);
1405
+ expect(b.tree.priv._selected_edge_id).toBe("e1");
1406
+ expect(b.tree.priv._lit_edge_id).toBe(null);
1407
+ });
1408
+
1409
+ test("entering edition puts a lit edge out", async () => {
1410
+ const {tree} = await reading();
1411
+ gobj_send_event(tree, "EV_EDGE_CLICK", {id: "e1"}, tree);
1412
+ gobj_send_event(tree, "EV_SET_OPERATION_MODE", {operation_mode: "edition"}, tree);
1413
+ expect(tree.priv._lit_edge_id).toBe(null);
1414
+ });
1415
+ });