@yuneta/gobj-ui 7.23.96 → 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.
@@ -9686,6 +9686,11 @@ function load_devices(gobj) {
9686
9686
  "text-field": "{point_count_abbreviated}",
9687
9687
  "text-font": ["Noto Sans Regular"],
9688
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
9689
9694
  }
9690
9695
  });
9691
9696
  map.addLayer({
@@ -9700,12 +9705,16 @@ function load_devices(gobj) {
9700
9705
  "text-offset": [0, -2.5],
9701
9706
  "text-anchor": "top"
9702
9707
  },
9703
- paint: { "text-color": [
9704
- "case",
9705
- ["get", "connected"],
9706
- "green",
9707
- "red"
9708
- ] }
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
+ }
9709
9718
  });
9710
9719
  map.addLayer({
9711
9720
  id: "unclustered-point",
@@ -10019,6 +10028,66 @@ function register_c_yui_map() {
10019
10028
  * All Rights Reserved.
10020
10029
  ***********************************************************************/
10021
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
+ /***************************************************************
10022
10091
  * Constants
10023
10092
  ***************************************************************/
10024
10093
  var GCLASS_NAME$14 = "C_YUI_UPLOT";
@@ -10035,24 +10104,7 @@ var attrs_table$14 = [
10035
10104
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_JSON, "axes", 0, [{}], "Chart axes"),
10036
10105
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_JSON, "scales", 0, {}, "Chart scales"),
10037
10106
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_JSON, "data", 0, [[]], "Chart data"),
10038
- (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_JSON, "colors", 0, [
10039
- {
10040
- stroke: "red",
10041
- fill: "rgba(255,0,0,0.05)"
10042
- },
10043
- {
10044
- stroke: "green",
10045
- fill: "rgba(0,255,0,0.07)"
10046
- },
10047
- {
10048
- stroke: "blue",
10049
- fill: "rgba(0,0,255,0.05)"
10050
- },
10051
- {
10052
- stroke: "orange",
10053
- fill: "rgba(255,165,0,0.1)"
10054
- }
10055
- ], "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)"),
10056
10108
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_POINTER, "$container", 0, null, "HTML container for the chart"),
10057
10109
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_BOOLEAN, "own_container", 0, false, "If true, container is gobj-managed"),
10058
10110
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_POINTER, "uplot", 0, null, "uPlot instance"),
@@ -10060,7 +10112,7 @@ var attrs_table$14 = [
10060
10112
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_INTEGER, "timeout_idle", 0, 5, "Idle timeout (seconds)"),
10061
10113
  (0, _yuneta_gobj_js.SDATA_END)()
10062
10114
  ];
10063
- var PRIVATE_DATA$14 = {};
10115
+ var PRIVATE_DATA$14 = { theme_observer: null };
10064
10116
  var __gclass__$14 = null;
10065
10117
  /******************************
10066
10118
  * Framework Methods
@@ -10070,6 +10122,7 @@ var __gclass__$14 = null;
10070
10122
  ***************************************************************/
10071
10123
  function mt_create$14(gobj) {
10072
10124
  build_ui$13(gobj);
10125
+ gobj.priv.theme_observer = yui_watch_theme(gobj);
10073
10126
  let subscriber = (0, _yuneta_gobj_js.gobj_read_pointer_attr)(gobj, "subscriber");
10074
10127
  if (!subscriber) subscriber = (0, _yuneta_gobj_js.gobj_parent)(gobj);
10075
10128
  (0, _yuneta_gobj_js.gobj_subscribe_event)(gobj, null, {}, subscriber);
@@ -10086,6 +10139,10 @@ function mt_stop$14(gobj) {}
10086
10139
  * Framework Method: Destroy
10087
10140
  ***************************************************************/
10088
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
+ }
10089
10146
  let uplot$1 = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "uplot");
10090
10147
  if (uplot$1) {
10091
10148
  uplot$1.destroy();
@@ -10114,7 +10171,7 @@ function build_ui$13(gobj) {
10114
10171
  width: (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "width"),
10115
10172
  height: (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "height"),
10116
10173
  series: (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "series"),
10117
- axes: (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "axes"),
10174
+ axes: themed_axes((0, _yuneta_gobj_js.gobj_read_attr)(gobj, "axes")),
10118
10175
  scales: (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "scales")
10119
10176
  };
10120
10177
  let uplot$2 = new uplot.default(uPlot_options, (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "data"), $container);
@@ -10214,29 +10271,40 @@ function ac_add_serie(gobj, event, kw, src) {
10214
10271
  return -1;
10215
10272
  }
10216
10273
  }
10217
- let color = {
10218
- stroke: "Orange",
10219
- fill: "rgb(255, 165, 0, 0.05)"
10220
- };
10221
10274
  let colors = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "colors");
