@yuneta/gobj-ui 7.23.81 → 7.23.83

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.
@@ -120,8 +120,8 @@ SDATA(data_type_t.DTP_STRING, "layout", sdata_flag_t.SDF_PERSIST, ""
120
120
  SDATA(data_type_t.DTP_LIST, "hidden_topics", sdata_flag_t.SDF_PERSIST, "[]", "Topics hidden from the graph (legend). User preference, per treedb"),
121
121
  SDATA(data_type_t.DTP_STRING, "main_topic", sdata_flag_t.SDF_PERSIST, "", "The topic the tree hangs from; empty = deduced by the graph. User preference, per treedb"),
122
122
  SDATA(data_type_t.DTP_LIST, "loose_topics", sdata_flag_t.SDF_PERSIST, "[]", "Topics whose LOOSE records (no parent) are shown. User preference, per treedb"),
123
- SDATA(data_type_t.DTP_STRING, "node_mode", sdata_flag_t.SDF_PERSIST, "expanded", "How the records are drawn: `expanded` = the cards with their ports, `compact` = coloured squares, the topology alone. User preference"),
124
- SDATA(data_type_t.DTP_BOOLEAN, "node_labels", sdata_flag_t.SDF_PERSIST, true, "A compact node says its name under its square. User preference"),
123
+ SDATA(data_type_t.DTP_STRING, "node_mode", sdata_flag_t.SDF_PERSIST, "expanded", "How the records are drawn: `expanded` = the cards with their pills and ports, `compact` = one-line pills with the name, `shape` = coloured figures, the topology alone. User preference"),
124
+ SDATA(data_type_t.DTP_BOOLEAN, "node_labels", sdata_flag_t.SDF_PERSIST, true, "A `shape` node says its name under its figure. User preference"),
125
125
 
126
126
  /*---------------- Remote Connection ----------------*/
127
127
  SDATA(data_type_t.DTP_POINTER, "gobj_remote_yuno", 0, null, "Remote Yuno to request data"),
@@ -547,28 +547,64 @@ function option_label(name)
547
547
  ************************************************************/
548
548
  function node_shape_items(gobj, wide)
549
549
  {
550
- let toggle = (cls, icon, event_name, label_key) => {
551
- return ['button', {class: `${cls} button`, type: 'button',
550
+ /* Three push buttons in one group, not a select: a view is
551
+ * picked at a glance and in one press, and the pressed one
552
+ * SAYS which view is on -- a closed list says nothing until it
553
+ * is opened. Icons, because a card, a line and a figure draw
554
+ * themselves better than three words. */
555
+ let mode_buttons = NODE_MODES.map((mode) => {
556
+ let key = NODE_MODE_LABELS[mode];
557
+ return ['button', {class: 'GRAPH_NODE_MODE_BTN button', type: 'button',
558
+ 'data-mode': mode,
552
559
  style: {height: wide, width: '2.5em'},
553
- title: t(label_key), 'data-i18n-title': label_key,
554
- 'aria-label': t(label_key), 'data-i18n-aria-label': label_key,
560
+ title: t(key), 'data-i18n-title': key,
561
+ 'aria-label': t(key), 'data-i18n-aria-label': key,
555
562
  'aria-pressed': 'false'},
556
- ['i', {style: 'font-size:1.5em; color:inherit;', class: icon}],
563
+ ['i', {style: 'font-size:1.5em; color:inherit;', class: NODE_MODE_ICONS[mode]}],
557
564
  {
558
565
  click: (evt) => {
559
566
  evt.stopPropagation();
560
- gobj_send_event(gobj, event_name, {}, gobj);
567
+ gobj_send_event(gobj, "EV_SET_NODE_MODE", {node_mode: mode}, gobj);
561
568
  }
562
569
  }
563
570
  ];
564
- };
571
+ });
565
572
  return [
566
- toggle('GRAPH_NODE_MODE', 'yi-hexagon-nodes', 'EV_TOGGLE_NODE_MODE', 'closed nodes'),
567
- toggle('GRAPH_NODE_LABELS', 'yi-font', 'EV_TOGGLE_NODE_LABELS', 'node labels'),
573
+ ['div', {class: 'GRAPH_NODE_MODE buttons has-addons',
574
+ style: 'margin:0 0 0 .5rem; flex:0 0 auto; flex-wrap:nowrap;'}, mode_buttons],
575
+ ['button', {class: 'GRAPH_NODE_LABELS button', type: 'button',
576
+ style: {height: wide, width: '2.5em'},
577
+ title: t('node labels'), 'data-i18n-title': 'node labels',
578
+ 'aria-label': t('node labels'), 'data-i18n-aria-label': 'node labels',
579
+ 'aria-pressed': 'false'},
580
+ ['i', {style: 'font-size:1.5em; color:inherit;', class: 'yi-font'}],
581
+ {
582
+ click: (evt) => {
583
+ evt.stopPropagation();
584
+ gobj_send_event(gobj, "EV_TOGGLE_NODE_LABELS", {}, gobj);
585
+ }
586
+ }
587
+ ],
568
588
  ];
569
589
  }
570
590
 
571
- /* The pressed look and `aria-pressed` of the two, from the attrs.
591
+ /* The three views of a record: the child's `node_mode`, the i18n
592
+ * key of each, and the glyph -- a card, a line, a figure. */
593
+ const NODE_MODES = ['expanded', 'compact', 'shape'];
594
+ const NODE_MODE_LABELS = {
595
+ expanded: 'full',
596
+ compact: 'compact',
597
+ shape: 'shape',
598
+ };
599
+ const NODE_MODE_ICONS = {
600
+ expanded: 'yi-square',
601
+ compact: 'yi-bars',
602
+ shape: 'yi-hexagon-nodes',
603
+ };
604
+
605
+ /* The pressed view and the labels toggle, from the attrs. The
606
+ * toggle only means something on figures, so it is disabled
607
+ * elsewhere.
572
608
  * `$root` is whatever holds the toolbar: the toolbar itself before
573
609
  * the view is mounted, the view's container after. */
574
610
  function refresh_node_shape_buttons(gobj, $root)
@@ -576,17 +612,21 @@ function refresh_node_shape_buttons(gobj, $root)
576
612
  if(!$root) {
577
613
  return;
578
614
  }
579
- let compact = (gobj_read_str_attr(gobj, "node_mode") === "compact");
615
+ let mode = gobj_read_str_attr(gobj, "node_mode");
616
+ if(!NODE_MODES.includes(mode)) {
617
+ mode = 'expanded';
618
+ }
580
619
  let labels = gobj_read_bool_attr(gobj, "node_labels");
581
- set_pressed_state($root, '.GRAPH_NODE_MODE', compact);
582
- set_pressed_state($root, '.GRAPH_NODE_LABELS', labels);
583
- let $mode = $root.querySelector('.GRAPH_NODE_MODE');
584
- if($mode) {
585
- $mode.setAttribute('aria-pressed', compact? 'true' : 'false');
620
+ for(let $btn of $root.querySelectorAll('.GRAPH_NODE_MODE_BTN')) {
621
+ let on = ($btn.getAttribute('data-mode') === mode);
622
+ $btn.classList.toggle('pressed_state', on);
623
+ $btn.setAttribute('aria-pressed', on? 'true' : 'false');
586
624
  }
625
+ set_pressed_state($root, '.GRAPH_NODE_LABELS', labels);
587
626
  let $labels = $root.querySelector('.GRAPH_NODE_LABELS');
588
627
  if($labels) {
589
628
  $labels.setAttribute('aria-pressed', labels? 'true' : 'false');
629
+ $labels.disabled = (mode !== 'shape');
590
630
  }
591
631
  }
592
632
 
@@ -654,8 +694,8 @@ function make_toolbar(gobj)
654
694
  * way back to the default depth. */
655
695
  ...yui_graph_fold_items(gobj, gobj_read_str_attr(gobj, "wide")),
656
696
 
657
- /* The shape pair: closed squares or open cards, and the name
658
- * under a square. Two STATES, so they look pressed. */
697
+ /* The view of the nodes -- full cards, one-line pills or
698
+ * figures -- and the name under a figure. */
659
699
  ...node_shape_items(gobj, gobj_read_str_attr(gobj, "wide")),
660
700
 
661
701
  /* Inspect the treedb's raw tranger json in the lazy tree viewer
@@ -2770,14 +2810,14 @@ function ac_collapse_all(gobj, event, kw, src)
2770
2810
  }
2771
2811
 
2772
2812
  /************************************************************
2773
- * The shape pair of the toolbar: the attr flips, persists,
2774
- * shows on the button, and reaches the G6 child, which owns
2775
- * the nodes.
2813
+ * The view of the nodes and the labels toggle of the toolbar:
2814
+ * the attr changes, persists, shows on the control, and reaches
2815
+ * the G6 child, which owns the nodes.
2776
2816
  ************************************************************/
2777
- function ac_toggle_node_mode(gobj, event, kw, src)
2817
+ function ac_set_node_mode(gobj, event, kw, src)
2778
2818
  {
2779
2819
  let priv = gobj.priv;
2780
- let mode = (gobj_read_str_attr(gobj, "node_mode") === "compact")? "expanded" : "compact";
2820
+ let mode = (kw && NODE_MODES.includes(kw.node_mode))? kw.node_mode : "expanded";
2781
2821
 
2782
2822
  gobj_write_str_attr(gobj, "node_mode", mode);
2783
2823
  gobj_save_persistent_attrs(gobj, "node_mode");
@@ -2955,7 +2995,7 @@ function create_gclass(gclass_name)
2955
2995
  ["EV_FIND_NODES", ac_find_nodes, null],
2956
2996
  ["EV_EXPAND_ALL", ac_expand_all, null],
2957
2997
  ["EV_COLLAPSE_ALL", ac_collapse_all, null],
2958
- ["EV_TOGGLE_NODE_MODE", ac_toggle_node_mode, null],
2998
+ ["EV_SET_NODE_MODE", ac_set_node_mode, null],
2959
2999
  ["EV_TOGGLE_NODE_LABELS", ac_toggle_node_labels, null],
2960
3000
  ["EV_LAYOUT_AUTOSET", ac_layout_autoset, null],
2961
3001
  ["EV_LEGEND_TOPIC", ac_legend_topic, null],
@@ -2998,7 +3038,7 @@ function create_gclass(gclass_name)
2998
3038
  ["EV_FIND_NODES", 0],
2999
3039
  ["EV_EXPAND_ALL", 0],
3000
3040
  ["EV_COLLAPSE_ALL", 0],
3001
- ["EV_TOGGLE_NODE_MODE", 0],
3041
+ ["EV_SET_NODE_MODE", 0],
3002
3042
  ["EV_TOGGLE_NODE_LABELS", 0],
3003
3043
  ["EV_FIND_RESULT", 0],
3004
3044
  ["EV_LAYOUT_AUTOSET", 0],