@yuneta/gobj-ui 7.5.6 → 7.6.0

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.
@@ -52923,7 +52923,9 @@ var PRIVATE_DATA$1 = {
52923
52923
  _focus_ids: [],
52924
52924
  _pending_focus_topic: null,
52925
52925
  _pending_find: null,
52926
- _layout_asked: ""
52926
+ _layout_asked: "",
52927
+ _nodes_total: 0,
52928
+ _nodes_placed: 0
52927
52929
  };
52928
52930
  var __gclass__$1 = null;
52929
52931
  /******************************
@@ -53494,6 +53496,8 @@ function create_topic_node(gobj, desc, record) {
53494
53496
  let node_name = build_node_name(gobj, desc.topic_name, record.id);
53495
53497
  let xy = get_default_ne_xy(gobj);
53496
53498
  let geometry = get_node_graph_props(gobj, desc.topic_name, record.id, record);
53499
+ priv._nodes_total++;
53500
+ if (geometry_has_position(geometry)) priv._nodes_placed++;
53497
53501
  let x = (0, _yuneta_gobj_js.kw_get_int)(gobj, geometry, "x", xy, _yuneta_gobj_js.kw_flag_t.KW_CREATE);
53498
53502
  let y = (0, _yuneta_gobj_js.kw_get_int)(gobj, geometry, "y", xy, _yuneta_gobj_js.kw_flag_t.KW_CREATE);
53499
53503
  let ports = build_ports(gobj, desc);
@@ -55701,35 +55705,16 @@ function show_node_detail_popover(gobj, node_id) {
55701
55705
  * junction diamonds get their neutral fill/stroke re-themed.
55702
55706
  ************************************************************/
55703
55707
  /************************************************************
55704
- * How many nodes of this treedb carry a saved position, and how many
55705
- * there are. Positions live in `__graphs__` (per topic, per node) and,
55706
- * on older data, in a `_geometry` on the record itself; both are read.
55708
+ * Does this geometry carry a POSITION?
55709
+ *
55710
+ * An empty object does not. A treedb hands back `_geometry: {}` for a
55711
+ * record nobody ever moved, and a `__graphs__` node entry can hold a
55712
+ * port size and no coordinates — both are objects all the same.
55707
55713
  ************************************************************/
55708
55714
  function geometry_has_position(g) {
55709
55715
  if (!(0, _yuneta_gobj_js.is_object)(g)) return false;
55710
55716
  return (0, _yuneta_gobj_js.is_number)(g.x) || (0, _yuneta_gobj_js.is_number)(g.y);
55711
55717
  }
55712
- function count_saved_geometry(gobj) {
55713
- let priv = gobj.priv;
55714
- let saved = 0;
55715
- let total = 0;
55716
- for (let topic of Object.keys(priv.records || {})) {
55717
- let records = priv.records[topic];
55718
- if (!(0, _yuneta_gobj_js.is_array)(records)) continue;
55719
- let props = priv._graph_properties ? priv._graph_properties[topic] : null;
55720
- let nodes = props && (0, _yuneta_gobj_js.is_object)(props.nodes) ? props.nodes : null;
55721
- for (let record of records) {
55722
- if (!record) continue;
55723
- total++;
55724
- if (nodes && geometry_has_position(nodes[record.id])) saved++;
55725
- else if (geometry_has_position(record._geometry)) saved++;
55726
- }
55727
- }
55728
- return {
55729
- saved,
55730
- total
55731
- };
55732
- }
55733
55718
  /************************************************************
55734
55719
  * Choose a layout for a treedb nobody has arranged yet.
55735
55720
  *
@@ -55747,30 +55732,19 @@ function count_saved_geometry(gobj) {
55747
55732
  ************************************************************/
