@yuneta/gobj-ui 7.23.95 → 7.23.97

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.
@@ -4424,9 +4424,12 @@ function ensure_dock_style() {
4424
4424
  * the same hue on itself -- 4.49:1 on the light chip, under the 4.5
4425
4425
  * its 12px label needs. The label takes the text colour (11:1). */
4426
4426
  .yui-dock-chip.is-active { border-color: #2563eb; color: var(--bulma-text, #2e333d); background: rgba(37,99,235,0.10); font-weight: 600; }
4427
- /* A minimised window is quieter, not unreadable: 0.65 is 4.3:1 on the
4428
- * light scheme for a 12px label. */
4429
- .yui-dock-chip.is-min { opacity: 0.7; }
4427
+ /* A minimised window is quieter, not unreadable. 0.65 was 4.3:1 for a
4428
+ * 12px label; 0.7 (7.23.95) was measured against the PAGE and is 4.10
4429
+ * against what the label actually sits on, which is the chip's own
4430
+ * white. 0.8 is 5.34 / 5.81, and an active chip at 9.45 is still
4431
+ * plainly the loud one. */
4432
+ .yui-dock-chip.is-min { opacity: 0.8; }
4430
4433
  .yui-dock-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; flex: 0 0 auto; }
4431
4434
  .yui-dock-chip.is-min .yui-dock-dot { background: var(--bulma-text-weak); }
4432
4435
  .yui-dock-icon { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; font-size: 14px; flex: 0 0 auto; }
@@ -9683,6 +9686,11 @@ function load_devices(gobj) {
9683
9686
  "text-field": "{point_count_abbreviated}",
9684
9687
  "text-font": ["Noto Sans Regular"],
9685
9688
  "text-size": 14
9689
+ },
9690
+ paint: {
9691
+ "text-color": "#ffffff",
9692
+ "text-halo-color": "rgba(0,0,0,0.35)",
9693
+ "text-halo-width": 1
9686
9694
  }
9687
9695
  });
9688
9696
  map.addLayer({
@@ -9697,12 +9705,16 @@ function load_devices(gobj) {
9697
9705
  "text-offset": [0, -2.5],
9698
9706
  "text-anchor": "top"
9699
9707
  },
9700
- paint: { "text-color": [
9701
- "case",
9702
- ["get", "connected"],
9703
- "green",
9704
- "red"
9705
- ] }
9708
+ paint: {
9709
+ "text-color": [
9710
+ "case",
9711
+ ["get", "connected"],
9712
+ "#1e7a3c",
9713
+ "#b3243a"
9714
+ ],
9715
+ "text-halo-color": "#ffffff",
9716
+ "text-halo-width": 1.4
9717
+ }
9706
9718
  });
