@yuneta/gobj-ui 7.31.7 → 7.31.8

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.
@@ -239,6 +239,8 @@ let PRIVATE_DATA = {
239
239
  lit_parent_path: "", // path of its PARENT card
240
240
  lit_port: "", // the parent's port the edge leaves from: its row is washed
241
241
  lit_found: false, // the last build drew it
242
+ lit_edge_id: "", // the id of the lit edge in the graph drawn now
243
+ cards: null, // Map path -> {id, kw, has_parent}: a card repainted alone
242
244
  };
243
245
 
244
246
  let __gclass__ = null;
@@ -774,6 +776,24 @@ function build_graph(gobj)
774
776
  lineWidth: 1,
775
777
  endArrow: true,
776
778
  },
779
+ /* An edge lit by a click (light_edge): a state, so lighting
780
+ * it redraws the line and its two cards, not the graph. A
781
+ * callback, so a theme switch paints the other amber. */
782
+ state: {
783
+ lit: () => {
784
+ let dark = yui_is_dark();
785
+ let lit_color = dark? LIT_COLOR_DARK : LIT_COLOR_LIGHT;
786
+ return {
787
+ stroke: lit_color,
788
+ lineWidth: 3,
789
+ halo: true,
790
+ haloStroke: dark? LIT_HALO_DARK : LIT_HALO_LIGHT,
791
+ haloLineWidth: 8,
792
+ endArrowFill: lit_color,
793
+ endArrowStroke: lit_color,
794
+ };
795
+ },
796
+ },
777
797
  },
778
798
 
779
799
  layout: layout_cfg.g6_layout,
@@ -1173,29 +1193,25 @@ function get_group_label(path)
1173
1193
  }
1174
1194
 
1175
1195
  /************************************************************
1176
- * Recursively build nodes and edges from JSON
1196
+ * The rows of the card of `path`: one per key of `kw`, the
1197
+ * containers among them (`pending_complex`, each with the port
1198
+ * and the row it opens), and how many rows the find matched.
1177
1199
  ************************************************************/
