@yuneta/gobj-ui 7.5.7 → 7.6.1

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.
@@ -54062,6 +54062,25 @@ async function graph_center(gobj) {
54062
54062
  async function graph_fitview(gobj) {
54063
54063
  await gobj.priv.graph.fitView();
54064
54064
  }
54065
+ var MIN_READABLE_ZOOM = .5;
54066
+ /************************************************************
54067
+ * Fit the graph in the viewport, but never zoom out past the point
54068
+ * where nothing on a card can be read.
54069
+ *
54070
+ * A wide fan — a schema treedb is one topic and a hundred columns —
54071
+ * fits at about 0.2, which is a hairline strip: technically the whole
54072
+ * graph, and worth nothing. Stopping at a legible zoom and centring
54073
+ * shows a part you can actually read, and the minimap (which such a
54074
+ * graph always has) says where that part is.
54075
+ ************************************************************/
54076
+ async function graph_fit_readable(gobj) {
54077
+ let graph = gobj.priv.graph;
54078
+ await graph.fitView();
54079
+ if (graph.getZoom() < MIN_READABLE_ZOOM) {
54080
+ await graph.zoomTo(MIN_READABLE_ZOOM);
54081
+ await graph.fitCenter();
54082
+ }
54083
+ }
54065
54084
  /************************************************************
54066
54085
  * Focus the graph on one topic: highlight (amber 'active' state)
54067
54086
  * every node of that topic and centre the viewport on them. An
@@ -55732,18 +55751,19 @@ function geometry_has_position(g) {
55732
55751
  ************************************************************/
55733
55752
  function auto_layout(gobj) {
55734
55753
  let priv = gobj.priv;
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;
55754
+ if (priv._layout_asked) return false;
55755
+ if (priv._nodes_total > 0 && priv._nodes_placed * 2 > priv._nodes_total) return false;
55756
+ if (!priv.graph) return false;
55738
55757
  let name = "dagre";
55739
55758
  (0, _yuneta_gobj_js.gobj_write_attr)(gobj, "layout", name);
55740
55759
  try {
55741
55760
  priv.graph.setLayout(_layouts[name]);
55742
55761
  } catch (e) {
55743
55762
  (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: cannot set the '${name}' layout: ${e}`);
55744
- return;
55763
+ return false;
55745
55764
  }
55746
55765
  (0, _yuneta_gobj_js.gobj_publish_event)(gobj, "EV_LAYOUT_AUTOSET", { layout: name });
55766
+ return true;
55747
55767
  }
55748
55768
  /************************************************************
55749
55769
  * Show or hide the minimap, deciding by the SIZE of the graph.
@@ -56602,12 +56622,16 @@ function ac_load_data(gobj, event, kw, src) {
56602
56622
  graph_draw(gobj).then(() => {
56603
56623
  create_links(gobj);
56604
56624
  graph_draw(gobj).then(() => {
56625
+ let auto_laid = false;
56605
56626
  try {
56606
- auto_layout(gobj);
56627
+ auto_laid = auto_layout(gobj);
56607
56628
  } catch (e) {
56608
56629
  (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: auto_layout failed: ${e}`);
56609
56630
  }
56610
56631
  graph_layout(gobj).then(() => {
56632
+ if (auto_laid) graph_fit_readable(gobj).catch((e) => {
56633
+ (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: cannot fit the graph: ${e}`);
56634
+ });
56611
56635
  if (priv.edit_mode) graph_add_plugin(gobj, "history");
56612
56636
  else graph_remove_plugin(gobj, "history");
56613
56637
  if (priv._pending_focus_topic !== null) {
@@ -54049,6 +54049,25 @@ async function graph_center(gobj) {
54049
54049
  async function graph_fitview(gobj) {
54050
54050
  await gobj.priv.graph.fitView();
54051
54051
  }
54052
+ var MIN_READABLE_ZOOM = .5;
54053
+ /************************************************************
54054
+ * Fit the graph in the viewport, but never zoom out past the point
54055
+ * where nothing on a card can be read.
54056
+ *
54057
+ * A wide fan — a schema treedb is one topic and a hundred columns —
54058
+ * fits at about 0.2, which is a hairline strip: technically the whole
54059
+ * graph, and worth nothing. Stopping at a legible zoom and centring
54060
+ * shows a part you can actually read, and the minimap (which such a
54061
+ * graph always has) says where that part is.
54062
+ ************************************************************/
54063
+ async function graph_fit_readable(gobj) {
54064
+ let graph = gobj.priv.graph;
54065
+ await graph.fitView();
54066
+ if (graph.getZoom() < MIN_READABLE_ZOOM) {
54067
+ await graph.zoomTo(MIN_READABLE_ZOOM);
54068
+ await graph.fitCenter();
54069
+ }
54070
+ }
54052
54071
  /************************************************************
54053
54072
  * Focus the graph on one topic: highlight (amber 'active' state)
54054
54073
  * every node of that topic and centre the viewport on them. An
@@ -55719,18 +55738,19 @@ function geometry_has_position(g) {
55719
55738
  ************************************************************/
55720
55739
  function auto_layout(gobj) {
55721
55740
  let priv = gobj.priv;
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;
55741
+ if (priv._layout_asked) return false;
55742
+ if (priv._nodes_total > 0 && priv._nodes_placed * 2 > priv._nodes_total) return false;
55743
+ if (!priv.graph) return false;
55725
55744
  let name = "dagre";
55726
55745
  gobj_write_attr(gobj, "layout", name);
55727
55746
  try {
55728
55747
  priv.graph.setLayout(_layouts[name]);
55729
55748
  } catch (e) {
55730
55749
  log_error(`${gobj_short_name(gobj)}: cannot set the '${name}' layout: ${e}`);
55731
- return;
55750
+ return false;
55732
55751
  }
55733
55752
  gobj_publish_event(gobj, "EV_LAYOUT_AUTOSET", { layout: name });
55753
+ return true;
55734
55754
  }
55735
55755
  /************************************************************
55736
55756
  * Show or hide the minimap, deciding by the SIZE of the graph.
@@ -56589,12 +56609,16 @@ function ac_load_data(gobj, event, kw, src) {
56589
56609
  graph_draw(gobj).then(() => {
56590
56610
  create_links(gobj);
56591
56611
  graph_draw(gobj).then(() => {
56612
+ let auto_laid = false;
56592
56613
  try {
56593
- auto_layout(gobj);
56614
+ auto_laid = auto_layout(gobj);
56594
56615
  } catch (e) {
56595
56616
  log_error(`${gobj_short_name(gobj)}: auto_layout failed: ${e}`);
56596
56617
  }
56597
56618
  graph_layout(gobj).then(() => {
56619
+ if (auto_laid) graph_fit_readable(gobj).catch((e) => {
56620
+ log_error(`${gobj_short_name(gobj)}: cannot fit the graph: ${e}`);
56621
+ });
56598
56622
  if (priv.edit_mode) graph_add_plugin(gobj, "history");
56599
56623
  else graph_remove_plugin(gobj, "history");
56600
56624
  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.7",
3
+ "version": "7.6.1",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -2104,6 +2104,32 @@ async function graph_fitview(gobj)
2104
2104
  await graph.fitView();
2105
2105
  }
2106
2106
 
2107
+ /* Below this the cards carry no readable text at all. */
2108
+ const MIN_READABLE_ZOOM = 0.5;
2109
+
2110
+ /************************************************************
2111
+ * Fit the graph in the viewport, but never zoom out past the point
2112
+ * where nothing on a card can be read.
2113
+ *
2114
+ * A wide fan — a schema treedb is one topic and a hundred columns —
2115
+ * fits at about 0.2, which is a hairline strip: technically the whole
2116
+ * graph, and worth nothing. Stopping at a legible zoom and centring
2117
+ * shows a part you can actually read, and the minimap (which such a
2118
+ * graph always has) says where that part is.
2119
+ ************************************************************/
2120
+ async function graph_fit_readable(gobj)
2121
+ {
2122
+ let priv = gobj.priv;
2123
+ let graph = priv.graph;
2124
+
2125
+ await graph.fitView();
2126
+
2127
+ if(graph.getZoom() < MIN_READABLE_ZOOM) {
2128
+ await graph.zoomTo(MIN_READABLE_ZOOM);
2129
+ await graph.fitCenter();
2130
+ }
2131
+ }
2132
+
2107
2133
  /************************************************************
2108
2134
  * Focus the graph on one topic: highlight (amber 'active' state)
2109
2135
  * every node of that topic and centre the viewport on them. An
@@ -4544,7 +4570,7 @@ function auto_layout(gobj)
4544
4570
  let priv = gobj.priv;
4545
4571
 
4546
4572
  if(priv._layout_asked) {
4547
- return; /* the user picked one for this treedb */
4573
+ return false; /* the user picked one for this treedb */
4548
4574
  }
4549
4575
  /* MOST of the nodes, not one of them.
4550
4576
  *
@@ -4557,10 +4583,10 @@ function auto_layout(gobj)
4557
4583
  * invented as readily as one a human chose, so a single stored
4558
4584
  * coordinate proves nothing. One leftover is not an arrangement. */
4559
4585
  if(priv._nodes_total > 0 && priv._nodes_placed * 2 > priv._nodes_total) {
4560
- return; /* somebody arranged it: leave it alone */
4586
+ return false; /* somebody arranged it: leave it alone */
4561
4587
  }
4562
4588
  if(!priv.graph) {
4563
- return;
4589
+ return false;
4564
4590
  }
4565
4591
 
4566
4592
  let name = "dagre";
@@ -4569,11 +4595,12 @@ function auto_layout(gobj)
4569
4595
  priv.graph.setLayout(_layouts[name]);
4570
4596
  } catch(e) {
4571
4597
  log_error(`${gobj_short_name(gobj)}: cannot set the '${name}' layout: ${e}`);
4572
- return;
4598
+ return false;
4573
4599
  }
4574
4600
  /* The toolbar's select was filled before the data arrived, so it is
4575
4601
  * still showing `manual`: tell it what the graph is actually doing. */
4576
4602
  gobj_publish_event(gobj, "EV_LAYOUT_AUTOSET", {layout: name});
4603
+ return true;
4577
4604
  }
4578
4605
 
4579
4606
  /************************************************************
@@ -5871,12 +5898,24 @@ function ac_load_data(gobj, event, kw, src)
5871
5898
  /* Before the layout runs, and only now: whether anybody has
5872
5899
  * ever placed a node of this treedb is not known until its
5873
5900
  * records and __graphs__ are in. */
5901
+ let auto_laid = false;
5874
5902
  try {
5875
- auto_layout(gobj);
5903
+ auto_laid = auto_layout(gobj);
5876
5904
  } catch(e) {
5877
5905
  log_error(`${gobj_short_name(gobj)}: auto_layout failed: ${e}`);
5878
5906
  }
5879
5907
  graph_layout(gobj).then(() => {
5908
+ /* A graph laid out by us opens WHOLE. dagre spreads a
5909
+ * 126-node treedb over some 19000px, and the camera is
5910
+ * wherever it was: without this you get eight cards in
5911
+ * the top-left corner and no reason to think there are
5912
+ * 118 more. Only when WE laid it out — a saved
5913
+ * arrangement includes where its owner was looking. */
5914
+ if(auto_laid) {
5915
+ graph_fit_readable(gobj).catch((e) => {
5916
+ log_error(`${gobj_short_name(gobj)}: cannot fit the graph: ${e}`);
5917
+ });
5918
+ }
5880
5919
  if(priv.edit_mode) {
5881
5920
  graph_add_plugin(gobj, "history");
5882
5921
  } else {