9707
9719
  map.addLayer({
9708
9720
  id: "unclustered-point",
@@ -10016,6 +10028,66 @@ function register_c_yui_map() {
10016
10028
  * All Rights Reserved.
10017
10029
  ***********************************************************************/
10018
10030
  /***************************************************************
10031
+ * The ink of a chart, and its palette.
10032
+ *
10033
+ * uPlot is built for a white page: its axis labels are `#000`
10034
+ * and its grid `rgba(0,0,0,0.07)`, which on the dark scheme are
10035
+ * 1.16:1 and 1.04 -- an axis nobody can read and a grid that is
10036
+ * not there. And the series were CSS colour names: `blue` is
10037
+ * 2.11:1 on the dark ground, `orange` 1.97 on the light one, so
10038
+ * whichever scheme you were in, one of the lines was a rumour.
10039
+ *
10040
+ * These are given to uPlot as FUNCTIONS: it calls them when it
10041
+ * draws, so the value can never be stale -- what goes stale is
10042
+ * the canvas, and that is what EV_THEME redraws.
10043
+ *
10044
+ * The palette is six colours that clear 3:1 on BOTH grounds
10045
+ * (worst 3.39 on white, 3.71 on near-black), ordered so the
10046
+ * first two are the pair that survives colour blindness -- blue
10047
+ * and orange, never red and green as the opening pair.
10048
+ ***************************************************************/
10049
+ function axis_ink() {
10050
+ return yui_is_dark() ? "#c7cdd8" : "#2e333d";
10051
+ }
10052
+ function grid_ink() {
10053
+ return yui_is_dark() ? "rgba(199,205,216,0.16)" : "rgba(46,51,61,0.12)";
10054
+ }
10055
+ var CHART_PALETTE = [
10056
+ {
10057
+ stroke: "#2f6fd0",
10058
+ fill: "rgba(47,111,208,0.10)"
10059
+ },
10060
+ {
10061
+ stroke: "#b8620a",
10062
+ fill: "rgba(184,98,10,0.10)"
10063
+ },
10064
+ {
10065
+ stroke: "#2f8f4e",
10066
+ fill: "rgba(47,143,78,0.10)"
10067
+ },
10068
+ {
10069
+ stroke: "#8b5cf6",
10070
+ fill: "rgba(139,92,246,0.10)"
10071
+ },
10072
+ {
10073
+ stroke: "#0e9aa7",
10074
+ fill: "rgba(14,154,167,0.10)"
10075
+ },
10076
+ {
10077
+ stroke: "#d1344b",
10078
+ fill: "rgba(209,52,75,0.10)"
10079
+ }
10080
+ ];
10081
+ function themed_axes(axes) {
10082
+ return (Array.isArray(axes) ? axes : [axes || {}]).map((ax) => {
10083
+ let a = Object.assign({}, ax || {});
10084
+ if (a.stroke === void 0) a.stroke = axis_ink;
10085
+ a.grid = Object.assign({ stroke: grid_ink }, a.grid || {});
10086
+ a.ticks = Object.assign({ stroke: grid_ink }, a.ticks || {});
10087
+ return a;
10088
+ });
10089
+ }
10090
+ /***************************************************************
10019
10091
  * Constants
10020
10092
  ***************************************************************/
10021
10093
  var GCLASS_NAME$14 = "C_YUI_UPLOT";
@@ -10032,24 +10104,7 @@ var attrs_table$14 = [
10032
10104
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_JSON, "axes", 0, [{}], "Chart axes"),
10033
10105
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_JSON, "scales", 0, {}, "Chart scales"),
10034
10106
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_JSON, "data", 0, [[]], "Chart data"),
10035
- (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_JSON, "colors", 0, [
10036
- {
10037
- stroke: "red",
10038
- fill: "rgba(255,0,0,0.05)"
10039
- },
10040
- {
10041
- stroke: "green",
10042
- fill: "rgba(0,255,0,0.07)"
10043
- },
10044
- {
10045
- stroke: "blue",
10046
- fill: "rgba(0,0,255,0.05)"
10047
- },
10048
- {
10049
- stroke: "orange",
10050
- fill: "rgba(255,165,0,0.1)"
10051
- }
10052
- ], "Color settings"),
10107
+ (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_JSON, "colors", 0, CHART_PALETTE, "Series colours, in order. The default palette clears 3:1 on both schemes and opens with the colour-blind-safe pair (blue, orange)"),
10053
10108
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_POINTER, "$container", 0, null, "HTML container for the chart"),
10054
10109
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_BOOLEAN, "own_container", 0, false, "If true, container is gobj-managed"),
10055
10110
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_POINTER, "uplot", 0, null, "uPlot instance"),
@@ -10057,7 +10112,7 @@ var attrs_table$14 = [
10057
10112
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_INTEGER, "timeout_idle", 0, 5, "Idle timeout (seconds)"),
10058
10113
  (0, _yuneta_gobj_js.SDATA_END)()
10059
10114
  ];
10060
- var PRIVATE_DATA$14 = {};
10115
+ var PRIVATE_DATA$14 = { theme_observer: null };
10061
10116
  var __gclass__$14 = null;
10062
10117
  /******************************
10063
10118
  * Framework Methods
@@ -10067,6 +10122,7 @@ var __gclass__$14 = null;
10067
10122
  ***************************************************************/
10068
10123
  function mt_create$14(gobj) {
10069
10124
  build_ui$13(gobj);
10125
+ gobj.priv.theme_observer = yui_watch_theme(gobj);
10070
10126
  let subscriber = (0, _yuneta_gobj_js.gobj_read_pointer_attr)(gobj, "subscriber");
10071
10127
  if (!subscriber) subscriber = (0, _yuneta_gobj_js.gobj_parent)(gobj);
10072
10128
  (0, _yuneta_gobj_js.gobj_subscribe_event)(gobj, null, {}, subscriber);
@@ -10083,6 +10139,10 @@ function mt_stop$14(gobj) {}
10083
10139
  * Framework Method: Destroy
10084
10140
  ***************************************************************/
10085
10141
  function mt_destroy$14(gobj) {
10142
+ if (gobj.priv.theme_observer) {
10143
+ gobj.priv.theme_observer.disconnect();
10144
+ gobj.priv.theme_observer = null;
10145
+ }
10086
10146
  let uplot$1 = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "uplot");
10087
10147
  if (uplot$1) {
10088
10148
  uplot$1.destroy();
@@ -10111,7 +10171,7 @@ function build_ui$13(gobj) {
10111
10171
  width: (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "width"),
10112
10172
  height: (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "height"),
10113
10173
  series: (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "series"),
10114
- axes: (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "axes"),
10174
+ axes: themed_axes((0, _yuneta_gobj_js.gobj_read_attr)(gobj, "axes")),
10115
10175
  scales: (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "scales")
10116
10176
  };
10117
10177
  let uplot$2 = new uplot.default(uPlot_options, (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "data"), $container);
@@ -10211,29 +10271,40 @@ function ac_add_serie(gobj, event, kw, src) {
10211
10271
  return -1;
10212
10272
  }
10213
10273
  }
10214
- let color = {
10215
- stroke: "Orange",
10216
- fill: "rgb(255, 165, 0, 0.05)"
10217
- };
10218
10274
  let colors = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "colors");