10222
- 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];
10223
10277
  (0, _yuneta_gobj_js.kw_get_str)(gobj, kw, "stroke", color.stroke, _yuneta_gobj_js.kw_flag_t.KW_CREATE);
10224
10278
  (0, _yuneta_gobj_js.kw_get_str)(gobj, kw, "fill", color.fill, _yuneta_gobj_js.kw_flag_t.KW_CREATE);
10225
10279
  uplot$4.addSeries(kw);
10226
10280
  return 0;
10227
10281
  }
10228
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
+ /******************************************************
10229
10297
  *
10230
10298
  ******************************************************/
10231
10299
  function ac_del_serie(gobj, event, kw, src) {
10232
- let uplot$5 = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "uplot");
10233
- for (let idx = 1; idx < uplot$5.series.length; idx++) {
10234
- 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];
10235
10303
  if (serie.id && serie.id === kw.id) {
10236
- uplot$5.delSeries(idx);
10237
- let data = uplot$5.data.splice(idx, 1);
10304
+ uplot$6.delSeries(idx);
10305
+ let data = uplot$6.data.splice(idx, 1);
10238
10306
  if (data.length === 1) data = [[]];
10239
- uplot$5.setData(data);
10307
+ uplot$6.setData(data);
10240
10308
  return 0;
10241
10309
  }
10242
10310
  }
@@ -10246,9 +10314,9 @@ function ac_del_serie(gobj, event, kw, src) {
10246
10314
  *
10247
10315
  ******************************************************/
10248
10316
  function ac_clear(gobj, event, kw, src) {
10249
- let uplot$6 = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "uplot");
10250
- uplot$6.setData([[]]);
10251
- 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);
10252
10320
  return 0;
10253
10321
  }
10254
10322
  /***************************
@@ -10272,7 +10340,8 @@ function create_gclass$14(gclass_name) {
10272
10340
  ["EV_LOAD_DATA", 0],
10273
10341
  ["EV_ADD_SERIE", 0],
10274
10342
  ["EV_DEL_SERIE", 0],
10275
- ["EV_CLEAR", 0]
10343
+ ["EV_CLEAR", 0],
10344
+ ["EV_THEME", 0]
10276
10345
  ], [["ST_IDLE", [
10277
10346
  [
10278
10347
  "EV_LOAD_DATA",
@@ -10293,6 +10362,11 @@ function create_gclass$14(gclass_name) {
10293
10362
  "EV_CLEAR",
10294
10363
  ac_clear,
10295
10364
  null
10365
+ ],
10366
+ [
10367
+ "EV_THEME",
10368
+ ac_theme$4,
10369
+ null
10296
10370
  ]
10297
10371
  ]]], gmt$14, 0, attrs_table$14, PRIVATE_DATA$14, 0, 0, 0, 0);
10298
10372
  if (!__gclass__$14) return -1;
@@ -9681,6 +9681,11 @@ function load_devices(gobj) {
9681
9681
  "text-field": "{point_count_abbreviated}",
9682
9682
  "text-font": ["Noto Sans Regular"],
9683
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
9684
9689
  }
9685
9690
  });
9686
9691
  map.addLayer({
@@ -9695,12 +9700,16 @@ function load_devices(gobj) {
9695
9700
  "text-offset": [0, -2.5],
9696
9701
  "text-anchor": "top"
9697
9702
  },
9698
- paint: { "text-color": [
9699
- "case",
9700
- ["get", "connected"],
9701
- "green",
9702
- "red"
9703
- ] }
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
+ }
9704
9713
  });
9705
9714
  map.addLayer({
9706
9715
  id: "unclustered-point",
@@ -10014,6 +10023,66 @@ function register_c_yui_map() {
10014
10023
  * All Rights Reserved.
10015
10024
  ***********************************************************************/
10016
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
+ /***************************************************************
10017
10086
  * Constants
10018
10087
  ***************************************************************/
10019
10088
  var GCLASS_NAME$14 = "C_YUI_UPLOT";
@@ -10030,24 +10099,7 @@ var attrs_table$14 = [
10030
10099
  SDATA(data_type_t.DTP_JSON, "axes", 0, [{}], "Chart axes"),
10031
10100
  SDATA(data_type_t.DTP_JSON, "scales", 0, {}, "Chart scales"),
10032
10101
  SDATA(data_type_t.DTP_JSON, "data", 0, [[]], "Chart data"),
10033
- SDATA(data_type_t.DTP_JSON, "colors", 0, [
10034
- {
10035
- stroke: "red",
10036
- fill: "rgba(255,0,0,0.05)"
10037
- },
10038
- {
10039
- stroke: "green",
10040
- fill: "rgba(0,255,0,0.07)"
10041
- },
10042
- {
10043
- stroke: "blue",
10044
- fill: "rgba(0,0,255,0.05)"
10045
- },
10046
- {
10047
- stroke: "orange",
10048
- fill: "rgba(255,165,0,0.1)"
10049
- }
10050
- ], "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)"),
10051
10103
  SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "HTML container for the chart"),