1178
- function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
1200
+ function card_rows_of(gobj, path, kw)
1179
1201
  {
1180
- let group_id = gen_node_id(gobj);
1202
+ let priv = gobj.priv;
1181
1203
  let is_dict = is_object(kw);
1182
- let is_list = is_array(kw);
1183
-
1184
- if(!is_dict && !is_list) {
1185
- return null;
1186
- }
1187
1204
 
1188
1205
  /*
1189
- * Build HTML content for this group.
1190
1206
  * The theme is read live as the card is drawn (like the gobj-tree's
1191
1207
  * cards): ac_theme rebuilds on a switch, so this is always current.
1192
1208
  */
1193
- let priv = gobj.priv;
1194
1209
  let needle = priv.search || "";
1195
1210
  let dark = yui_is_dark();
1196
1211
  let lines = [];
1197
1212
  let pending_complex = [];
1198
1213
  let card_matched = false;
1214
+ let matches = 0;
1199
1215
 
1200
1216
  let colors = json_card_style(
1201
1217
  is_dict ? GROUP_COLORS.dict : GROUP_COLORS.list, dark
@@ -1208,7 +1224,7 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
1208
1224
  let matched = cell_matches(key, value, type, needle);
1209
1225
  if(matched) {
1210
1226
  card_matched = true;
1211
- priv.match_count++;
1227
+ matches++;
1212
1228
  }
1213
1229
 
1214
1230
  /*
@@ -1249,40 +1265,32 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
1249
1265
  lines.push(build_cell_html(key, value, type, dark, matched, fold));
1250
1266
  }
1251
1267
 
1252
- /*
1253
- * A pure collection is not drawn: its row above names it and its
1254
- * children hang from THIS card's parent. The root always gets a
1255
- * card, or a document that is a plain list of records would have
1256
- * nothing to hang anything from.
1257
- */
1258
- if(parent_id && is_pure_collection(kw)) {
1259
- if(priv.collapsed.has(path)) {
1260
- /* Folded, and it draws nothing of its own -- so the space
1261
- * its children were taking is left HERE, in their place
1262
- * among the parent's other children. */
1263
- push_fold_phantom(gobj, path, parent_id, parent_port, nodes, edges);
1264
- return parent_id;
1265
- }
1266
- for(let pending of pending_complex) {
1267
- /*
1268
- * `parent_port` and not one of ours: this collection has no
1269
- * card, so the port its row opened in the PARENT is the one
1270
- * every one of these lines leaves from -- fourteen columns
1271
- * out of the single `cols` port, which is what the document
1272
- * says and what the reader traces back.
1273
- */
1274
- build_json_nodes(
1275
- gobj,
1276
- add_segment(path, pending.key),
1277
- pending.value,
1278
- nodes,
1279
- edges,
1280
- parent_id,
1281
- parent_port
1282
- );
1283
- }
1284
- return parent_id;
1285
- }
1268
+ return {
1269
+ is_dict: is_dict,
1270
+ dark: dark,
1271
+ colors: colors,
1272
+ lines: lines,
1273
+ pending_complex: pending_complex,
1274
+ card_matched: card_matched,
1275
+ matches: matches,
1276
+ };
1277
+ }
1278
+
1279
+ /************************************************************
1280
+ * The html of the card of `path`, from its rows (card_rows_of),
1281
+ * lit or not as priv.lit_* says now. The build draws every card
1282
+ * with it, and repaint_cards() one card alone: the same moment
1283
+ * reads the same either way.
1284
+ ************************************************************/
1285
+ function card_html_of(gobj, path, rows, has_parent)
1286
+ {
1287
+ let priv = gobj.priv;
1288
+ let is_dict = rows.is_dict;
1289
+ let dark = rows.dark;
1290
+ let colors = rows.colors;
1291
+ let lines = rows.lines;
1292
+ let pending_complex = rows.pending_complex;
1293
+ let card_matched = rows.card_matched;
1286
1294
 
1287
1295
  let label = get_group_label(path) || (is_dict ? "{}" : "[]");
1288
1296
 
@@ -1305,7 +1313,7 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
1305
1313
  * the line says which key it is.
1306
1314
  */
1307
1315
  let lit_color = dark? LIT_COLOR_DARK : LIT_COLOR_LIGHT;
1308
- let lit_child = !!parent_id && !empty_string(priv.lit_path) && path === priv.lit_path;
1316
+ let lit_child = has_parent && !empty_string(priv.lit_path) && path === priv.lit_path;
1309
1317
  let lit_row = -1;
1310
1318
  let lit_parent = !empty_string(priv.lit_path) && path === priv.lit_parent_path;
1311
1319
  if(lit_parent) {
@@ -1317,9 +1325,6 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
1317
1325
  }
1318
1326
  }
1319
1327
  let lit_card = lit_child || lit_parent;
1320
- if(lit_child) {
1321
- priv.lit_found = true;
1322
- }
1323
1328
  if(lit_card) {
1324
1329
  border_color = lit_color;
1325
1330
  border_width = 3;
@@ -1373,6 +1378,79 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
1373
1378
  ${content_html}
1374
1379
  </div>`;
1375
1380
 
1381
+ return {
1382
+ node_html: node_html,
1383
+ min_width: min_width,
1384
+ card_height: card_height,
1385
+ folded: folded,
1386
+ lit_child: lit_child,
1387
+ };
1388
+ }
1389
+
1390
+ /************************************************************
1391
+ * Recursively build nodes and edges from JSON
1392
+ ************************************************************/
1393
+ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
1394
+ {
1395
+ let group_id = gen_node_id(gobj);
1396
+ let is_dict = is_object(kw);
1397
+ let is_list = is_array(kw);
1398
+
1399
+ if(!is_dict && !is_list) {
1400
+ return null;
1401
+ }
1402
+
1403
+ let priv = gobj.priv;
1404
+ let rows = card_rows_of(gobj, path, kw);
1405
+ let dark = rows.dark;
1406
+ let colors = rows.colors;
1407
+ let pending_complex = rows.pending_complex;
1408
+ priv.match_count += rows.matches;
1409
+
1410
+ /*
1411
+ * A pure collection is not drawn: its row above names it and its
1412
+ * children hang from THIS card's parent. The root always gets a
1413
+ * card, or a document that is a plain list of records would have
1414
+ * nothing to hang anything from.
1415
+ */
1416
+ if(parent_id && is_pure_collection(kw)) {
1417
+ if(priv.collapsed.has(path)) {
1418
+ /* Folded, and it draws nothing of its own -- so the space
1419
+ * its children were taking is left HERE, in their place
1420
+ * among the parent's other children. */
1421
+ push_fold_phantom(gobj, path, parent_id, parent_port, nodes, edges);
1422
+ return parent_id;
1423
+ }
1424
+ for(let pending of pending_complex) {
1425
+ /*
1426
+ * `parent_port` and not one of ours: this collection has no
1427
+ * card, so the port its row opened in the PARENT is the one
1428
+ * every one of these lines leaves from -- fourteen columns
1429
+ * out of the single `cols` port, which is what the document
1430
+ * says and what the reader traces back.
1431
+ */
1432
+ build_json_nodes(
1433
+ gobj,
1434
+ add_segment(path, pending.key),
1435
+ pending.value,
1436
+ nodes,
1437
+ edges,
1438
+ parent_id,
1439
+ parent_port
1440
+ );
1441
+ }
1442
+ return parent_id;
1443
+ }
1444
+
1445
+ let card = card_html_of(gobj, path, rows, !!parent_id);
1446
+ let folded = card.folded;
1447
+ let lit_child = card.lit_child;
1448
+ let min_width = card.min_width;
1449
+ let card_height = card.card_height;
1450
+ if(lit_child) {
1451
+ priv.lit_found = true;
1452
+ }
1453
+
1376
1454
  /*
1377
1455
  * ONE PORT PER CONTAINER KEY, ON THE LINE OF ITS OWN ROW.
1378
1456
  *
@@ -1441,7 +1519,7 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
1441
1519
 
1442
1520
  },
1443
1521
  style: {
1444
- innerHTML: node_html,
1522
+ innerHTML: card.node_html,
1445
1523
  size: [min_width, card_height],
1446
1524
  dx: -(min_width / 2),
1447
1525
  dy: -(card_height / 2),
@@ -1452,12 +1530,15 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
1452
1530
  },
1453
1531
  };
1454
1532
  nodes.push(node);
1533
+ priv.cards.set(path, {id: group_id, kw: kw, has_parent: !!parent_id});
1455
1534
 
1456
1535
  /*
1457
1536
  * Edge from parent to this group, out of the port its key opened.
1537
+ * Its id is its child card's: a card has one edge coming in.
1458
1538
  */
1459
1539
  if(parent_id) {
1460
1540
  let edge = {
1541
+ id: "je-" + group_id,
1461
1542
  source: parent_id,
1462
1543
  target: group_id,
1463
1544
  style: {
@@ -1489,15 +1570,8 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
1489
1570
  edge.style.sourcePort = parent_port;
1490
1571
  }
1491
1572
  if(lit_child) {
1492
- Object.assign(edge.style, {
1493
- stroke: lit_color,
1494
- lineWidth: 3,
1495
- halo: true,
1496
- haloStroke: dark? LIT_HALO_DARK : LIT_HALO_LIGHT,
1497
- haloLineWidth: 8,
1498
- endArrowFill: lit_color,
1499
- endArrowStroke: lit_color,
1500
- });
1573
+ edge.states = ["lit"];
1574
+ priv.lit_edge_id = edge.id;
1501
1575
  }
1502
1576
  edges.push(edge);
1503
1577
  }
@@ -1621,6 +1695,8 @@ function load_json(gobj)
1621
1695
  priv.node_counter = 0;
1622
1696
  priv.match_count = 0;
1623
1697
  priv.lit_found = false;
1698
+ priv.lit_edge_id = "";
1699
+ priv.cards = new Map();
1624
1700
 
1625
1701
  let nodes = [];
1626
1702
  let edges = [];
@@ -1895,6 +1971,101 @@ function refresh_json(gobj, opts)
1895
1971
  }
1896
1972
  }
1897
1973
 
1974
+ /************************************************************
1975
+ * Repaint the cards of these paths alone, lit or not as
1976
+ * priv.lit_* says now, and draw once. A click on an edge
1977
+ * changes two cards: rebuilding the graph for them redrew
1978
+ * every card, the layout and the camera's frame.
1979
+ ************************************************************/
1980
+ function repaint_cards(gobj, paths)
1981
+ {
1982
+ let priv = gobj.priv;
1983
+ let graph = priv.graph;
1984
+
1985
+ if(!graph || !priv.cards) {
1986
+ return;
1987
+ }
1988
+ let updates = [];
1989
+ for(let path of paths) {
1990
+ let c = priv.cards.get(path);
1991
+ if(!c) {
1992
+ continue; /* a path with no card of its own: nothing to repaint */
1993
+ }
1994
+ let rows = card_rows_of(gobj, path, c.kw);
1995
+ let card = card_html_of(gobj, path, rows, c.has_parent);
1996
+ updates.push({id: c.id, style: {innerHTML: card.node_html}});
1997
+ }
1998
+ try {
1999
+ if(updates.length) {
2000
+ graph.updateNodeData(updates);
2001
+ }
2002
+ Promise.resolve(graph.draw()).then(() => {
2003
+ /* A repainted card is new DOM: put the anchor's mark back. */
2004
+ paint_anchor_mark(gobj);
2005
+ }).catch((e) => {
2006
+ log_error(`${gobj_short_name(gobj)}: redraw failed: ${e}`);
2007
+ });
2008
+ } catch(e) {
2009
+ log_error(`${gobj_short_name(gobj)}: cannot repaint the cards: ${e}`);
2010
+ }
2011
+ }
2012
+
2013
+ /************************************************************
2014
+ * Put the lit edge out: its state off, and the paths of its
2015
+ * two cards returned, to be repainted plain. Draws nothing:
2016
+ * the caller repaints once, and two draws race. [] when
2017
+ * nothing is lit.
2018
+ ************************************************************/
2019
+ function put_out_edge(gobj)
2020
+ {
2021
+ let priv = gobj.priv;
2022
+ let graph = priv.graph;
2023
+
2024
+ if(empty_string(priv.lit_path)) {
2025
+ return [];
2026
+ }
2027
+ let paths = [priv.lit_path, priv.lit_parent_path];
2028
+ let edge_id = priv.lit_edge_id;
2029
+
2030
+ priv.lit_path = "";
2031
+ priv.lit_parent_path = "";
2032
+ priv.lit_port = "";
2033
+ priv.lit_edge_id = "";
2034
+
2035
+ if(graph && !empty_string(edge_id)) {
2036
+ try {
2037
+ graph.updateData({edges: [{id: edge_id, states: []}]});
2038
+ } catch(e) {
2039
+ log_error(`${gobj_short_name(gobj)}: edge state not cleared: ${e}`);
2040
+ }
2041
+ }
2042
+ return paths;
2043
+ }
2044
+
2045
+ /************************************************************
2046
+ * Light an edge: its `lit` state on, and the paths of its two
2047
+ * cards returned, to be repainted with the ring (the parent's
2048
+ * row of the key it leaves from washed). The cards are html,
2049
+ * where G6 paints no state, so their mark is in their html.
2050
+ * Draws nothing, as put_out_edge().
2051
+ ************************************************************/
2052
+ function light_edge(gobj, edge_id, child_path, parent_path, port)
2053
+ {
2054
+ let priv = gobj.priv;
2055
+
2056
+ priv.lit_path = child_path;
2057
+ priv.lit_parent_path = parent_path;
2058
+ priv.lit_port = port;
2059
+ priv.lit_edge_id = edge_id;
2060
+
2061
+ try {
2062
+ priv.graph.updateData({edges: [{id: edge_id, states: ["lit"]}]});
2063
+ } catch(e) {
2064
+ log_error(`${gobj_short_name(gobj)}: edge state not set: ${e}`);
2065
+ }
2066
+ return [child_path, parent_path];
2067
+ }
2068
+
1898
2069
  /************************************************************
1899
2070
  * Custom tree layout for JSON visualization
1900
2071
  ************************************************************/
@@ -2093,6 +2264,7 @@ function ac_load_data(gobj, event, kw, src)
2093
2264
  gobj.priv.lit_path = "";
2094
2265
  gobj.priv.lit_parent_path = "";
2095
2266
  gobj.priv.lit_port = "";
2267
+ gobj.priv.lit_edge_id = "";
2096
2268
  }
2097
2269
 
2098
2270
  refresh_json(gobj);
@@ -2276,10 +2448,10 @@ function ac_collapse_all(gobj, event, kw, src)
2276
2448
  * EV_EDGE_CLICK { id }
2277
2449
  *
2278
2450
  * Light the edge and its two ends, or put it out when it is
2279
- * the lit one. Baked into the drawing, like a find match: the
2280
- * cards are html, where G6 paints no state, so the drawing is
2281
- * rebuilt with the camera kept. The edge is kept by the PATH
2282
- * of its child card, which a rebuild keeps and the ids do not.
2451
+ * the lit one. Only the edge and its two cards are redrawn
2452
+ * (light_edge). The edge is kept by the PATH of its child
2453
+ * card, which a rebuild (a fold, a find) keeps and the ids do
2454
+ * not: the rebuild lights it again.
2283
2455
  ************************************************************/
2284
2456
  function ac_edge_click(gobj, event, kw, src)
2285
2457
  {
@@ -2305,16 +2477,18 @@ function ac_edge_click(gobj, event, kw, src)
2305
2477
  return 0; /* the invisible edge a fold leaves */
2306
2478
  }
2307
2479
 
2308
- if(priv.lit_path === tdata.path) {
2309
- priv.lit_path = "";
2310
- priv.lit_parent_path = "";
2311
- priv.lit_port = "";
2312
- } else {
2313
- priv.lit_path = tdata.path;
2314
- priv.lit_parent_path = (source && source.data && source.data.path) || "";
2315
- priv.lit_port = (edge.style && edge.style.sourcePort) || "";
2480
+ let same = (priv.lit_path === tdata.path);
2481
+ let paths = put_out_edge(gobj);
2482
+ if(!same) {
2483
+ paths = paths.concat(light_edge(
2484
+ gobj,
2485
+ edge.id,
2486
+ tdata.path,
2487
+ (source && source.data && source.data.path) || "",
2488
+ (edge.style && edge.style.sourcePort) || ""
2489
+ ));
2316
2490
  }
2317
- refresh_json(gobj, {preserve_view: true});
2491
+ repaint_cards(gobj, new Set(paths));
2318
2492
  return 0;
2319
2493
  }
2320
2494
 
@@ -2328,10 +2502,7 @@ function ac_canvas_click(gobj, event, kw, src)
2328
2502
  if(empty_string(priv.lit_path)) {
2329
2503
  return 0;
2330
2504
  }
2331
- priv.lit_path = "";
2332
- priv.lit_parent_path = "";
2333
- priv.lit_port = "";
2334
- refresh_json(gobj, {preserve_view: true});
2505
+ repaint_cards(gobj, put_out_edge(gobj));
2335
2506
  return 0;
2336
2507
  }
2337
2508
 
@@ -165,3 +165,58 @@ describe("the moments uPlot writes (yui_uplot_time.js)", () => {
165
165
  expect(fmt("{h}:{mm}{aa}")(AFTERNOON)).toBe("15:05");
166
166
  });
167
167
  });
168
+
169
+ describe("one formatter per locale and time zone", () => {
170
+ const with_counted_intl = (fn) => {
171
+ const Real = Intl.DateTimeFormat;
172
+ let built = 0;
173
+ Intl.DateTimeFormat = function(...args) {
174
+ built++;
175
+ return new Real(...args);
176
+ };
177
+ try {
178
+ fn();
179
+ } finally {
180
+ Intl.DateTimeFormat = Real;
181
+ }
182
+ return built;
183
+ };
184
+
185
+ test("a filter over many rows builds the formatter once", () => {
186
+ const built = with_counted_intl(() => {
187
+ for(let i = 0; i < 1000; i++) {
188
+ fmt_date_time(new Date(D.getTime() + i * 1000), "fr");
189
+ }
190
+ });
191
+ expect(built).toBe(1);
192
+ expect(fmt_date_time(D, "fr")).toBe(new Intl.DateTimeFormat("fr", {
193
+ day: "numeric", month: "short", year: "numeric",
194
+ hour: "2-digit", minute: "2-digit", second: "2-digit", hourCycle: "h23"
195
+ }).format(D));
196
+ });
197
+
198
+ test("a change of language writes in the new language at once", () => {
199
+ expect(fmt_date_time(D, "es")).toBe("14 oct 2026, 15:05:09");
200
+ expect(fmt_date_time(D, "en")).toBe("Oct 14, 2026, 15:05:09");
201
+ expect(fmt_date_time(D, "es")).toBe("14 oct 2026, 15:05:09");
202
+ });
203
+
204
+ test("a change of time zone writes in the new zone", () => {
205
+ const tz = process.env.TZ;
206
+ const instant = new Date(Date.UTC(2026, 0, 15, 12, 0, 0));
207
+ try {
208
+ process.env.TZ = "UTC";
209
+ expect(fmt_date_time(instant, "es")).toBe("15 ene 2026, 12:00:00");
210
+ process.env.TZ = "Asia/Tokyo";
211
+ expect(fmt_date_time(instant, "es")).toBe("15 ene 2026, 21:00:00");
212
+ process.env.TZ = "UTC";
213
+ expect(fmt_date_time(instant, "es")).toBe("15 ene 2026, 12:00:00");
214
+ } finally {
215
+ if(tz === undefined) {
216
+ delete process.env.TZ;
217
+ } else {
218
+ process.env.TZ = tz;
219
+ }
220
+ }
221
+ });
222
+ });
@@ -8,7 +8,10 @@
8
8
  * edge LIGHTS it: the line in amber, its two cards ringed, and
9
9
  * the row of the parent's key the line leaves from washed. A
10
10
  * second click on it, or a click on the canvas, puts it out; a
11
- * fold that takes its child card away puts it out too.
11
+ * fold that takes its child card away puts it out too. Lighting
12
+ * and putting out redraw the edge (its `lit` state) and its two
13
+ * cards, never the graph (gobj-ui 7.31.8; before, every click
14
+ * rebuilt every card and ran the layout again).
12
15
  *
13
16
  * Driven through the real gclass, in jsdom, with a G6 double that
14
17
  * keeps the data it is given.
@@ -36,6 +39,7 @@ vi.mock("@antv/g6", async (importOriginal) => {
36
39
  this.handlers = {};
37
40
  this.plugins = (options.plugins || []).slice();
38
41
  this.data = {nodes: [], edges: []};
42
+ this.counts = {setData: 0, draw: 0, updated_nodes: []};
39
43
  graphs.push(this);
40
44
  return new Proxy(this, {
41
45
  get: (t, k) => (k in t) ? t[k] : (() => undefined),
@@ -47,6 +51,22 @@ vi.mock("@antv/g6", async (importOriginal) => {
47
51
  e.id = e.id || `e${i}`;
48
52
  });
49
53
  this.data = data;
54
+ this.counts.setData++;
55
+ }
56
+ updateNodeData(updates) {
57
+ for(const u of updates) {
58
+ const nd = this.getNodeData(u.id);
59
+ nd.style = {...nd.style, ...(u.style || {})};
60
+ this.counts.updated_nodes.push(u.id);
61
+ }
62
+ }
63
+ updateData(data) {
64
+ for(const u of (data.edges || [])) {
65
+ const ed = this.getEdgeData(u.id);
66
+ if(u.states !== undefined) {
67
+ ed.states = u.states.slice();
68
+ }
69
+ }
50
70
  }
51
71
  clear() {
52
72
  this.data = {nodes: [], edges: []};
@@ -55,6 +75,7 @@ vi.mock("@antv/g6", async (importOriginal) => {
55
75
  return Promise.resolve();
56
76
  }
57
77
  draw() {
78
+ this.counts.draw++;
58
79
  return Promise.resolve();
59
80
  }
60
81
  on(name, fn) {
@@ -184,6 +205,7 @@ function card(graph, path)
184
205
  return graph.data.nodes.find((n) => n.data && n.data.path === path && !n.data.phantom).style.innerHTML;
185
206
  }
186
207
  const RING = /border: 3px solid/;
208
+ const is_lit = (e) => (e.states || []).includes("lit");
187
209
  const WASH = /background:color-mix\(in srgb, #[0-9a-f]+ 28%, transparent\)/g;
188
210
 
189
211
  function problems()
@@ -222,8 +244,13 @@ describe("C_YUI_JSON_GRAPH: zoom floor, minimap, lit edge", () => {
222
244
  await settle();
223
245
 
224
246
  const lit = edge_to(graph, child);
225
- expect(lit.style.lineWidth).toBe(3);
226
- expect(lit.style.halo).toBe(true);
247
+ expect(is_lit(lit)).toBe(true);
248
+ expect(graph.data.edges.filter(is_lit).length).toBe(1);
249
+ /* The look of the state: 3px, amber, a halo */
250
+ const look = graph.options.edge.state.lit();
251
+ expect(look.lineWidth).toBe(3);
252
+ expect(look.halo).toBe(true);
253
+ expect(look.stroke).toMatch(/^#[0-9a-f]{6}$/);
227
254
  expect(card(graph, child)).toMatch(RING);
228
255
  expect(card(graph, root)).toMatch(RING);
229
256
  expect((card(graph, root).match(WASH) || []).length).toBe(1);
@@ -233,7 +260,7 @@ describe("C_YUI_JSON_GRAPH: zoom floor, minimap, lit edge", () => {
233
260
 
234
261
  graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, child).id}});
235
262
  await settle();
236
- expect(edge_to(graph, child).style.lineWidth).not.toBe(3);
263
+ expect(is_lit(edge_to(graph, child))).toBe(false);
237
264
  expect(card(graph, root)).not.toMatch(RING);
238
265
  expect(problems()).toEqual([]);
239
266
  });
@@ -257,4 +284,63 @@ describe("C_YUI_JSON_GRAPH: zoom floor, minimap, lit edge", () => {
257
284
  expect(graph.data.nodes.some((n) => RING.test(n.style.innerHTML || ""))).toBe(false);
258
285
  expect(problems()).toEqual([]);
259
286
  });
287
+ test("lighting and putting out redraw the edge and its two cards, never the graph", async () => {
288
+ const {graph} = await mount(DOC);
289
+ const root = graph.data.nodes[0];
290
+ const child = graph.data.nodes.find((n) => n.data && n.data.path === "``b");
291
+ const builds = graph.counts.setData;
292
+ const draws = graph.counts.draw;
293
+
294
+ graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, "``b").id}});
295
+ await settle();
296
+ expect(graph.counts.setData).toBe(builds);
297
+ expect(graph.counts.draw).toBe(draws + 1);
298
+ expect([...graph.counts.updated_nodes].sort()).toEqual([root.id, child.id].sort());
299
+
300
+ graph.counts.updated_nodes.length = 0;
301
+ graph.emit(CanvasEvent.CLICK, {});
302
+ await settle();
303
+ expect(graph.counts.setData).toBe(builds);
304
+ expect(graph.counts.draw).toBe(draws + 2);
305
+ expect([...graph.counts.updated_nodes].sort()).toEqual([root.id, child.id].sort());
306
+ expect(graph.data.nodes.some((n) => RING.test(n.style.innerHTML || ""))).toBe(false);
307
+ expect(graph.data.edges.some(is_lit)).toBe(false);
308
+ expect(problems()).toEqual([]);
309
+ });
310
+
311
+ test("a click on another edge moves the light in ONE draw", async () => {
312
+ const {graph} = await mount(DOC);
313
+ graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, "``b").id}});
314
+ await settle();
315
+ const draws = graph.counts.draw;
316
+ graph.counts.updated_nodes.length = 0;
317
+
318
+ graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, "``b`y").id}});
319
+ await settle();
320
+ expect(graph.counts.draw).toBe(draws + 1);
321
+ /* `b was the child and is now the parent: repainted once */
322
+ expect(graph.counts.updated_nodes.length).toBe(3);
323
+ expect(is_lit(edge_to(graph, "``b"))).toBe(false);
324
+ expect(is_lit(edge_to(graph, "``b`y"))).toBe(true);
325
+ expect(card(graph, "``b`y")).toMatch(RING);
326
+ expect(card(graph, "``b")).toMatch(RING);
327
+ expect(card(graph, graph.data.nodes[0].data.path)).not.toMatch(RING);
328
+ expect(problems()).toEqual([]);
329
+ });
330
+
331
+ test("a rebuild (a find) keeps the edge lit, and a click on it then puts it out", async () => {
332
+ const {view, graph} = await mount(DOC);
333
+ graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, "``b").id}});
334
+ await settle();
335
+ gobj_send_event(view, "EV_FIND_NODES", {text: "z"}, view);
336
+ await settle();
337
+ expect(is_lit(edge_to(graph, "``b"))).toBe(true);
338
+ expect(card(graph, "``b")).toMatch(RING);
339
+
340
+ graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, "``b").id}});
341
+ await settle();
342
+ expect(graph.data.edges.some(is_lit)).toBe(false);
343
+ expect(graph.data.nodes.some((n) => RING.test(n.style.innerHTML || ""))).toBe(false);
344
+ expect(problems()).toEqual([]);
345
+ });
260
346
  });