10219
- if (idx < colors.length) color = colors[idx];
10275
+ if (!Array.isArray(colors) || !colors.length) colors = CHART_PALETTE;
10276
+ let color = colors[Math.max(0, idx - 1) % colors.length];
10220
10277
  (0, _yuneta_gobj_js.kw_get_str)(gobj, kw, "stroke", color.stroke, _yuneta_gobj_js.kw_flag_t.KW_CREATE);
10221
10278
  (0, _yuneta_gobj_js.kw_get_str)(gobj, kw, "fill", color.fill, _yuneta_gobj_js.kw_flag_t.KW_CREATE);
10222
10279
  uplot$4.addSeries(kw);
10223
10280
  return 0;
10224
10281
  }
10225
10282
  /******************************************************
10283
+ * The scheme changed: the ink functions answer the new
10284
+ * one already, the canvas is what has to be painted again.
10285
+ ******************************************************/
10286
+ function ac_theme$4(gobj, event, kw, src) {
10287
+ let uplot$5 = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "uplot");
10288
+ if (!uplot$5) return 0;
10289
+ try {
10290
+ uplot$5.redraw();
10291
+ } catch (e) {
10292
+ (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: cannot redraw the chart: ${e}`);
10293
+ }
10294
+ return 0;
10295
+ }
10296
+ /******************************************************
10226
10297
  *
10227
10298
  ******************************************************/
10228
10299
  function ac_del_serie(gobj, event, kw, src) {
10229
- let uplot$5 = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "uplot");
10230
- for (let idx = 1; idx < uplot$5.series.length; idx++) {
10231
- let serie = uplot$5.series[idx];
10300
+ let uplot$6 = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "uplot");
10301
+ for (let idx = 1; idx < uplot$6.series.length; idx++) {
10302
+ let serie = uplot$6.series[idx];
10232
10303
  if (serie.id && serie.id === kw.id) {
10233
- uplot$5.delSeries(idx);
10234
- let data = uplot$5.data.splice(idx, 1);
10304
+ uplot$6.delSeries(idx);
10305
+ let data = uplot$6.data.splice(idx, 1);
10235
10306
  if (data.length === 1) data = [[]];
10236
- uplot$5.setData(data);
10307
+ uplot$6.setData(data);
10237
10308
  return 0;
10238
10309
  }
10239
10310
  }
@@ -10243,9 +10314,9 @@ function ac_del_serie(gobj, event, kw, src) {
10243
10314
  *
10244
10315
  ******************************************************/
10245
10316
  function ac_clear(gobj, event, kw, src) {
10246
- let uplot$6 = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "uplot");
10247
- uplot$6.setData([[]]);
10248
- for (let idx = uplot$6.series.length - 1; idx > 0; idx--) uplot$6.delSeries(idx);
10317
+ let uplot$7 = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "uplot");
10318
+ uplot$7.setData([[]]);
10319
+ for (let idx = uplot$7.series.length - 1; idx > 0; idx--) uplot$7.delSeries(idx);
10249
10320
  return 0;
10250
10321
  }
10251
10322
  /***************************
@@ -10269,7 +10340,8 @@ function create_gclass$14(gclass_name) {
10269
10340
  ["EV_LOAD_DATA", 0],
10270
10341
  ["EV_ADD_SERIE", 0],
10271
10342
  ["EV_DEL_SERIE", 0],
10272
- ["EV_CLEAR", 0]
10343
+ ["EV_CLEAR", 0],
10344
+ ["EV_THEME", 0]
10273
10345
  ], [["ST_IDLE", [
10274
10346
  [
10275
10347
  "EV_LOAD_DATA",
@@ -10290,6 +10362,11 @@ function create_gclass$14(gclass_name) {
10290
10362
  "EV_CLEAR",
10291
10363
  ac_clear,
10292
10364
  null
10365
+ ],
10366
+ [
10367
+ "EV_THEME",
10368
+ ac_theme$4,
10369
+ null
10293
10370
  ]
10294
10371
  ]]], gmt$14, 0, attrs_table$14, PRIVATE_DATA$14, 0, 0, 0, 0);
10295
10372
  if (!__gclass__$14) return -1;
@@ -4419,9 +4419,12 @@ function ensure_dock_style() {
4419
4419
  * the same hue on itself -- 4.49:1 on the light chip, under the 4.5
4420
4420
  * its 12px label needs. The label takes the text colour (11:1). */
4421
4421
  .yui-dock-chip.is-active { border-color: #2563eb; color: var(--bulma-text, #2e333d); background: rgba(37,99,235,0.10); font-weight: 600; }
4422
- /* A minimised window is quieter, not unreadable: 0.65 is 4.3:1 on the
4423
- * light scheme for a 12px label. */
4424
- .yui-dock-chip.is-min { opacity: 0.7; }
4422
+ /* A minimised window is quieter, not unreadable. 0.65 was 4.3:1 for a
4423
+ * 12px label; 0.7 (7.23.95) was measured against the PAGE and is 4.10
4424
+ * against what the label actually sits on, which is the chip's own
4425
+ * white. 0.8 is 5.34 / 5.81, and an active chip at 9.45 is still
4426
+ * plainly the loud one. */
4427
+ .yui-dock-chip.is-min { opacity: 0.8; }
4425
4428
  .yui-dock-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; flex: 0 0 auto; }
4426
4429
  .yui-dock-chip.is-min .yui-dock-dot { background: var(--bulma-text-weak); }
4427
4430
  .yui-dock-icon { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; font-size: 14px; flex: 0 0 auto; }
@@ -9678,6 +9681,11 @@ function load_devices(gobj) {
9678
9681
  "text-field": "{point_count_abbreviated}",
9679
9682
  "text-font": ["Noto Sans Regular"],
9680
9683
  "text-size": 14
9684
+ },
9685
+ paint: {
9686
+ "text-color": "#ffffff",
9687
+ "text-halo-color": "rgba(0,0,0,0.35)",
9688
+ "text-halo-width": 1
9681
9689
  }
9682
9690
  });
9683
9691
  map.addLayer({
@@ -9692,12 +9700,16 @@ function load_devices(gobj) {
9692
9700
  "text-offset": [0, -2.5],
9693
9701
  "text-anchor": "top"
9694
9702
  },
9695
- paint: { "text-color": [
9696
- "case",
9697
- ["get", "connected"],
9698
- "green",
9699
- "red"
9700
- ] }
9703
+ paint: {
9704
+ "text-color": [
9705
+ "case",
9706
+ ["get", "connected"],
9707
+ "#1e7a3c",
9708
+ "#b3243a"
9709
+ ],
9710
+ "text-halo-color": "#ffffff",
9711
+ "text-halo-width": 1.4
9712
+ }
9701
9713
  });
9702
9714
  map.addLayer({
9703
9715
  id: "unclustered-point",
@@ -10011,6 +10023,66 @@ function register_c_yui_map() {
10011
10023
  * All Rights Reserved.
10012
10024
  ***********************************************************************/
10013
10025
  /***************************************************************
10026
+ * The ink of a chart, and its palette.
10027
+ *
10028
+ * uPlot is built for a white page: its axis labels are `#000`
10029
+ * and its grid `rgba(0,0,0,0.07)`, which on the dark scheme are
10030
+ * 1.16:1 and 1.04 -- an axis nobody can read and a grid that is
10031
+ * not there. And the series were CSS colour names: `blue` is
10032
+ * 2.11:1 on the dark ground, `orange` 1.97 on the light one, so
10033
+ * whichever scheme you were in, one of the lines was a rumour.
10034
+ *
10035
+ * These are given to uPlot as FUNCTIONS: it calls them when it
10036
+ * draws, so the value can never be stale -- what goes stale is
10037
+ * the canvas, and that is what EV_THEME redraws.
10038
+ *
10039
+ * The palette is six colours that clear 3:1 on BOTH grounds
10040
+ * (worst 3.39 on white, 3.71 on near-black), ordered so the
10041
+ * first two are the pair that survives colour blindness -- blue
10042
+ * and orange, never red and green as the opening pair.
10043
+ ***************************************************************/
10044
+ function axis_ink() {
10045
+ return yui_is_dark() ? "#c7cdd8" : "#2e333d";
10046
+ }
10047
+ function grid_ink() {
10048
+ return yui_is_dark() ? "rgba(199,205,216,0.16)" : "rgba(46,51,61,0.12)";
10049
+ }
10050
+ var CHART_PALETTE = [
10051
+ {
10052
+ stroke: "#2f6fd0",
10053
+ fill: "rgba(47,111,208,0.10)"
10054
+ },
10055
+ {
10056
+ stroke: "#b8620a",
10057
+ fill: "rgba(184,98,10,0.10)"
10058
+ },
10059
+ {
10060
+ stroke: "#2f8f4e",
10061
+ fill: "rgba(47,143,78,0.10)"
10062
+ },
10063
+ {
10064
+ stroke: "#8b5cf6",
10065
+ fill: "rgba(139,92,246,0.10)"
10066
+ },
10067
+ {
10068
+ stroke: "#0e9aa7",
10069
+ fill: "rgba(14,154,167,0.10)"
10070
+ },
10071
+ {
10072
+ stroke: "#d1344b",
10073
+ fill: "rgba(209,52,75,0.10)"
10074
+ }
10075
+ ];
10076
+ function themed_axes(axes) {
10077
+ return (Array.isArray(axes) ? axes : [axes || {}]).map((ax) => {
10078
+ let a = Object.assign({}, ax || {});
10079
+ if (a.stroke === void 0) a.stroke = axis_ink;
10080
+ a.grid = Object.assign({ stroke: grid_ink }, a.grid || {});
10081
+ a.ticks = Object.assign({ stroke: grid_ink }, a.ticks || {});
10082
+ return a;
10083
+ });
10084
+ }
10085
+ /***************************************************************
10014
10086
  * Constants
10015
10087
  ***************************************************************/
10016
10088
  var GCLASS_NAME$14 = "C_YUI_UPLOT";
@@ -10027,24 +10099,7 @@ var attrs_table$14 = [
10027
10099
  SDATA(data_type_t.DTP_JSON, "axes", 0, [{}], "Chart axes"),
10028
10100
  SDATA(data_type_t.DTP_JSON, "scales", 0, {}, "Chart scales"),
10029
10101
  SDATA(data_type_t.DTP_JSON, "data", 0, [[]], "Chart data"),
10030
- SDATA(data_type_t.DTP_JSON, "colors", 0, [
10031
- {
10032
- stroke: "red",
10033
- fill: "rgba(255,0,0,0.05)"
10034
- },
10035
- {
10036
- stroke: "green",
10037
- fill: "rgba(0,255,0,0.07)"
10038
- },
10039
- {
10040
- stroke: "blue",
10041
- fill: "rgba(0,0,255,0.05)"
10042
- },
10043
- {
10044
- stroke: "orange",
10045
- fill: "rgba(255,165,0,0.1)"
10046
- }
10047
- ], "Color settings"),
10102
+ SDATA(data_type_t.DTP_JSON, "colors", 0, CHART_PALETTE, "Series colours, in order. The default palette clears 3:1 on both schemes and opens with the colour-blind-safe pair (blue, orange)"),
10048
10103
  SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "HTML container for the chart"),
10049
10104
  SDATA(data_type_t.DTP_BOOLEAN, "own_container", 0, false, "If true, container is gobj-managed"),
10050
10105
  SDATA(data_type_t.DTP_POINTER, "uplot", 0, null, "uPlot instance"),
@@ -10052,7 +10107,7 @@ var attrs_table$14 = [
10052
10107
  SDATA(data_type_t.DTP_INTEGER, "timeout_idle", 0, 5, "Idle timeout (seconds)"),
10053
10108
  SDATA_END()
10054
10109
  ];
10055
- var PRIVATE_DATA$14 = {};
10110
+ var PRIVATE_DATA$14 = { theme_observer: null };
10056
10111
  var __gclass__$14 = null;
10057
10112
  /******************************
10058
10113
  * Framework Methods
@@ -10062,6 +10117,7 @@ var __gclass__$14 = null;
10062
10117
  ***************************************************************/
10063
10118
  function mt_create$14(gobj) {
10064
10119
  build_ui$13(gobj);
10120
+ gobj.priv.theme_observer = yui_watch_theme(gobj);
10065
10121
  let subscriber = gobj_read_pointer_attr(gobj, "subscriber");
10066
10122
  if (!subscriber) subscriber = gobj_parent(gobj);
10067
10123
  gobj_subscribe_event(gobj, null, {}, subscriber);
@@ -10078,6 +10134,10 @@ function mt_stop$14(gobj) {}
10078
10134
  * Framework Method: Destroy
10079
10135
  ***************************************************************/
10080
10136
  function mt_destroy$14(gobj) {
10137
+ if (gobj.priv.theme_observer) {
10138
+ gobj.priv.theme_observer.disconnect();
10139
+ gobj.priv.theme_observer = null;
10140
+ }
10081
10141
  let uplot = gobj_read_attr(gobj, "uplot");
10082
10142
  if (uplot) {
10083
10143
  uplot.destroy();
@@ -10106,7 +10166,7 @@ function build_ui$13(gobj) {
10106
10166
  width: gobj_read_attr(gobj, "width"),
10107
10167
  height: gobj_read_attr(gobj, "height"),
10108
10168
  series: gobj_read_attr(gobj, "series"),
10109
- axes: gobj_read_attr(gobj, "axes"),
10169
+ axes: themed_axes(gobj_read_attr(gobj, "axes")),
10110
10170
  scales: gobj_read_attr(gobj, "scales")
10111
10171
  };
10112
10172
  let uplot = new uPlot(uPlot_options, gobj_read_attr(gobj, "data"), $container);
@@ -10206,18 +10266,29 @@ function ac_add_serie(gobj, event, kw, src) {
10206
10266
  return -1;
10207
10267
  }
10208
10268
  }
10209
- let color = {
10210
- stroke: "Orange",
10211
- fill: "rgb(255, 165, 0, 0.05)"
10212
- };
10213
10269
  let colors = gobj_read_attr(gobj, "colors");
10214
- if (idx < colors.length) color = colors[idx];
10270
+ if (!Array.isArray(colors) || !colors.length) colors = CHART_PALETTE;
10271
+ let color = colors[Math.max(0, idx - 1) % colors.length];
10215
10272
  kw_get_str(gobj, kw, "stroke", color.stroke, kw_flag_t.KW_CREATE);
10216
10273
  kw_get_str(gobj, kw, "fill", color.fill, kw_flag_t.KW_CREATE);
10217
10274
  uplot.addSeries(kw);
10218
10275
  return 0;
10219
10276
  }
10220
10277
  /******************************************************
10278
+ * The scheme changed: the ink functions answer the new
10279
+ * one already, the canvas is what has to be painted again.
10280
+ ******************************************************/
10281
+ function ac_theme$4(gobj, event, kw, src) {
10282
+ let uplot = gobj_read_attr(gobj, "uplot");
10283
+ if (!uplot) return 0;
10284
+ try {
10285
+ uplot.redraw();
10286
+ } catch (e) {
10287
+ log_error(`${gobj_short_name(gobj)}: cannot redraw the chart: ${e}`);
10288
+ }
10289
+ return 0;
10290
+ }
10291
+ /******************************************************
10221
10292
  *
10222
10293
  ******************************************************/
10223
10294
  function ac_del_serie(gobj, event, kw, src) {
@@ -10264,7 +10335,8 @@ function create_gclass$14(gclass_name) {
10264
10335
  ["EV_LOAD_DATA", 0],
10265
10336
  ["EV_ADD_SERIE", 0],
10266
10337
  ["EV_DEL_SERIE", 0],
10267
- ["EV_CLEAR", 0]
10338
+ ["EV_CLEAR", 0],
10339
+ ["EV_THEME", 0]
10268
10340
  ], [["ST_IDLE", [
10269
10341
  [
10270
10342
  "EV_LOAD_DATA",
@@ -10285,6 +10357,11 @@ function create_gclass$14(gclass_name) {
10285
10357
  "EV_CLEAR",
10286
10358
  ac_clear,
10287
10359
  null
10360
+ ],
10361
+ [
10362
+ "EV_THEME",
10363
+ ac_theme$4,
10364
+ null
10288
10365
  ]
10289
10366
  ]]], gmt$14, 0, attrs_table$14, PRIVATE_DATA$14, 0, 0, 0, 0);
10290
10367
  if (!__gclass__$14) return -1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.23.95",
3
+ "version": "7.23.97",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
package/src/c_yui_map.js CHANGED
@@ -442,6 +442,16 @@ function load_devices(gobj)
442
442
  'text-field': '{point_count_abbreviated}',
443
443
  'text-font': ['Noto Sans Regular'],
444
444
  'text-size': 14
445
+ },
446
+ /* It had no paint at all, which is maplibre's black -- on the
447
+ * red circle of a cluster that is 5.25:1 and on the green one
448
+ * 4.09, both of them a number read at a glance. White with a
449
+ * dark halo is 5.14 and 4.0 with the halo behind it, and it is
450
+ * the same ink whatever colour the cluster takes. */
451
+ paint: {
452
+ 'text-color': '#ffffff',
453
+ 'text-halo-color': 'rgba(0,0,0,0.35)',
454
+ 'text-halo-width': 1
445
455
  }
446
456
  });
447
457
 
@@ -459,11 +469,21 @@ function load_devices(gobj)
459
469
  'text-anchor': 'top'
460
470
  },
