@yuneta/gobj-ui 7.31.3 → 7.31.5
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.
- package/README.md +13 -1
- package/dist/gobj-ui.cjs.js +25140 -24972
- package/dist/gobj-ui.es.js +25141 -24973
- package/package.json +1 -1
- package/src/c_g6_nodes_tree.js +3 -3
- package/src/c_yui_json_graph.js +236 -9
- package/src/json_graph_lit_edge.wiring.test.js +260 -0
package/package.json
CHANGED
package/src/c_g6_nodes_tree.js
CHANGED
|
@@ -1238,7 +1238,7 @@ function build_graph(gobj)
|
|
|
1238
1238
|
style: {
|
|
1239
1239
|
startArrow: true, // HACK target/source interchanged
|
|
1240
1240
|
endArrow: false,
|
|
1241
|
-
/* A line of
|
|
1241
|
+
/* A line of 1.6px is a 1.6px target: answer a click
|
|
1242
1242
|
* some px around it (G6's default adds 2). */
|
|
1243
1243
|
increasedLineWidthForHitTesting: 14,
|
|
1244
1244
|
},
|
|
@@ -1248,7 +1248,7 @@ function build_graph(gobj)
|
|
|
1248
1248
|
state: {
|
|
1249
1249
|
lit: () => ({
|
|
1250
1250
|
stroke: highlight_color(priv.theme),
|
|
1251
|
-
lineWidth:
|
|
1251
|
+
lineWidth: 3,
|
|
1252
1252
|
halo: true,
|
|
1253
1253
|
haloStroke: highlight_halo(priv.theme),
|
|
1254
1254
|
haloLineWidth: 8,
|
|
@@ -9391,7 +9391,7 @@ function edge_inherited_style_of(gobj, d)
|
|
|
9391
9391
|
{
|
|
9392
9392
|
let priv = gobj.priv;
|
|
9393
9393
|
let style = {
|
|
9394
|
-
lineWidth: d.is_tree ? 2
|
|
9394
|
+
lineWidth: d.is_tree ? 2 : 1.6,
|
|
9395
9395
|
stroke: default_edge_stroke(gobj, d, priv.theme),
|
|
9396
9396
|
themed_default: true,
|
|
9397
9397
|
};
|
package/src/c_yui_json_graph.js
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
gobj_publish_event,
|
|
35
35
|
gobj_save_persistent_attrs,
|
|
36
36
|
gobj_read_bool_attr,
|
|
37
|
+
gobj_read_integer_attr,
|
|
37
38
|
createElement2,
|
|
38
39
|
is_string,
|
|
39
40
|
is_array,
|
|
@@ -63,6 +64,8 @@ import {
|
|
|
63
64
|
yui_graph_update_zoom,
|
|
64
65
|
} from "./yui_graph_camera.js";
|
|
65
66
|
|
|
67
|
+
import {yui_graph_minimap_options, yui_graph_minimap_block} from "./yui_graph_minimap.js";
|
|
68
|
+
|
|
66
69
|
import {t} from "i18next";
|
|
67
70
|
|
|
68
71
|
import {
|
|
@@ -70,6 +73,7 @@ import {
|
|
|
70
73
|
ExtensionCategory,
|
|
71
74
|
Graph,
|
|
72
75
|
NodeEvent,
|
|
76
|
+
EdgeEvent,
|
|
73
77
|
CanvasEvent,
|
|
74
78
|
register,
|
|
75
79
|
} from '@antv/g6';
|
|
@@ -98,6 +102,19 @@ const GCLASS_NAME = "C_YUI_JSON_GRAPH";
|
|
|
98
102
|
*/
|
|
99
103
|
const FOLD_SWALLOWED_EVENTS = ["pointerdown", "pointerup", "mousedown", "click"];
|
|
100
104
|
|
|
105
|
+
/*
|
|
106
|
+
* A lit edge and its two ends: the amber of the schema graph and the
|
|
107
|
+
* treedb graph (C_YUI_TREEDB_SCHEMA, C_G6_NODES_TREE), one per scheme.
|
|
108
|
+
*/
|
|
109
|
+
const LIT_COLOR_DARK = "#f0a020";
|
|
110
|
+
const LIT_COLOR_LIGHT = "#b45309";
|
|
111
|
+
const LIT_HALO_DARK = "rgba(240,160,32,0.35)";
|
|
112
|
+
const LIT_HALO_LIGHT = "rgba(180,83,9,0.35)";
|
|
113
|
+
|
|
114
|
+
/* The width an edge takes a click on, in px: G6's default adds only
|
|
115
|
+
* 2 to the line's own. */
|
|
116
|
+
const EDGE_HIT_WIDTH = 14;
|
|
117
|
+
|
|
101
118
|
/*
|
|
102
119
|
* Layouts, same shape the gobj tree's registry uses
|
|
103
120
|
* (`c_yui_gobj_tree_js.js`): a G6 layout config plus the edge type
|
|
@@ -183,6 +200,7 @@ SDATA(data_type_t.DTP_STRING, "canvas_id", 0, "", "Canvas ID"),
|
|
|
183
200
|
/*---------------- Graph Settings ----------------*/
|
|
184
201
|
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"),
|
|
185
202
|
SDATA(data_type_t.DTP_STRING, "layout", 0, "json-tree", "Layout key (see LAYOUTS)"),
|
|
203
|
+
SDATA(data_type_t.DTP_INTEGER, "minimap_min_nodes", 0, 10, "Show the minimap from this many cards on (0 = never), as the treedb graph does"),
|
|
186
204
|
|
|
187
205
|
SDATA_END()
|
|
188
206
|
];
|
|
@@ -215,6 +233,12 @@ let PRIVATE_DATA = {
|
|
|
215
233
|
last_zoom: 1, // tells a wheel zoom from a drag in aftertransform
|
|
216
234
|
center_posted: false, // one re-centring in flight, never a queue of them
|
|
217
235
|
pending_keep: null, // {path,x,y}: a card to put back where it was
|
|
236
|
+
|
|
237
|
+
/*---------------- lit edge ----------------*/
|
|
238
|
+
lit_path: "", // path of the CHILD card of the lit edge: a rebuild finds it again
|
|
239
|
+
lit_parent_path: "", // path of its PARENT card
|
|
240
|
+
lit_port: "", // the parent's port the edge leaves from: its row is washed
|
|
241
|
+
lit_found: false, // the last build drew it
|
|
218
242
|
};
|
|
219
243
|
|
|
220
244
|
let __gclass__ = null;
|
|
@@ -732,7 +756,10 @@ function build_graph(gobj)
|
|
|
732
756
|
container: priv.canvas_id,
|
|
733
757
|
animation: false,
|
|
734
758
|
autoResize: false,
|
|
735
|
-
|
|
759
|
+
/* The floor was 0.1, and a document of a few hundred cards
|
|
760
|
+
* did not fit at 10%: Fit stopped there with most of it off
|
|
761
|
+
* screen. */
|
|
762
|
+
zoomRange: [0.02, 4],
|
|
736
763
|
|
|
737
764
|
node: {
|
|
738
765
|
style: {
|
|
@@ -816,8 +843,12 @@ function build_graph(gobj)
|
|
|
816
843
|
}
|
|
817
844
|
});
|
|
818
845
|
|
|
819
|
-
graph.on(
|
|
820
|
-
|
|
846
|
+
graph.on(EdgeEvent.CLICK, (evt) => {
|
|
847
|
+
gobj_send_event(gobj, "EV_EDGE_CLICK", g6_event_kw(evt), gobj);
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
graph.on(CanvasEvent.CLICK, () => {
|
|
851
|
+
gobj_send_event(gobj, "EV_CANVAS_CLICK", {}, gobj);
|
|
821
852
|
});
|
|
822
853
|
|
|
823
854
|
/*
|
|
@@ -1268,12 +1299,40 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
|
|
|
1268
1299
|
let border_color = card_matched? (dark? "#ffb300": "#ff8f00"): colors.border;
|
|
1269
1300
|
let border_width = card_matched? 2: 1;
|
|
1270
1301
|
|
|
1302
|
+
/*
|
|
1303
|
+
* The lit edge: this card is its CHILD end, or its PARENT end --
|
|
1304
|
+
* and then the row of the key the edge leaves from is washed, so
|
|
1305
|
+
* the line says which key it is.
|
|
1306
|
+
*/
|
|
1307
|
+
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;
|
|
1309
|
+
let lit_row = -1;
|
|
1310
|
+
let lit_parent = !empty_string(priv.lit_path) && path === priv.lit_parent_path;
|
|
1311
|
+
if(lit_parent) {
|
|
1312
|
+
for(let pending of pending_complex) {
|
|
1313
|
+
if(pending.port === priv.lit_port) {
|
|
1314
|
+
lit_row = pending.row;
|
|
1315
|
+
break;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
let lit_card = lit_child || lit_parent;
|
|
1320
|
+
if(lit_child) {
|
|
1321
|
+
priv.lit_found = true;
|
|
1322
|
+
}
|
|
1323
|
+
if(lit_card) {
|
|
1324
|
+
border_color = lit_color;
|
|
1325
|
+
border_width = 3;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1271
1328
|
/*
|
|
1272
1329
|
* Build node HTML content
|
|
1273
1330
|
*/
|
|
1274
|
-
let content_html = lines.map(line =>
|
|
1275
|
-
|
|
1276
|
-
|
|
1331
|
+
let content_html = lines.map((line, i) => {
|
|
1332
|
+
let wash = (i === lit_row)?
|
|
1333
|
+
` background:color-mix(in srgb, ${lit_color} 28%, transparent);` : "";
|
|
1334
|
+
return `<div style="font-family:monospace; font-size:13px; padding:1px 6px; white-space:nowrap;${wash}">${line}</div>`;
|
|
1335
|
+
}).join("");
|
|
1277
1336
|
|
|
1278
1337
|
let min_width = Math.max(180, label.length * 9);
|
|
1279
1338
|
let card_height = CARD_HEADER_H + lines.length * CARD_ROW_H;
|
|
@@ -1295,8 +1354,9 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
|
|
|
1295
1354
|
<div class="JSON_CARD" data-json-path="${escapeHtml(path)}" style="
|
|
1296
1355
|
min-width: ${min_width}px;
|
|
1297
1356
|
background: ${colors.bg};
|
|
1298
|
-
border: ${border_width}px ${is_dict ? 'dashed' : 'solid'} ${border_color};
|
|
1357
|
+
border: ${border_width}px ${(is_dict && !lit_card) ? 'dashed' : 'solid'} ${border_color};
|
|
1299
1358
|
border-radius: ${is_dict ? '6px' : '0'};
|
|
1359
|
+
${lit_card? `box-shadow: 0 0 0 4px ${dark? LIT_HALO_DARK : LIT_HALO_LIGHT};` : ""}
|
|
1300
1360
|
opacity: 0.9;
|
|
1301
1361
|
overflow: hidden;
|
|
1302
1362
|
">
|
|
@@ -1402,7 +1462,10 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
|
|
|
1402
1462
|
target: group_id,
|
|
1403
1463
|
style: {
|
|
1404
1464
|
stroke: colors.border,
|
|
1405
|
-
|
|
1465
|
+
/* 1.6 and a click 7px either side of it: a 1px line
|
|
1466
|
+
* was a 1px target. */
|
|
1467
|
+
lineWidth: 1.6,
|
|
1468
|
+
increasedLineWidthForHitTesting: EDGE_HIT_WIDTH,
|
|
1406
1469
|
/*
|
|
1407
1470
|
* Said on the EDGE and not left to the graph's element
|
|
1408
1471
|
* default: a per-element `style` is what the reader of
|
|
@@ -1425,6 +1488,17 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
|
|
|
1425
1488
|
if(parent_port) {
|
|
1426
1489
|
edge.style.sourcePort = parent_port;
|
|
1427
1490
|
}
|
|
1491
|
+
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
|
+
});
|
|
1501
|
+
}
|
|
1428
1502
|
edges.push(edge);
|
|
1429
1503
|
}
|
|
1430
1504
|
|
|
@@ -1452,6 +1526,75 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
|
|
|
1452
1526
|
return group_id;
|
|
1453
1527
|
}
|
|
1454
1528
|
|
|
1529
|
+
/************************************************************
|
|
1530
|
+
* The minimap plugin of the graph, or null when it has none.
|
|
1531
|
+
************************************************************/
|
|
1532
|
+
function minimap_plugin(gobj)
|
|
1533
|
+
{
|
|
1534
|
+
let graph = gobj.priv.graph;
|
|
1535
|
+
let plugins = graph.getPlugins() || [];
|
|
1536
|
+
if(!plugins.some((p) => typeof p === "object" && p.key === "minimap")) {
|
|
1537
|
+
return null;
|
|
1538
|
+
}
|
|
1539
|
+
return graph.getPluginInstance("minimap") || null;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
/************************************************************
|
|
1543
|
+
* Show or hide the minimap, deciding by the number of cards
|
|
1544
|
+
* about to be drawn (`n`), from `minimap_min_nodes` on -- the
|
|
1545
|
+
* rule of the gobj tree (C_YUI_GOBJ_TREE_JS), whose code this
|
|
1546
|
+
* is: called BEFORE the render, because the minimap builds its
|
|
1547
|
+
* canvas off the render events and one added after the last
|
|
1548
|
+
* render is never painted. Its blocks wear the border colour of
|
|
1549
|
+
* their card, read at each paint, so a theme switch repaints
|
|
1550
|
+
* them; the phantom a fold leaves is not drawn.
|
|
1551
|
+
************************************************************/
|
|
1552
|
+
function refresh_minimap(gobj, n)
|
|
1553
|
+
{
|
|
1554
|
+
let graph = gobj.priv.graph;
|
|
1555
|
+
let threshold = gobj_read_integer_attr(gobj, "minimap_min_nodes");
|
|
1556
|
+
let plugin = minimap_plugin(gobj);
|
|
1557
|
+
|
|
1558
|
+
if(!threshold || n < threshold) {
|
|
1559
|
+
if(plugin) {
|
|
1560
|
+
graph.setPlugins((graph.getPlugins() || []).filter(
|
|
1561
|
+
(p) => !(typeof p === "object" && p.key === "minimap")
|
|
1562
|
+
));
|
|
1563
|
+
if(!plugin.destroyed && plugin.destroy) {
|
|
1564
|
+
plugin.destroy();
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
return;
|
|
1568
|
+
}
|
|
1569
|
+
if(plugin) {
|
|
1570
|
+
return; /* already up */
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
let shape = (id, element_type, element) => {
|
|
1574
|
+
if(element_type !== "node") {
|
|
1575
|
+
return element; /* edges clone themselves fine */
|
|
1576
|
+
}
|
|
1577
|
+
try {
|
|
1578
|
+
let nd = graph.getNodeData(id);
|
|
1579
|
+
let data = (nd && nd.data) || {};
|
|
1580
|
+
if(data.phantom) {
|
|
1581
|
+
return yui_graph_minimap_block(nd, "transparent");
|
|
1582
|
+
}
|
|
1583
|
+
let colors = json_card_style(
|
|
1584
|
+
data.is_dict? GROUP_COLORS.dict : GROUP_COLORS.list, yui_is_dark()
|
|
1585
|
+
);
|
|
1586
|
+
return yui_graph_minimap_block(nd, colors.border);
|
|
1587
|
+
} catch(e) {
|
|
1588
|
+
log_error(`${gobj_short_name(gobj)}: minimap shape failed: ${e}`);
|
|
1589
|
+
return element;
|
|
1590
|
+
}
|
|
1591
|
+
};
|
|
1592
|
+
graph.setPlugins((plugins) => [
|
|
1593
|
+
...plugins,
|
|
1594
|
+
{key: "minimap", type: "minimap", ...yui_graph_minimap_options(shape)}
|
|
1595
|
+
]);
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1455
1598
|
/************************************************************
|
|
1456
1599
|
* Load JSON data into graph
|
|
1457
1600
|
************************************************************/
|
|
@@ -1477,12 +1620,26 @@ function load_json(gobj)
|
|
|
1477
1620
|
|
|
1478
1621
|
priv.node_counter = 0;
|
|
1479
1622
|
priv.match_count = 0;
|
|
1623
|
+
priv.lit_found = false;
|
|
1480
1624
|
|
|
1481
1625
|
let nodes = [];
|
|
1482
1626
|
let edges = [];
|
|
1483
1627
|
|
|
1484
1628
|
build_json_nodes(gobj, path, json, nodes, edges, null);
|
|
1485
1629
|
|
|
1630
|
+
if(!empty_string(priv.lit_path) && !priv.lit_found) {
|
|
1631
|
+
/* Its child card is gone (a fold above it): nothing is lit. */
|
|
1632
|
+
priv.lit_path = "";
|
|
1633
|
+
priv.lit_parent_path = "";
|
|
1634
|
+
priv.lit_port = "";
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
try {
|
|
1638
|
+
refresh_minimap(gobj, nodes.length);
|
|
1639
|
+
} catch(e) {
|
|
1640
|
+
log_error(`${gobj_short_name(gobj)}: refresh_minimap failed: ${e}`);
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1486
1643
|
let preserve_view = !!priv.pending_preserve_view;
|
|
1487
1644
|
priv.pending_preserve_view = false;
|
|
1488
1645
|
|
|
@@ -1931,8 +2088,11 @@ function ac_load_data(gobj, event, kw, src)
|
|
|
1931
2088
|
if(kw.data !== undefined) {
|
|
1932
2089
|
gobj_write_attr(gobj, "json_data", kw.data);
|
|
1933
2090
|
/* A new document: the folds and the space they were holding
|
|
1934
|
-
* belonged to the old one. */
|
|
2091
|
+
* belonged to the old one, and so did the lit edge. */
|
|
1935
2092
|
priv_reset_folds(gobj);
|
|
2093
|
+
gobj.priv.lit_path = "";
|
|
2094
|
+
gobj.priv.lit_parent_path = "";
|
|
2095
|
+
gobj.priv.lit_port = "";
|
|
1936
2096
|
}
|
|
1937
2097
|
|
|
1938
2098
|
refresh_json(gobj);
|
|
@@ -2112,6 +2272,69 @@ function ac_collapse_all(gobj, event, kw, src)
|
|
|
2112
2272
|
return 0;
|
|
2113
2273
|
}
|
|
2114
2274
|
|
|
2275
|
+
/************************************************************
|
|
2276
|
+
* EV_EDGE_CLICK { id }
|
|
2277
|
+
*
|
|
2278
|
+
* 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.
|
|
2283
|
+
************************************************************/
|
|
2284
|
+
function ac_edge_click(gobj, event, kw, src)
|
|
2285
|
+
{
|
|
2286
|
+
let priv = gobj.priv;
|
|
2287
|
+
let graph = priv.graph;
|
|
2288
|
+
|
|
2289
|
+
if(!graph || priv.anchor_state === "arming") {
|
|
2290
|
+
return 0; /* picking a card for the anchor: an edge is no answer */
|
|
2291
|
+
}
|
|
2292
|
+
let edge;
|
|
2293
|
+
let source;
|
|
2294
|
+
let target;
|
|
2295
|
+
try {
|
|
2296
|
+
edge = graph.getEdgeData(kw.id);
|
|
2297
|
+
source = graph.getNodeData(edge.source);
|
|
2298
|
+
target = graph.getNodeData(edge.target);
|
|
2299
|
+
} catch(e) {
|
|
2300
|
+
log_warning(`${gobj_short_name(gobj)}: EV_EDGE_CLICK of an edge not in the graph: ${kw.id}`);
|
|
2301
|
+
return -1;
|
|
2302
|
+
}
|
|
2303
|
+
let tdata = (target && target.data) || {};
|
|
2304
|
+
if(tdata.phantom || empty_string(tdata.path)) {
|
|
2305
|
+
return 0; /* the invisible edge a fold leaves */
|
|
2306
|
+
}
|
|
2307
|
+
|
|
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) || "";
|
|
2316
|
+
}
|
|
2317
|
+
refresh_json(gobj, {preserve_view: true});
|
|
2318
|
+
return 0;
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
/************************************************************
|
|
2322
|
+
* EV_CANVAS_CLICK -- a click on nothing puts the lit edge out.
|
|
2323
|
+
************************************************************/
|
|
2324
|
+
function ac_canvas_click(gobj, event, kw, src)
|
|
2325
|
+
{
|
|
2326
|
+
let priv = gobj.priv;
|
|
2327
|
+
|
|
2328
|
+
if(empty_string(priv.lit_path)) {
|
|
2329
|
+
return 0;
|
|
2330
|
+
}
|
|
2331
|
+
priv.lit_path = "";
|
|
2332
|
+
priv.lit_parent_path = "";
|
|
2333
|
+
priv.lit_port = "";
|
|
2334
|
+
refresh_json(gobj, {preserve_view: true});
|
|
2335
|
+
return 0;
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2115
2338
|
/************************************************************
|
|
2116
2339
|
*
|
|
2117
2340
|
************************************************************/
|
|
@@ -2525,6 +2748,8 @@ function create_gclass(gclass_name)
|
|
|
2525
2748
|
["EV_ZOOM_RESET", ac_zoom_reset, null],
|
|
2526
2749
|
["EV_CENTER", ac_center, null],
|
|
2527
2750
|
["EV_NODE_CLICK", ac_node_click, null],
|
|
2751
|
+
["EV_EDGE_CLICK", ac_edge_click, null],
|
|
2752
|
+
["EV_CANVAS_CLICK", ac_canvas_click, null],
|
|
2528
2753
|
["EV_TOGGLE_ANCHOR", ac_toggle_anchor, null],
|
|
2529
2754
|
["EV_CENTER_ANCHOR", ac_center_anchor, null],
|
|
2530
2755
|
["EV_RESIZE", ac_resize, null],
|
|
@@ -2550,6 +2775,8 @@ function create_gclass(gclass_name)
|
|
|
2550
2775
|
["EV_ZOOM_RESET", 0],
|
|
2551
2776
|
["EV_CENTER", 0],
|
|
2552
2777
|
["EV_NODE_CLICK", 0],
|
|
2778
|
+
["EV_EDGE_CLICK", 0],
|
|
2779
|
+
["EV_CANVAS_CLICK", 0],
|
|
2553
2780
|
["EV_TOGGLE_ANCHOR", 0],
|
|
2554
2781
|
["EV_CENTER_ANCHOR", 0],
|
|
2555
2782
|
["EV_RESIZE", 0],
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/***********************************************************************
|
|
3
|
+
* json_graph_lit_edge.wiring.test.js
|
|
4
|
+
*
|
|
5
|
+
* The JSON graph (C_YUI_JSON_GRAPH) zooms out to 2% (a document
|
|
6
|
+
* of a few hundred cards did not fit at the old 10% floor), shows
|
|
7
|
+
* a minimap from `minimap_min_nodes` cards on, and a click on an
|
|
8
|
+
* edge LIGHTS it: the line in amber, its two cards ringed, and
|
|
9
|
+
* the row of the parent's key the line leaves from washed. A
|
|
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.
|
|
12
|
+
*
|
|
13
|
+
* Driven through the real gclass, in jsdom, with a G6 double that
|
|
14
|
+
* keeps the data it is given.
|
|
15
|
+
*
|
|
16
|
+
* Copyright (c) 2026, ArtGins.
|
|
17
|
+
* All Rights Reserved.
|
|
18
|
+
***********************************************************************/
|
|
19
|
+
import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
|
|
20
|
+
|
|
21
|
+
globalThis.ResizeObserver = class {
|
|
22
|
+
observe() {
|
|
23
|
+
}
|
|
24
|
+
unobserve() {
|
|
25
|
+
}
|
|
26
|
+
disconnect() {
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const graphs = vi.hoisted(() => []);
|
|
31
|
+
vi.mock("@antv/g6", async (importOriginal) => {
|
|
32
|
+
const real = await importOriginal();
|
|
33
|
+
class FakeGraph {
|
|
34
|
+
constructor(options) {
|
|
35
|
+
this.options = options;
|
|
36
|
+
this.handlers = {};
|
|
37
|
+
this.plugins = (options.plugins || []).slice();
|
|
38
|
+
this.data = {nodes: [], edges: []};
|
|
39
|
+
graphs.push(this);
|
|
40
|
+
return new Proxy(this, {
|
|
41
|
+
get: (t, k) => (k in t) ? t[k] : (() => undefined),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
setData(data) {
|
|
45
|
+
/* Edges get the ids G6 would give them */
|
|
46
|
+
data.edges.forEach((e, i) => {
|
|
47
|
+
e.id = e.id || `e${i}`;
|
|
48
|
+
});
|
|
49
|
+
this.data = data;
|
|
50
|
+
}
|
|
51
|
+
clear() {
|
|
52
|
+
this.data = {nodes: [], edges: []};
|
|
53
|
+
}
|
|
54
|
+
render() {
|
|
55
|
+
return Promise.resolve();
|
|
56
|
+
}
|
|
57
|
+
draw() {
|
|
58
|
+
return Promise.resolve();
|
|
59
|
+
}
|
|
60
|
+
on(name, fn) {
|
|
61
|
+
(this.handlers[name] = this.handlers[name] || []).push(fn);
|
|
62
|
+
}
|
|
63
|
+
emit(name, ev) {
|
|
64
|
+
for(const fn of (this.handlers[name] || [])) {
|
|
65
|
+
fn(ev);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
getZoom() {
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
getPosition() {
|
|
72
|
+
return [0, 0];
|
|
73
|
+
}
|
|
74
|
+
zoomTo() {
|
|
75
|
+
return Promise.resolve();
|
|
76
|
+
}
|
|
77
|
+
translateTo() {
|
|
78
|
+
return Promise.resolve();
|
|
79
|
+
}
|
|
80
|
+
getData() {
|
|
81
|
+
return this.data;
|
|
82
|
+
}
|
|
83
|
+
getNodeData(id) {
|
|
84
|
+
if(id === undefined) {
|
|
85
|
+
return this.data.nodes;
|
|
86
|
+
}
|
|
87
|
+
const nd = this.data.nodes.find((n) => n.id === id);
|
|
88
|
+
if(!nd) {
|
|
89
|
+
throw new Error(`node ${id} not found`);
|
|
90
|
+
}
|
|
91
|
+
return nd;
|
|
92
|
+
}
|
|
93
|
+
getEdgeData(id) {
|
|
94
|
+
const ed = this.data.edges.find((e) => e.id === id);
|
|
95
|
+
if(!ed) {
|
|
96
|
+
throw new Error(`edge ${id} not found`);
|
|
97
|
+
}
|
|
98
|
+
return ed;
|
|
99
|
+
}
|
|
100
|
+
getPlugins() {
|
|
101
|
+
return this.plugins;
|
|
102
|
+
}
|
|
103
|
+
setPlugins(p) {
|
|
104
|
+
this.plugins = (typeof p === "function")? p(this.plugins) : p;
|
|
105
|
+
}
|
|
106
|
+
getPluginInstance() {
|
|
107
|
+
return {destroyed: false, destroy() {
|
|
108
|
+
}};
|
|
109
|
+
}
|
|
110
|
+
getBehaviors() {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
getOptions() {
|
|
114
|
+
return {behaviors: []};
|
|
115
|
+
}
|
|
116
|
+
getCanvas() {
|
|
117
|
+
return {getLayers: () => ({}), getContainer: () => null};
|
|
118
|
+
}
|
|
119
|
+
fitView() {
|
|
120
|
+
return Promise.resolve();
|
|
121
|
+
}
|
|
122
|
+
destroy() {
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return {...real, Graph: FakeGraph};
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const {
|
|
129
|
+
SDATA_END, gclass_create, gobj_start_up, gobj_create_yuno, gobj_create_pure_child,
|
|
130
|
+
gobj_start, gobj_read_attr, gobj_send_event, set_log_callback, register_c_timer,
|
|
131
|
+
} = await import("@yuneta/gobj-js");
|
|
132
|
+
const {EdgeEvent, CanvasEvent} = await import("@antv/g6");
|
|
133
|
+
const {register_c_yui_json_graph} = await import("./c_yui_json_graph.js");
|
|
134
|
+
|
|
135
|
+
const logged = [];
|
|
136
|
+
let yuno = null;
|
|
137
|
+
let seq = 0;
|
|
138
|
+
|
|
139
|
+
beforeAll(async () => {
|
|
140
|
+
const i18next = (await import("i18next")).default;
|
|
141
|
+
await i18next.init({lng: "en", resources: {en: {translation: {}}}});
|
|
142
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
143
|
+
set_log_callback((level, msg) => {
|
|
144
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
145
|
+
});
|
|
146
|
+
register_c_timer();
|
|
147
|
+
register_c_yui_json_graph();
|
|
148
|
+
gclass_create("C_TEST_JG_YUNO", [], [["ST_IDLE", []]], {}, 0,
|
|
149
|
+
[SDATA_END()], {}, 0, 0, 0, 0);
|
|
150
|
+
yuno = gobj_create_yuno("jg_yuno", "C_TEST_JG_YUNO", {});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
beforeEach(() => {
|
|
154
|
+
logged.length = 0;
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
function settle()
|
|
158
|
+
{
|
|
159
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function mount(json, attrs)
|
|
163
|
+
{
|
|
164
|
+
const $container = document.createElement("div");
|
|
165
|
+
document.body.appendChild($container);
|
|
166
|
+
const view = gobj_create_pure_child(`json-lit-${++seq}`, "C_YUI_JSON_GRAPH",
|
|
167
|
+
Object.assign({$container: $container, json_data: json}, attrs || {}), yuno);
|
|
168
|
+
document.body.appendChild(gobj_read_attr(view, "$container"));
|
|
169
|
+
gobj_start(view);
|
|
170
|
+
await settle();
|
|
171
|
+
return {view, graph: graphs[graphs.length - 1]};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const DOC = {a: 1, b: {x: 1, y: {z: 2}}, c: [1, 2]};
|
|
175
|
+
|
|
176
|
+
/* The edge to the card of `path`, and the card of a path */
|
|
177
|
+
function edge_to(graph, path)
|
|
178
|
+
{
|
|
179
|
+
const nd = graph.data.nodes.find((n) => n.data && n.data.path === path && !n.data.phantom);
|
|
180
|
+
return graph.data.edges.find((e) => e.target === nd.id);
|
|
181
|
+
}
|
|
182
|
+
function card(graph, path)
|
|
183
|
+
{
|
|
184
|
+
return graph.data.nodes.find((n) => n.data && n.data.path === path && !n.data.phantom).style.innerHTML;
|
|
185
|
+
}
|
|
186
|
+
const RING = /border: 3px solid/;
|
|
187
|
+
const WASH = /background:color-mix\(in srgb, #[0-9a-f]+ 28%, transparent\)/g;
|
|
188
|
+
|
|
189
|
+
function problems()
|
|
190
|
+
{
|
|
191
|
+
return logged.filter((l) => l.level === "error" || l.level === "warning").map((l) => l.msg);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
describe("C_YUI_JSON_GRAPH: zoom floor, minimap, lit edge", () => {
|
|
195
|
+
test("the zoom goes down to 2%, and an edge takes a click well around its line", async () => {
|
|
196
|
+
const {graph} = await mount(DOC);
|
|
197
|
+
expect(graph.options.zoomRange[0]).toBeLessThanOrEqual(0.02);
|
|
198
|
+
for(const e of graph.data.edges) {
|
|
199
|
+
if(e.style.opacity === 0) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
expect(e.style.increasedLineWidthForHitTesting).toBeGreaterThanOrEqual(10);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("the minimap is there from minimap_min_nodes cards on, and not below", async () => {
|
|
207
|
+
const few = await mount(DOC, {minimap_min_nodes: 10});
|
|
208
|
+
expect(few.graph.plugins.some((p) => p.key === "minimap")).toBe(false);
|
|
209
|
+
const many = await mount(DOC, {minimap_min_nodes: 2});
|
|
210
|
+
const minimap = many.graph.plugins.find((p) => p.key === "minimap");
|
|
211
|
+
expect(minimap).toBeTruthy();
|
|
212
|
+
expect(minimap.containerStyle).toMatchObject({top: "auto", bottom: "12px", left: "12px"});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("an edge click lights the line, its two cards and the parent's row; again puts it out", async () => {
|
|
216
|
+
const {graph} = await mount(DOC);
|
|
217
|
+
const root = graph.data.nodes[0].data.path;
|
|
218
|
+
const child = graph.data.nodes.find((n) => n.data && n.data.path !== root && !n.data.phantom).data.path;
|
|
219
|
+
expect(card(graph, child)).not.toMatch(RING);
|
|
220
|
+
|
|
221
|
+
graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, child).id}});
|
|
222
|
+
await settle();
|
|
223
|
+
|
|
224
|
+
const lit = edge_to(graph, child);
|
|
225
|
+
expect(lit.style.lineWidth).toBe(3);
|
|
226
|
+
expect(lit.style.halo).toBe(true);
|
|
227
|
+
expect(card(graph, child)).toMatch(RING);
|
|
228
|
+
expect(card(graph, root)).toMatch(RING);
|
|
229
|
+
expect((card(graph, root).match(WASH) || []).length).toBe(1);
|
|
230
|
+
/* only those two */
|
|
231
|
+
const ringed = graph.data.nodes.filter((n) => RING.test(n.style.innerHTML || ""));
|
|
232
|
+
expect(ringed.length).toBe(2);
|
|
233
|
+
|
|
234
|
+
graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, child).id}});
|
|
235
|
+
await settle();
|
|
236
|
+
expect(edge_to(graph, child).style.lineWidth).not.toBe(3);
|
|
237
|
+
expect(card(graph, root)).not.toMatch(RING);
|
|
238
|
+
expect(problems()).toEqual([]);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test("a canvas click puts it out; a new document starts with nothing lit", async () => {
|
|
242
|
+
const {view, graph} = await mount(DOC);
|
|
243
|
+
const root = graph.data.nodes[0].data.path;
|
|
244
|
+
const child = graph.data.nodes.find((n) => n.data && n.data.path !== root && !n.data.phantom).data.path;
|
|
245
|
+
|
|
246
|
+
graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, child).id}});
|
|
247
|
+
await settle();
|
|
248
|
+
expect(card(graph, child)).toMatch(RING);
|
|
249
|
+
graph.emit(CanvasEvent.CLICK, {});
|
|
250
|
+
await settle();
|
|
251
|
+
expect(card(graph, child)).not.toMatch(RING);
|
|
252
|
+
|
|
253
|
+
graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, child).id}});
|
|
254
|
+
await settle();
|
|
255
|
+
gobj_send_event(view, "EV_LOAD_DATA", {data: DOC}, view);
|
|
256
|
+
await settle();
|
|
257
|
+
expect(graph.data.nodes.some((n) => RING.test(n.style.innerHTML || ""))).toBe(false);
|
|
258
|
+
expect(problems()).toEqual([]);
|
|
259
|
+
});
|
|
260
|
+
});
|