10052
10104
  SDATA(data_type_t.DTP_BOOLEAN, "own_container", 0, false, "If true, container is gobj-managed"),
10053
10105
  SDATA(data_type_t.DTP_POINTER, "uplot", 0, null, "uPlot instance"),
@@ -10055,7 +10107,7 @@ var attrs_table$14 = [
10055
10107
  SDATA(data_type_t.DTP_INTEGER, "timeout_idle", 0, 5, "Idle timeout (seconds)"),
10056
10108
  SDATA_END()
10057
10109
  ];
10058
- var PRIVATE_DATA$14 = {};
10110
+ var PRIVATE_DATA$14 = { theme_observer: null };
10059
10111
  var __gclass__$14 = null;
10060
10112
  /******************************
10061
10113
  * Framework Methods
@@ -10065,6 +10117,7 @@ var __gclass__$14 = null;
10065
10117
  ***************************************************************/
10066
10118
  function mt_create$14(gobj) {
10067
10119
  build_ui$13(gobj);
10120
+ gobj.priv.theme_observer = yui_watch_theme(gobj);
10068
10121
  let subscriber = gobj_read_pointer_attr(gobj, "subscriber");
10069
10122
  if (!subscriber) subscriber = gobj_parent(gobj);
10070
10123
  gobj_subscribe_event(gobj, null, {}, subscriber);
@@ -10081,6 +10134,10 @@ function mt_stop$14(gobj) {}
10081
10134
  * Framework Method: Destroy
10082
10135
  ***************************************************************/
10083
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
+ }
10084
10141
  let uplot = gobj_read_attr(gobj, "uplot");
10085
10142
  if (uplot) {
10086
10143
  uplot.destroy();
@@ -10109,7 +10166,7 @@ function build_ui$13(gobj) {
10109
10166
  width: gobj_read_attr(gobj, "width"),
10110
10167
  height: gobj_read_attr(gobj, "height"),
10111
10168
  series: gobj_read_attr(gobj, "series"),
10112
- axes: gobj_read_attr(gobj, "axes"),
10169
+ axes: themed_axes(gobj_read_attr(gobj, "axes")),
10113
10170
  scales: gobj_read_attr(gobj, "scales")
10114
10171
  };
10115
10172
  let uplot = new uPlot(uPlot_options, gobj_read_attr(gobj, "data"), $container);
@@ -10209,18 +10266,29 @@ function ac_add_serie(gobj, event, kw, src) {
10209
10266
  return -1;
10210
10267
  }
10211
10268
  }
10212
- let color = {
10213
- stroke: "Orange",
10214
- fill: "rgb(255, 165, 0, 0.05)"
10215
- };
10216
10269
  let colors = gobj_read_attr(gobj, "colors");
10217
- 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];
10218
10272
  kw_get_str(gobj, kw, "stroke", color.stroke, kw_flag_t.KW_CREATE);
10219
10273
  kw_get_str(gobj, kw, "fill", color.fill, kw_flag_t.KW_CREATE);
10220
10274
  uplot.addSeries(kw);
10221
10275
  return 0;
10222
10276
  }
10223
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
+ /******************************************************
10224
10292
  *
10225
10293
  ******************************************************/
10226
10294
  function ac_del_serie(gobj, event, kw, src) {
@@ -10267,7 +10335,8 @@ function create_gclass$14(gclass_name) {
10267
10335
  ["EV_LOAD_DATA", 0],
10268
10336
  ["EV_ADD_SERIE", 0],
10269
10337
  ["EV_DEL_SERIE", 0],
10270
- ["EV_CLEAR", 0]
10338
+ ["EV_CLEAR", 0],
10339
+ ["EV_THEME", 0]
10271
10340
  ], [["ST_IDLE", [
10272
10341
  [
10273
10342
  "EV_LOAD_DATA",
@@ -10288,6 +10357,11 @@ function create_gclass$14(gclass_name) {
10288
10357
  "EV_CLEAR",
10289
10358
  ac_clear,
10290
10359
  null
10360
+ ],
10361
+ [
10362
+ "EV_THEME",
10363
+ ac_theme$4,
10364
+ null
10291
10365
  ]
10292
10366
  ]]], gmt$14, 0, attrs_table$14, PRIVATE_DATA$14, 0, 0, 0, 0);
10293
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.96",
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(