461
471
  paint: {
472
+ /* A label on a MAP is not text on a page: what is behind it
473
+ * is a tile, and a tile is any colour there is. `green` and
474
+ * `red` measured 4.48 and 3.48 on the beige of a typical
475
+ * street tile -- and over water, forest or an aerial layer
476
+ * the number means nothing at all. The colours are the
477
+ * stronger pair (4.69 / 5.66 on that beige), and the HALO
478
+ * is what actually carries them: it is drawn around every
479
+ * glyph, so the label reads on whatever the tile is. */
462
480
  'text-color': [
463
481
  'case',
464
- ['get', 'connected'], 'green',
465
- 'red'
466
- ]
482
+ ['get', 'connected'], '#1e7a3c',
483
+ '#b3243a'
484
+ ],
485
+ 'text-halo-color': '#ffffff',
486
+ 'text-halo-width': 1.4
467
487
  }
468
488
  });
469
489
 
@@ -32,6 +32,62 @@ import {
32
32
  import uPlot from "uplot";
33
33
  import "uplot/dist/uPlot.min.css";
34
34
 
35
+ import {yui_is_dark, yui_watch_theme} from "./yui_theme.js";
36
+
37
+
38
+ /***************************************************************
39
+ * The ink of a chart, and its palette.
40
+ *
41
+ * uPlot is built for a white page: its axis labels are `#000`
42
+ * and its grid `rgba(0,0,0,0.07)`, which on the dark scheme are
43
+ * 1.16:1 and 1.04 -- an axis nobody can read and a grid that is
44
+ * not there. And the series were CSS colour names: `blue` is
45
+ * 2.11:1 on the dark ground, `orange` 1.97 on the light one, so
46
+ * whichever scheme you were in, one of the lines was a rumour.
47
+ *
48
+ * These are given to uPlot as FUNCTIONS: it calls them when it
49
+ * draws, so the value can never be stale -- what goes stale is
50
+ * the canvas, and that is what EV_THEME redraws.
51
+ *
52
+ * The palette is six colours that clear 3:1 on BOTH grounds
53
+ * (worst 3.39 on white, 3.71 on near-black), ordered so the
54
+ * first two are the pair that survives colour blindness -- blue
55
+ * and orange, never red and green as the opening pair.
56
+ ***************************************************************/
57
+ function axis_ink()
58
+ {
59
+ return yui_is_dark()? "#c7cdd8" : "#2e333d";
60
+ }
61
+
62
+ function grid_ink()
63
+ {
64
+ return yui_is_dark()? "rgba(199,205,216,0.16)" : "rgba(46,51,61,0.12)";
65
+ }
66
+
67
+ const CHART_PALETTE = [
68
+ {stroke: "#2f6fd0", fill: "rgba(47,111,208,0.10)"}, /* 4.88 / 3.71 */
69
+ {stroke: "#b8620a", fill: "rgba(184,98,10,0.10)"}, /* 4.38 / 4.13 */
70
+ {stroke: "#2f8f4e", fill: "rgba(47,143,78,0.10)"}, /* 4.07 / 4.45 */
71
+ {stroke: "#8b5cf6", fill: "rgba(139,92,246,0.10)"}, /* 4.23 / 4.28 */
72
+ {stroke: "#0e9aa7", fill: "rgba(14,154,167,0.10)"}, /* 3.39 / 5.35 */
73
+ {stroke: "#d1344b", fill: "rgba(209,52,75,0.10)"}, /* 4.88 / 3.71 */
74
+ ];
75
+
76
+ /* The axes the host asked for, with the ink it did not ask about. */
77
+ function themed_axes(axes)
78
+ {
79
+ let list = Array.isArray(axes)? axes : [axes || {}];
80
+ return list.map((ax) => {
81
+ let a = Object.assign({}, ax || {});
82
+ if(a.stroke === undefined) {
83
+ a.stroke = axis_ink;
84
+ }
85
+ a.grid = Object.assign({stroke: grid_ink}, a.grid || {});
86
+ a.ticks = Object.assign({stroke: grid_ink}, a.ticks || {});
87
+ return a;
88
+ });
89
+ }
90
+
35
91
  /***************************************************************
36
92
  * Constants
37
93
  ***************************************************************/
@@ -50,12 +106,8 @@ SDATA(data_type_t.DTP_JSON, "series", 0, [{}], "Data series"),
50
106
  SDATA(data_type_t.DTP_JSON, "axes", 0, [{}], "Chart axes"),
51
107
  SDATA(data_type_t.DTP_JSON, "scales", 0, {}, "Chart scales"),
52
108
  SDATA(data_type_t.DTP_JSON, "data", 0, [[]], "Chart data"),
53
- SDATA(data_type_t.DTP_JSON, "colors", 0, [
54
- {stroke:"red", fill: "rgba(255,0,0,0.05)"},
55
- {stroke:"green", fill: "rgba(0,255,0,0.07)"},
56
- {stroke:"blue", fill: "rgba(0,0,255,0.05)"},
57
- {stroke:"orange", fill: "rgba(255,165,0,0.1)"},
58
- ], "Color settings"),
109
+ SDATA(data_type_t.DTP_JSON, "colors", 0, CHART_PALETTE,
110
+ "Series colours, in order. The default palette clears 3:1 on both schemes and opens with the colour-blind-safe pair (blue, orange)"),
59
111
  SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "HTML container for the chart"),