55748
55733
  function auto_layout(gobj) {
55749
55734
  let priv = gobj.priv;
55750
- if (priv._layout_asked) {
55751
- (0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: AL: bail asked='${priv._layout_asked}'`);
55752
- return;
55753
- }
55754
- let g = count_saved_geometry(gobj);
55755
- (0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: AL: saved=${g.saved}/${g.total} graph=${!!priv.graph}`);
55756
- if (g.total > 0 && g.saved * 2 > g.total) {
55757
- (0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: AL: bail majority`);
55758
- return;
55759
- }
55760
- if (!priv.graph) {
55761
- (0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: AL: bail no graph`);
55762
- return;
55763
- }
55735
+ if (priv._layout_asked) return false;
55736
+ if (priv._nodes_total > 0 && priv._nodes_placed * 2 > priv._nodes_total) return false;
55737
+ if (!priv.graph) return false;
55764
55738
  let name = "dagre";
55765
55739
  (0, _yuneta_gobj_js.gobj_write_attr)(gobj, "layout", name);
55766
55740
  try {
55767
55741
  priv.graph.setLayout(_layouts[name]);
55768
55742
  } catch (e) {
55769
55743
  (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: cannot set the '${name}' layout: ${e}`);
55770
- return;
55744
+ return false;
55771
55745
  }
55772
- (0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: AL: set dagre, publishing`);
55773
55746
  (0, _yuneta_gobj_js.gobj_publish_event)(gobj, "EV_LAYOUT_AUTOSET", { layout: name });
55747
+ return true;
55774
55748
  }
55775
55749
  /************************************************************
55776
55750
  * Show or hide the minimap, deciding by the SIZE of the graph.
@@ -56569,10 +56543,12 @@ function ac_descs(gobj, event, kw, src) {
56569
56543
  * Clear all graph data, from parent
56570
56544
  ************************************************************/
56571
56545
  function ac_clear_data(gobj, event, kw, src) {
56572
- gobj.priv;
56546
+ let priv = gobj.priv;
56573
56547
  deselect_node(gobj);
56574
56548
  hide_create_popover(gobj);
56575
56549
  (0, _yuneta_gobj_js.gobj_write_attr)(gobj, "records", {});
56550
+ priv._nodes_total = 0;
56551
+ priv._nodes_placed = 0;
56576
56552
  graph_remove_plugin(gobj, "history");
56577
56553
  update_history_buttons(gobj);
56578
56554
  graph_clear(gobj);
@@ -56627,12 +56603,16 @@ function ac_load_data(gobj, event, kw, src) {
56627
56603
  graph_draw(gobj).then(() => {
56628
56604
  create_links(gobj);
56629
56605
  graph_draw(gobj).then(() => {
56606
+ let auto_laid = false;
56630
56607
  try {
56631
- auto_layout(gobj);
56608
+ auto_laid = auto_layout(gobj);
56632
56609
  } catch (e) {
56633
56610
  (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: auto_layout failed: ${e}`);
56634
56611
  }
56635
56612
  graph_layout(gobj).then(() => {
56613
+ if (auto_laid) graph_fitview(gobj).catch((e) => {
56614
+ (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: cannot fit the graph: ${e}`);
56615
+ });
56636
56616
  if (priv.edit_mode) graph_add_plugin(gobj, "history");
56637
56617
  else graph_remove_plugin(gobj, "history");
56638
56618
  if (priv._pending_focus_topic !== null) {
@@ -52910,7 +52910,9 @@ var PRIVATE_DATA$1 = {
52910
52910
  _focus_ids: [],
52911
52911
  _pending_focus_topic: null,
52912
52912
  _pending_find: null,
52913
- _layout_asked: ""
52913
+ _layout_asked: "",
52914
+ _nodes_total: 0,
52915
+ _nodes_placed: 0
52914
52916
  };
52915
52917
  var __gclass__$1 = null;
52916
52918
  /******************************
@@ -53481,6 +53483,8 @@ function create_topic_node(gobj, desc, record) {
53481
53483
  let node_name = build_node_name(gobj, desc.topic_name, record.id);
53482
53484
  let xy = get_default_ne_xy(gobj);
53483
53485
  let geometry = get_node_graph_props(gobj, desc.topic_name, record.id, record);
53486
+ priv._nodes_total++;
53487
+ if (geometry_has_position(geometry)) priv._nodes_placed++;
53484
53488
  let x = kw_get_int(gobj, geometry, "x", xy, kw_flag_t.KW_CREATE);
53485
53489
  let y = kw_get_int(gobj, geometry, "y", xy, kw_flag_t.KW_CREATE);
53486
53490
  let ports = build_ports(gobj, desc);
@@ -55688,35 +55692,16 @@ function show_node_detail_popover(gobj, node_id) {
55688
55692
  * junction diamonds get their neutral fill/stroke re-themed.
55689
55693
  ************************************************************/
55690
55694
  /************************************************************
55691
- * How many nodes of this treedb carry a saved position, and how many
55692
- * there are. Positions live in `__graphs__` (per topic, per node) and,
55693
- * on older data, in a `_geometry` on the record itself; both are read.
55695
+ * Does this geometry carry a POSITION?
55696
+ *
55697
+ * An empty object does not. A treedb hands back `_geometry: {}` for a
55698
+ * record nobody ever moved, and a `__graphs__` node entry can hold a
55699
+ * port size and no coordinates — both are objects all the same.
55694
55700
  ************************************************************/
55695
55701
  function geometry_has_position(g) {
55696
55702
  if (!is_object(g)) return false;
55697
55703
  return is_number(g.x) || is_number(g.y);
55698
55704
  }
55699
- function count_saved_geometry(gobj) {
55700
- let priv = gobj.priv;
55701
- let saved = 0;
55702
- let total = 0;
55703
- for (let topic of Object.keys(priv.records || {})) {
55704
- let records = priv.records[topic];
55705
- if (!is_array(records)) continue;
55706
- let props = priv._graph_properties ? priv._graph_properties[topic] : null;
55707
- let nodes = props && is_object(props.nodes) ? props.nodes : null;
55708
- for (let record of records) {
55709
- if (!record) continue;
55710
- total++;
55711
- if (nodes && geometry_has_position(nodes[record.id])) saved++;
55712
- else if (geometry_has_position(record._geometry)) saved++;
55713
- }
55714
- }
55715
- return {
55716
- saved,
55717
- total
55718
- };
55719
- }
55720
55705
  /************************************************************
55721
55706
  * Choose a layout for a treedb nobody has arranged yet.
55722
55707
  *
@@ -55734,30 +55719,19 @@ function count_saved_geometry(gobj) {
55734
55719
  ************************************************************/
55735
55720
  function auto_layout(gobj) {
55736
55721
  let priv = gobj.priv;
55737
- if (priv._layout_asked) {
55738
- log_warning(`${gobj_short_name(gobj)}: AL: bail asked='${priv._layout_asked}'`);
55739
- return;
55740
- }
55741
- let g = count_saved_geometry(gobj);
55742
- log_warning(`${gobj_short_name(gobj)}: AL: saved=${g.saved}/${g.total} graph=${!!priv.graph}`);
55743
- if (g.total > 0 && g.saved * 2 > g.total) {
55744
- log_warning(`${gobj_short_name(gobj)}: AL: bail majority`);
55745
- return;
55746
- }
55747
- if (!priv.graph) {
55748
- log_warning(`${gobj_short_name(gobj)}: AL: bail no graph`);
55749
- return;
55750
- }
55722
+ if (priv._layout_asked) return false;
55723
+ if (priv._nodes_total > 0 && priv._nodes_placed * 2 > priv._nodes_total) return false;
55724
+ if (!priv.graph) return false;
55751
55725
  let name = "dagre";
55752
55726
  gobj_write_attr(gobj, "layout", name);
55753
55727
  try {
55754
55728
  priv.graph.setLayout(_layouts[name]);
55755
55729
  } catch (e) {
55756
55730
  log_error(`${gobj_short_name(gobj)}: cannot set the '${name}' layout: ${e}`);
55757
- return;
55731
+ return false;
55758
55732
  }
55759
- log_warning(`${gobj_short_name(gobj)}: AL: set dagre, publishing`);
55760
55733
  gobj_publish_event(gobj, "EV_LAYOUT_AUTOSET", { layout: name });
55734
+ return true;
55761
55735
  }
55762
55736
  /************************************************************
55763
55737
  * Show or hide the minimap, deciding by the SIZE of the graph.
@@ -56556,10 +56530,12 @@ function ac_descs(gobj, event, kw, src) {
56556
56530
  * Clear all graph data, from parent
56557
56531
  ************************************************************/
56558
56532
  function ac_clear_data(gobj, event, kw, src) {
56559
- gobj.priv;
56533
+ let priv = gobj.priv;
56560
56534
  deselect_node(gobj);
56561
56535
  hide_create_popover(gobj);
56562
56536
  gobj_write_attr(gobj, "records", {});
56537
+ priv._nodes_total = 0;
56538
+ priv._nodes_placed = 0;
56563
56539
  graph_remove_plugin(gobj, "history");
56564
56540
  update_history_buttons(gobj);
56565
56541
  graph_clear(gobj);
@@ -56614,12 +56590,16 @@ function ac_load_data(gobj, event, kw, src) {
56614
56590
  graph_draw(gobj).then(() => {
56615
56591
  create_links(gobj);
56616
56592
  graph_draw(gobj).then(() => {
56593
+ let auto_laid = false;
56617
56594
  try {
56618
- auto_layout(gobj);
56595
+ auto_laid = auto_layout(gobj);
56619
56596
  } catch (e) {
56620
56597
  log_error(`${gobj_short_name(gobj)}: auto_layout failed: ${e}`);
56621
56598
  }
56622
56599
  graph_layout(gobj).then(() => {
56600
+ if (auto_laid) graph_fitview(gobj).catch((e) => {
56601
+ log_error(`${gobj_short_name(gobj)}: cannot fit the graph: ${e}`);
56602
+ });
56623
56603
  if (priv.edit_mode) graph_add_plugin(gobj, "history");
56624
56604
  else graph_remove_plugin(gobj, "history");
56625
56605
  if (priv._pending_focus_topic !== null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.5.6",
3
+ "version": "7.6.0",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -293,6 +293,8 @@ let PRIVATE_DATA = {
293
293
  _pending_focus_topic: null, // focus requested before data was loaded
294
294
  _pending_find: null, // find requested before data was loaded
295
295
  _layout_asked: "", // layout the host asked for at create (see mt_create)
296
+ _nodes_total: 0, // nodes built so far (auto_layout)
297
+ _nodes_placed: 0, // ...of which carried a saved position
296
298
  };
297
299
 
298
300
  let __gclass__ = null;
@@ -1224,6 +1226,19 @@ function create_topic_node(gobj, desc, record)
1224
1226
  let node_name = build_node_name(gobj, desc.topic_name, record.id);
1225
1227
  let xy = get_default_ne_xy(gobj);
1226
1228
  let geometry = get_node_graph_props(gobj, desc.topic_name, record.id, record);
1229
+
1230
+ /* Counted HERE, and before the two kw_get_int() below, because those
1231
+ * carry KW_CREATE: `get_node_graph_props()` hands back the record's own
1232
+ * `_geometry` object when it has one — and `{}` is one — so the very
1233
+ * next lines WRITE the invented cascade coordinates into it. Ask the
1234
+ * question a moment later and every node of every treedb answers
1235
+ * "placed", which is exactly how the dagre default kept refusing to
1236
+ * fire: 126 of 126, all of them positions the app had just made up. */
1237
+ priv._nodes_total++;
1238
+ if(geometry_has_position(geometry)) {
1239
+ priv._nodes_placed++;
1240
+ }
1241
+
1227
1242
  let x = kw_get_int(gobj, geometry, "x", xy, kw_flag_t.KW_CREATE);
1228
1243
  let y = kw_get_int(gobj, geometry, "y", xy, kw_flag_t.KW_CREATE);
1229
1244
 
@@ -4495,52 +4510,20 @@ function show_node_detail_popover(gobj, node_id)
4495
4510
  * junction diamonds get their neutral fill/stroke re-themed.
4496
4511
  ************************************************************/
4497
4512
  /************************************************************
4498
- * How many nodes of this treedb carry a saved position, and how many
4499
- * there are. Positions live in `__graphs__` (per topic, per node) and,
4500
- * on older data, in a `_geometry` on the record itself; both are read.
4513
+ * Does this geometry carry a POSITION?
4514
+ *
4515
+ * An empty object does not. A treedb hands back `_geometry: {}` for a
4516
+ * record nobody ever moved, and a `__graphs__` node entry can hold a
4517
+ * port size and no coordinates — both are objects all the same.
4501
4518
  ************************************************************/
4502
4519
  function geometry_has_position(g)
4503
4520
  {
4504
- /* An EMPTY object is not a position. A treedb hands back
4505
- * `_geometry: {}` for a record nobody ever moved, and a `__graphs__`
4506
- * node entry can hold a port size with no coordinates — both are
4507
- * objects, and taking either for "this was placed" is wrong. */
4508
4521
  if(!is_object(g)) {
4509
4522
  return false;
4510
4523
  }
4511
4524
  return is_number(g.x) || is_number(g.y);
4512
4525
  }
4513
4526
 
4514
- function count_saved_geometry(gobj)
4515
- {
4516
- let priv = gobj.priv;
4517
- let saved = 0;
4518
- let total = 0;
4519
-
4520
- for(let topic of Object.keys(priv.records || {})) {
4521
- let records = priv.records[topic];
4522
- if(!is_array(records)) {
4523
- continue;
4524
- }
4525
- let props = priv._graph_properties? priv._graph_properties[topic] : null;
4526
- let nodes = (props && is_object(props.nodes))? props.nodes : null;
4527
-
4528
- for(let record of records) {
4529
- if(!record) {
4530
- continue;
4531
- }
4532
- total++;
4533
- if(nodes && geometry_has_position(nodes[record.id])) {
4534
- saved++;
4535
- } else if(geometry_has_position(record._geometry)) {
4536
- saved++;
4537
- }
4538
- }
4539
- }
4540
-
4541
- return {saved: saved, total: total};
4542
- }
4543
-
4544
4527
  /************************************************************
4545
4528
  * Choose a layout for a treedb nobody has arranged yet.
4546
4529
  *
@@ -4561,8 +4544,7 @@ function auto_layout(gobj)
4561
4544
  let priv = gobj.priv;
4562
4545
 
4563
4546
  if(priv._layout_asked) {
4564
- log_warning(`${gobj_short_name(gobj)}: AL: bail asked='${priv._layout_asked}'`);
4565
- return; /* the user picked one for this treedb */
4547
+ return false; /* the user picked one for this treedb */
4566
4548
  }
4567
4549
  /* MOST of the nodes, not one of them.
4568
4550
  *
@@ -4571,15 +4553,14 @@ function auto_layout(gobj)
4571
4553
  * that forced this had exactly ONE node of 126 carrying a geometry,
4572
4554
  * and it was `{x:100, y:100}` — the first cascade slot, saved. One
4573
4555
  * leftover is not an arrangement. A majority is. */
4574
- let g = count_saved_geometry(gobj);
4575
- log_warning(`${gobj_short_name(gobj)}: AL: saved=${g.saved}/${g.total} graph=${!!priv.graph}`);
4576
- if(g.total > 0 && g.saved * 2 > g.total) {
4577
- log_warning(`${gobj_short_name(gobj)}: AL: bail majority`);
4578
- return; /* somebody arranged it: leave it alone */
4556
+ /* MOST of the nodes, not one of them: the app saves a position it
4557
+ * invented as readily as one a human chose, so a single stored
4558
+ * coordinate proves nothing. One leftover is not an arrangement. */
4559
+ if(priv._nodes_total > 0 && priv._nodes_placed * 2 > priv._nodes_total) {
4560
+ return false; /* somebody arranged it: leave it alone */
4579
4561
  }
4580
4562
  if(!priv.graph) {
4581
- log_warning(`${gobj_short_name(gobj)}: AL: bail no graph`);
4582
- return;
4563
+ return false;
4583
4564
  }
4584
4565
 
4585
4566
  let name = "dagre";
@@ -4588,12 +4569,12 @@ function auto_layout(gobj)
4588
4569
  priv.graph.setLayout(_layouts[name]);
4589
4570
  } catch(e) {
4590
4571
  log_error(`${gobj_short_name(gobj)}: cannot set the '${name}' layout: ${e}`);
4591
- return;
4572
+ return false;
4592
4573
  }
4593
4574
  /* The toolbar's select was filled before the data arrived, so it is
4594
4575
  * still showing `manual`: tell it what the graph is actually doing. */
4595
- log_warning(`${gobj_short_name(gobj)}: AL: set dagre, publishing`);
4596
4576
  gobj_publish_event(gobj, "EV_LAYOUT_AUTOSET", {layout: name});
4577
+ return true;
4597
4578
  }
4598
4579
 
4599
4580
  /************************************************************
@@ -5796,6 +5777,11 @@ function ac_clear_data(gobj, event, kw, src)
5796
5777
 
5797
5778
  gobj_write_attr(gobj, "records", {});
5798
5779
 
5780
+ /* The node counters belong to the data that is going away: a refresh
5781
+ * that kept them would decide the layout on the previous treedb. */
5782
+ priv._nodes_total = 0;
5783
+ priv._nodes_placed = 0;
5784
+
5799
5785
  graph_remove_plugin(gobj, "history");
5800
5786
  update_history_buttons(gobj);
5801
5787
  graph_clear(gobj);
@@ -5886,12 +5872,24 @@ function ac_load_data(gobj, event, kw, src)
5886
5872
  /* Before the layout runs, and only now: whether anybody has
5887
5873
  * ever placed a node of this treedb is not known until its
5888
5874
  * records and __graphs__ are in. */
5875
+ let auto_laid = false;
5889
5876
  try {
5890
- auto_layout(gobj);
5877
+ auto_laid = auto_layout(gobj);
5891
5878
  } catch(e) {
5892
5879
  log_error(`${gobj_short_name(gobj)}: auto_layout failed: ${e}`);
5893
5880
  }
5894
5881
  graph_layout(gobj).then(() => {
5882
+ /* A graph laid out by us opens WHOLE. dagre spreads a
5883
+ * 126-node treedb over some 19000px, and the camera is
5884
+ * wherever it was: without this you get eight cards in
5885
+ * the top-left corner and no reason to think there are
5886
+ * 118 more. Only when WE laid it out — a saved
5887
+ * arrangement includes where its owner was looking. */
5888
+ if(auto_laid) {
5889
+ graph_fitview(gobj).catch((e) => {
5890
+ log_error(`${gobj_short_name(gobj)}: cannot fit the graph: ${e}`);
5891
+ });
5892
+ }
5895
5893
  if(priv.edit_mode) {
5896
5894
  graph_add_plugin(gobj, "history");
5897
5895
  } else {