@yuneta/gobj-ui 7.5.6 → 7.5.7

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,20 +55732,9 @@ 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;
55736
+ if (priv._nodes_total > 0 && priv._nodes_placed * 2 > priv._nodes_total) return;
55737
+ if (!priv.graph) return;
55764
55738
  let name = "dagre";
55765
55739
  (0, _yuneta_gobj_js.gobj_write_attr)(gobj, "layout", name);
55766
55740
  try {
@@ -55769,7 +55743,6 @@ function auto_layout(gobj) {
55769
55743
  (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: cannot set the '${name}' layout: ${e}`);
55770
55744
  return;
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 });
55774
55747
  }
55775
55748
  /************************************************************
@@ -56569,10 +56542,12 @@ function ac_descs(gobj, event, kw, src) {
56569
56542
  * Clear all graph data, from parent
56570
56543
  ************************************************************/
56571
56544
  function ac_clear_data(gobj, event, kw, src) {
56572
- gobj.priv;
56545
+ let priv = gobj.priv;
56573
56546
  deselect_node(gobj);
56574
56547
  hide_create_popover(gobj);
56575
56548
  (0, _yuneta_gobj_js.gobj_write_attr)(gobj, "records", {});
56549
+ priv._nodes_total = 0;
56550
+ priv._nodes_placed = 0;
56576
56551
  graph_remove_plugin(gobj, "history");
56577
56552
  update_history_buttons(gobj);
56578
56553
  graph_clear(gobj);
@@ -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,20 +55719,9 @@ 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;
55723
+ if (priv._nodes_total > 0 && priv._nodes_placed * 2 > priv._nodes_total) return;
55724
+ if (!priv.graph) return;
55751
55725
  let name = "dagre";
55752
55726
  gobj_write_attr(gobj, "layout", name);
55753
55727
  try {
@@ -55756,7 +55730,6 @@ function auto_layout(gobj) {
55756
55730
  log_error(`${gobj_short_name(gobj)}: cannot set the '${name}' layout: ${e}`);
55757
55731
  return;
55758
55732
  }
55759
- log_warning(`${gobj_short_name(gobj)}: AL: set dagre, publishing`);
55760
55733
  gobj_publish_event(gobj, "EV_LAYOUT_AUTOSET", { layout: name });
55761
55734
  }
55762
55735
  /************************************************************
@@ -56556,10 +56529,12 @@ function ac_descs(gobj, event, kw, src) {
56556
56529
  * Clear all graph data, from parent
56557
56530
  ************************************************************/
56558
56531
  function ac_clear_data(gobj, event, kw, src) {
56559
- gobj.priv;
56532
+ let priv = gobj.priv;
56560
56533
  deselect_node(gobj);
56561
56534
  hide_create_popover(gobj);
56562
56535
  gobj_write_attr(gobj, "records", {});
56536
+ priv._nodes_total = 0;
56537
+ priv._nodes_placed = 0;
56563
56538
  graph_remove_plugin(gobj, "history");
56564
56539
  update_history_buttons(gobj);
56565
56540
  graph_clear(gobj);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.5.6",
3
+ "version": "7.5.7",
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,7 +4544,6 @@ 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
4547
  return; /* the user picked one for this treedb */
4566
4548
  }
4567
4549
  /* MOST of the nodes, not one of them.
@@ -4571,14 +4553,13 @@ 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`);
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) {
4578
4560
  return; /* 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
4563
  return;
4583
4564
  }
4584
4565
 
@@ -4592,7 +4573,6 @@ function auto_layout(gobj)
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});
4597
4577
  }
4598
4578
 
@@ -5796,6 +5776,11 @@ function ac_clear_data(gobj, event, kw, src)
5796
5776
 
5797
5777
  gobj_write_attr(gobj, "records", {});
5798
5778
 
5779
+ /* The node counters belong to the data that is going away: a refresh
5780
+ * that kept them would decide the layout on the previous treedb. */
5781
+ priv._nodes_total = 0;
5782
+ priv._nodes_placed = 0;
5783
+
5799
5784
  graph_remove_plugin(gobj, "history");
5800
5785
  update_history_buttons(gobj);
5801
5786
  graph_clear(gobj);