60
112
  SDATA(data_type_t.DTP_BOOLEAN, "own_container", 0, false, "If true, container is gobj-managed"),
61
113
  SDATA(data_type_t.DTP_POINTER, "uplot", 0, null, "uPlot instance"),
@@ -64,7 +116,9 @@ SDATA(data_type_t.DTP_INTEGER, "timeout_idle", 0, 5, "Idle timeout (s
64
116
  SDATA_END()
65
117
  ];
66
118
 
67
- let PRIVATE_DATA = {};
119
+ let PRIVATE_DATA = {
120
+ theme_observer: null, /* the DOM's data-theme, as an EV_THEME */
121
+ };
68
122
 
69
123
  let __gclass__ = null;
70
124
 
@@ -85,6 +139,11 @@ function mt_create(gobj)
85
139
  {
86
140
  build_ui(gobj);
87
141
 
142
+ /* A canvas does not restyle itself: the ink is read when uPlot
143
+ * DRAWS (see axis_ink), so a theme change only has to reach the
144
+ * machine and ask for a redraw. Same wiring as the graphs. */
145
+ gobj.priv.theme_observer = yui_watch_theme(gobj);
146
+
88
147
  /*
89
148
  * CHILD subscription model
90
149
  */
@@ -114,6 +173,10 @@ function mt_stop(gobj)
114
173
  ***************************************************************/
115
174
  function mt_destroy(gobj)
116
175
  {
176
+ if(gobj.priv.theme_observer) {
177
+ gobj.priv.theme_observer.disconnect();
178
+ gobj.priv.theme_observer = null;
179
+ }
117
180
  let uplot = gobj_read_attr(gobj, "uplot");
118
181
  if(uplot) {
119
182
  uplot.destroy();
@@ -159,7 +222,7 @@ function build_ui(gobj)
159
222
  width: gobj_read_attr(gobj, "width"),
160
223
  height: gobj_read_attr(gobj, "height"),
161
224
  series: gobj_read_attr(gobj, "series"),
162
- axes: gobj_read_attr(gobj, "axes"),
225
+ axes: themed_axes(gobj_read_attr(gobj, "axes")),
163
226
  scales: gobj_read_attr(gobj, "scales"),
164
227
  };
165
228
  let uplot = new uPlot(
@@ -381,11 +444,19 @@ function ac_add_serie(gobj, event, kw, src)
381
444
  return -1;
382
445
  }
383
446
  }
384
- let color = {stroke: "Orange", fill: "rgb(255, 165, 0, 0.05)"};
385
447
  let colors = gobj_read_attr(gobj, "colors");
386
- if(idx<colors.length) {
387
- color = colors[idx];
448
+ if(!Array.isArray(colors) || !colors.length) {
449
+ colors = CHART_PALETTE;
388
450
  }
451
+ /* `idx` counts uPlot's series, and series[0] is the X AXIS -- so
452
+ * the first line drawn was taking colours[1] and the palette's
453
+ * opener, the blue of the colour-blind-safe pair, was never used
454
+ * by anybody. The data series are counted from zero here.
455
+ *
456
+ * And it wraps around instead of falling back to one fixed
457
+ * colour: the old fallback was `Orange`, 1.97:1 on a white page,
458
+ * and it was what every series past the fourth got. */
459
+ let color = colors[Math.max(0, idx - 1) % colors.length];
389
460
  kw_get_str(gobj, kw, "stroke", color.stroke, kw_flag_t.KW_CREATE);
390
461
  kw_get_str(gobj, kw, "fill", color.fill, kw_flag_t.KW_CREATE);
391
462
  //kw["paths"] = beziercurve_path; //rectangle_path;
@@ -393,6 +464,24 @@ function ac_add_serie(gobj, event, kw, src)
393
464
  return 0;
394
465
  }
395
466
 
467
+ /******************************************************
468
+ * The scheme changed: the ink functions answer the new
469
+ * one already, the canvas is what has to be painted again.
470
+ ******************************************************/
471
+ function ac_theme(gobj, event, kw, src)
472
+ {
473
+ let uplot = gobj_read_attr(gobj, "uplot");
474
+ if(!uplot) {
475
+ return 0;
476
+ }
477
+ try {
478
+ uplot.redraw();
479
+ } catch(e) {
480
+ log_error(`${gobj_short_name(gobj)}: cannot redraw the chart: ${e}`);
481
+ }
482
+ return 0;
483
+ }
484
+
396
485
  /******************************************************
397
486
  *
398
487
  ******************************************************/
@@ -466,7 +555,8 @@ function create_gclass(gclass_name)
466
555
  ["EV_LOAD_DATA", ac_load_data, null],
467
556
  ["EV_ADD_SERIE", ac_add_serie, null],
468
557
  ["EV_DEL_SERIE", ac_del_serie, null],
469
- ["EV_CLEAR", ac_clear, null]
558
+ ["EV_CLEAR", ac_clear, null],
559
+ ["EV_THEME", ac_theme, null]
470
560
  ]]
471
561
  ];
472
562
 
@@ -477,7 +567,8 @@ function create_gclass(gclass_name)
477
567
  ["EV_LOAD_DATA", 0],
478
568
  ["EV_ADD_SERIE", 0],
479
569
  ["EV_DEL_SERIE", 0],
480
- ["EV_CLEAR", 0]
570
+ ["EV_CLEAR", 0],
571
+ ["EV_THEME", 0]
481
572
  ];
482
573
 
483
574
  __gclass__ = gclass_create(
@@ -201,9 +201,12 @@ function ensure_dock_style()
201
201
  * the same hue on itself -- 4.49:1 on the light chip, under the 4.5
202
202
  * its 12px label needs. The label takes the text colour (11:1). */
203
203
  .yui-dock-chip.is-active { border-color: #2563eb; color: var(--bulma-text, #2e333d); background: rgba(37,99,235,0.10); font-weight: 600; }
204
- /* A minimised window is quieter, not unreadable: 0.65 is 4.3:1 on the
205
- * light scheme for a 12px label. */
206
- .yui-dock-chip.is-min { opacity: 0.7; }
204
+ /* A minimised window is quieter, not unreadable. 0.65 was 4.3:1 for a
205
+ * 12px label; 0.7 (7.23.95) was measured against the PAGE and is 4.10
206
+ * against what the label actually sits on, which is the chip's own
207
+ * white. 0.8 is 5.34 / 5.81, and an active chip at 9.45 is still
208
+ * plainly the loud one. */
209
+ .yui-dock-chip.is-min { opacity: 0.8; }
207
210
  .yui-dock-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; flex: 0 0 auto; }
208
211
  .yui-dock-chip.is-min .yui-dock-dot { background: var(--bulma-text-weak); }
209
212
  .yui-dock-icon { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; font-size: 14px; flex: 0 0 auto; }