@yuneta/gobj-ui 7.28.0 → 7.28.2

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.
@@ -16000,6 +16000,10 @@ function register_c_yui_map() {
16000
16000
  * axes: yui_uplot_axes([{}]), // X and Y, with the ink of the theme
16001
16001
  * }, data, $el);
16002
16002
  *
16003
+ * A vertical axis is as wide as its longest label
16004
+ * (yui_uplot_axis_size, 7.28.1): uPlot's fixed 50px cut every
16005
+ * value past five digits.
16006
+ *
16003
16007
  * The palette is six colours that clear 3:1 on BOTH grounds
16004
16008
  * (worst 3.39 on white, 3.71 on near-black), ordered so the first
16005
16009
  * two are the pair that survives colour blindness -- blue and
@@ -16047,6 +16051,29 @@ var YUI_UPLOT_PALETTE = [
16047
16051
  }
16048
16052
  ];
16049
16053
  /************************************************************
16054
+ * The width of a vertical axis: its longest label, measured
16055
+ * in its own font, plus its ticks and its gap. uPlot gives a
16056
+ * Y axis a fixed 50px, which cuts any label wider than ~5
16057
+ * digits ("150,000" was drawn as ",0,000"). uPlot asks again
16058
+ * while the size settles (`cycle`): past the first answer the
16059
+ * last size stands, or the layout never converges.
16060
+ ************************************************************/
16061
+ function yui_uplot_axis_size(self, values, axis_idx, cycle) {
16062
+ let axis = self.axes[axis_idx];
16063
+ if (cycle > 1 && axis._size) return axis._size;
16064
+ let size = (axis.ticks && axis.ticks.size || 10) + (axis.gap || 5);
16065
+ let longest = (values || []).reduce((acc, v) => {
16066
+ let txt = v == null ? "" : String(v);
16067
+ return txt.length > acc.length ? txt : acc;
16068
+ }, "");
16069
+ if (longest && self.ctx) {
16070
+ self.ctx.font = Array.isArray(axis.font) ? axis.font[0] : axis.font || self.ctx.font;
16071
+ let dpr = typeof devicePixelRatio === "number" && devicePixelRatio > 0 ? devicePixelRatio : 1;
16072
+ size += self.ctx.measureText(longest).width / dpr;
16073
+ }
16074
+ return Math.max(50, Math.ceil(size));
16075
+ }
16076
+ /************************************************************
16050
16077
  * The axes the host asked for -- at least the X and the Y,
16051
16078
  * the two uPlot always draws -- with the ink it did not ask
16052
16079
  * about. A stroke, a grid or a ticks the host gave is kept.
@@ -16055,9 +16082,10 @@ var YUI_UPLOT_PALETTE = [
16055
16082
  function yui_uplot_axes(axes) {
16056
16083
  let list = Array.isArray(axes) ? axes.slice() : [axes || {}];
16057
16084
  while (list.length < 2) list.push({});
16058
- return list.map((ax) => {
16085
+ return list.map((ax, i) => {
16059
16086
  let a = Object.assign({}, ax || {});
16060
16087
  if (a.stroke === void 0) a.stroke = yui_uplot_axis_ink;
16088
+ if (i > 0 && (a.side === void 0 || a.side === 1 || a.side === 3) && a.size === void 0) a.size = yui_uplot_axis_size;
16061
16089
  a.grid = Object.assign({ stroke: yui_uplot_grid_ink }, a.grid || {});
16062
16090
  a.ticks = Object.assign({ stroke: yui_uplot_grid_ink }, a.ticks || {});
16063
16091
  return a;
@@ -15995,6 +15995,10 @@ function register_c_yui_map() {
15995
15995
  * axes: yui_uplot_axes([{}]), // X and Y, with the ink of the theme
15996
15996
  * }, data, $el);
15997
15997
  *
15998
+ * A vertical axis is as wide as its longest label
15999
+ * (yui_uplot_axis_size, 7.28.1): uPlot's fixed 50px cut every
16000
+ * value past five digits.
16001
+ *
15998
16002
  * The palette is six colours that clear 3:1 on BOTH grounds
15999
16003
  * (worst 3.39 on white, 3.71 on near-black), ordered so the first
16000
16004
  * two are the pair that survives colour blindness -- blue and
@@ -16042,6 +16046,29 @@ var YUI_UPLOT_PALETTE = [
16042
16046
  }
16043
16047
  ];
16044
16048
  /************************************************************
16049
+ * The width of a vertical axis: its longest label, measured
16050
+ * in its own font, plus its ticks and its gap. uPlot gives a
16051
+ * Y axis a fixed 50px, which cuts any label wider than ~5
16052
+ * digits ("150,000" was drawn as ",0,000"). uPlot asks again
16053
+ * while the size settles (`cycle`): past the first answer the
16054
+ * last size stands, or the layout never converges.
16055
+ ************************************************************/
16056
+ function yui_uplot_axis_size(self, values, axis_idx, cycle) {
16057
+ let axis = self.axes[axis_idx];
16058
+ if (cycle > 1 && axis._size) return axis._size;
16059
+ let size = (axis.ticks && axis.ticks.size || 10) + (axis.gap || 5);
16060
+ let longest = (values || []).reduce((acc, v) => {
16061
+ let txt = v == null ? "" : String(v);
16062
+ return txt.length > acc.length ? txt : acc;
16063
+ }, "");
16064
+ if (longest && self.ctx) {
16065
+ self.ctx.font = Array.isArray(axis.font) ? axis.font[0] : axis.font || self.ctx.font;
16066
+ let dpr = typeof devicePixelRatio === "number" && devicePixelRatio > 0 ? devicePixelRatio : 1;
16067
+ size += self.ctx.measureText(longest).width / dpr;
16068
+ }
16069
+ return Math.max(50, Math.ceil(size));
16070
+ }
16071
+ /************************************************************
16045
16072
  * The axes the host asked for -- at least the X and the Y,
16046
16073
  * the two uPlot always draws -- with the ink it did not ask
16047
16074
  * about. A stroke, a grid or a ticks the host gave is kept.
@@ -16050,9 +16077,10 @@ var YUI_UPLOT_PALETTE = [
16050
16077
  function yui_uplot_axes(axes) {
16051
16078
  let list = Array.isArray(axes) ? axes.slice() : [axes || {}];
16052
16079
  while (list.length < 2) list.push({});
16053
- return list.map((ax) => {
16080
+ return list.map((ax, i) => {
16054
16081
  let a = Object.assign({}, ax || {});
16055
16082
  if (a.stroke === void 0) a.stroke = yui_uplot_axis_ink;
16083
+ if (i > 0 && (a.side === void 0 || a.side === 1 || a.side === 3) && a.size === void 0) a.size = yui_uplot_axis_size;
16056
16084
  a.grid = Object.assign({ stroke: yui_uplot_grid_ink }, a.grid || {});
16057
16085
  a.ticks = Object.assign({ stroke: yui_uplot_grid_ink }, a.ticks || {});
16058
16086
  return a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.28.0",
3
+ "version": "7.28.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/gobj-ui.cjs.js",
@@ -42,7 +42,7 @@ const {
42
42
  } = await import("@yuneta/gobj-js");
43
43
  const {register_c_yui_uplot} = await import("./c_yui_uplot.js");
44
44
  const {
45
- yui_uplot_axes, yui_uplot_axis_ink, yui_uplot_grid_ink,
45
+ yui_uplot_axes, yui_uplot_axis_ink, yui_uplot_grid_ink, yui_uplot_axis_size,
46
46
  } = await import("./yui_uplot_ink.js");
47
47
 
48
48
  const logged = [];
@@ -67,6 +67,35 @@ afterEach(() => {
67
67
  document.documentElement.removeAttribute("data-theme");
68
68
  });
69
69
 
70
+ describe("the width of a vertical axis", () => {
71
+ const fake = (px_per_char) => ({
72
+ ctx: {font: "", measureText: (t) => ({width: t.length * px_per_char})},
73
+ axes: [{}, {ticks: {size: 10}, gap: 5, font: ["12px sans-serif"]}]
74
+ });
75
+
76
+ test("the Y axes are sized by their labels, the X is not; a host's size stands", () => {
77
+ const axes = yui_uplot_axes([{}, {}, {side: 1}, {side: 2}, {size: 80}]);
78
+ expect(axes[0].size).toBeUndefined();
79
+ expect(axes[1].size).toBe(yui_uplot_axis_size);
80
+ expect(axes[2].size).toBe(yui_uplot_axis_size);
81
+ expect(axes[3].size).toBeUndefined();
82
+ expect(axes[4].size).toBe(80);
83
+ });
84
+
85
+ test("fits the longest label, never under uPlot's 50px", () => {
86
+ const self = fake(7);
87
+ expect(yui_uplot_axis_size(self, ["0", "50,000", "150,000"], 1, 0)).toBe(Math.ceil(15 + 7 * 7));
88
+ expect(yui_uplot_axis_size(fake(7), ["0", "5"], 1, 0)).toBe(50);
89
+ expect(yui_uplot_axis_size(fake(7), null, 1, 0)).toBe(50);
90
+ });
91
+
92
+ test("past the first cycle the size settled stands", () => {
93
+ const self = fake(7);
94
+ self.axes[1]._size = 66;
95
+ expect(yui_uplot_axis_size(self, ["1,000,000,000"], 1, 2)).toBe(66);
96
+ });
97
+ });
98
+
70
99
  describe("yui_uplot_axes()", () => {
71
100
  test("gives the X and the Y axes, the two uPlot draws", () => {
72
101
  expect(yui_uplot_axes([{}]).length).toBe(2);
package/src/yui_dev.js CHANGED
@@ -935,7 +935,7 @@ function render_log(e)
935
935
  * createElement2() TRIMS a string content -- it has to, to decide
936
936
  * whether the string is HTML by looking at its first character -- and
937
937
  * the machine trace's leading spaces are its NESTING: gobj-js prefixes
938
- * every line with `tab()`, two spaces per level of __inside__, so an
938
+ * every line with `tab()`, four spaces per level of __inside__, so an
939
939
  * event sent from inside another one's action is indented under it.
940
940
  * Passed through createElement2 that indentation was eaten, and the
941
941
  * window showed a flat column where the console showed a tree. */
package/src/yui_icons.css CHANGED
@@ -511,6 +511,18 @@
511
511
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 384 512'%3E%3Cpath d='M0 64C0 28.7 28.7 0 64 0L213.5 0c17 0 33.3 6.7 45.3 18.7L365.3 125.3c12 12 18.7 28.3 18.7 45.3L384 448c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 64zm208-5.5l0 93.5c0 13.3 10.7 24 24 24L325.5 176 208 58.5zM154.2 295.6c8.6-10.1 7.5-25.2-2.6-33.8s-25.2-7.5-33.8 2.6l-48 56c-7.7 9-7.7 22.2 0 31.2l48 56c8.6 10.1 23.8 11.2 33.8 2.6s11.2-23.8 2.6-33.8l-34.6-40.4 34.6-40.4zm112-31.2c-8.6-10.1-23.8-11.2-33.8-2.6s-11.2 23.8-2.6 33.8l34.6 40.4-34.6 40.4c-8.6 10.1-7.5 25.2 2.6 33.8s25.2 7.5 33.8-2.6l48-56c7.7-9 7.7-22.2 0-31.2l-48-56z'/%3E%3C/svg%3E");
512
512
  }
513
513
 
514
+ /* An image of what is on screen, and the same as a document to print or
515
+ * keep as PDF (FontAwesome Free 7.3.1). */
516
+ .yi-file-image::before {
517
+ -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 384 512'%3E%3Cpath d='M0 64C0 28.7 28.7 0 64 0L213.5 0c17 0 33.3 6.7 45.3 18.7L365.3 125.3c12 12 18.7 28.3 18.7 45.3L384 448c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 64zm208-5.5l0 93.5c0 13.3 10.7 24 24 24L325.5 176 208 58.5zM128 256a32 32 0 1 0 -64 0 32 32 0 1 0 64 0zM92.6 448l198.8 0c15.8 0 28.6-12.8 28.6-28.6 0-7.3-2.8-14.4-7.9-19.7L215.3 297.9c-6-6.3-14.4-9.9-23.2-9.9l-.3 0c-8.8 0-17.1 3.6-23.2 9.9L71.9 399.7C66.8 405 64 412.1 64 419.4 64 435.2 76.8 448 92.6 448z'/%3E%3C/svg%3E");
518
+ mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 384 512'%3E%3Cpath d='M0 64C0 28.7 28.7 0 64 0L213.5 0c17 0 33.3 6.7 45.3 18.7L365.3 125.3c12 12 18.7 28.3 18.7 45.3L384 448c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 64zm208-5.5l0 93.5c0 13.3 10.7 24 24 24L325.5 176 208 58.5zM128 256a32 32 0 1 0 -64 0 32 32 0 1 0 64 0zM92.6 448l198.8 0c15.8 0 28.6-12.8 28.6-28.6 0-7.3-2.8-14.4-7.9-19.7L215.3 297.9c-6-6.3-14.4-9.9-23.2-9.9l-.3 0c-8.8 0-17.1 3.6-23.2 9.9L71.9 399.7C66.8 405 64 412.1 64 419.4 64 435.2 76.8 448 92.6 448z'/%3E%3C/svg%3E");
519
+ }
520
+
521
+ .yi-file-pdf::before {
522
+ -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 576 512'%3E%3Cpath d='M96 0C60.7 0 32 28.7 32 64l0 384c0 35.3 28.7 64 64 64l80 0 0-112c0-35.3 28.7-64 64-64l176 0 0-165.5c0-17-6.7-33.3-18.7-45.3L290.7 18.7C278.7 6.7 262.5 0 245.5 0L96 0zM357.5 176L264 176c-13.3 0-24-10.7-24-24L240 58.5 357.5 176zM240 380c-11 0-20 9-20 20l0 128c0 11 9 20 20 20s20-9 20-20l0-28 12 0c33.1 0 60-26.9 60-60s-26.9-60-60-60l-32 0zm32 80l-12 0 0-40 12 0c11 0 20 9 20 20s-9 20-20 20zm96-80c-11 0-20 9-20 20l0 128c0 11 9 20 20 20l32 0c28.7 0 52-23.3 52-52l0-64c0-28.7-23.3-52-52-52l-32 0zm20 128l0-88 12 0c6.6 0 12 5.4 12 12l0 64c0 6.6-5.4 12-12 12l-12 0zm88-108l0 128c0 11 9 20 20 20s20-9 20-20l0-44 28 0c11 0 20-9 20-20s-9-20-20-20l-28 0 0-24 28 0c11 0 20-9 20-20s-9-20-20-20l-48 0c-11 0-20 9-20 20z'/%3E%3C/svg%3E");
523
+ mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 576 512'%3E%3Cpath d='M96 0C60.7 0 32 28.7 32 64l0 384c0 35.3 28.7 64 64 64l80 0 0-112c0-35.3 28.7-64 64-64l176 0 0-165.5c0-17-6.7-33.3-18.7-45.3L290.7 18.7C278.7 6.7 262.5 0 245.5 0L96 0zM357.5 176L264 176c-13.3 0-24-10.7-24-24L240 58.5 357.5 176zM240 380c-11 0-20 9-20 20l0 128c0 11 9 20 20 20s20-9 20-20l0-28 12 0c33.1 0 60-26.9 60-60s-26.9-60-60-60l-32 0zm32 80l-12 0 0-40 12 0c11 0 20 9 20 20s-9 20-20 20zm96-80c-11 0-20 9-20 20l0 128c0 11 9 20 20 20l32 0c28.7 0 52-23.3 52-52l0-64c0-28.7-23.3-52-52-52l-32 0zm20 128l0-88 12 0c6.6 0 12 5.4 12 12l0 64c0 6.6-5.4 12-12 12l-12 0zm88-108l0 128c0 11 9 20 20 20s20-9 20-20l0-44 28 0c11 0 20-9 20-20s-9-20-20-20l-28 0 0-24 28 0c11 0 20-9 20-20s-9-20-20-20l-48 0c-11 0-20 9-20 20z'/%3E%3C/svg%3E");
524
+ }
525
+
514
526
  /* Open apart: a box with an arrow leaving it, the "open in a new
515
527
  * window" of Material (open_in_new), Gmail, Teams and Slack. Two
516
528
  * overlapping frames say COPY in the market (FontAwesome Free 7.3.1). */
@@ -28,6 +28,10 @@
28
28
  * axes: yui_uplot_axes([{}]), // X and Y, with the ink of the theme
29
29
  * }, data, $el);
30
30
  *
31
+ * A vertical axis is as wide as its longest label
32
+ * (yui_uplot_axis_size, 7.28.1): uPlot's fixed 50px cut every
33
+ * value past five digits.
34
+ *
31
35
  * The palette is six colours that clear 3:1 on BOTH grounds
32
36
  * (worst 3.39 on white, 3.71 on near-black), ordered so the first
33
37
  * two are the pair that survives colour blindness -- blue and
@@ -63,6 +67,33 @@ const YUI_UPLOT_PALETTE = [
63
67
  {stroke: "#d1344b", fill: "rgba(209,52,75,0.10)"}, /* 4.88 / 3.71 */
64
68
  ];
65
69
 
70
+ /************************************************************
71
+ * The width of a vertical axis: its longest label, measured
72
+ * in its own font, plus its ticks and its gap. uPlot gives a
73
+ * Y axis a fixed 50px, which cuts any label wider than ~5
74
+ * digits ("150,000" was drawn as ",0,000"). uPlot asks again
75
+ * while the size settles (`cycle`): past the first answer the
76
+ * last size stands, or the layout never converges.
77
+ ************************************************************/
78
+ function yui_uplot_axis_size(self, values, axis_idx, cycle)
79
+ {
80
+ let axis = self.axes[axis_idx];
81
+ if(cycle > 1 && axis._size) {
82
+ return axis._size;
83
+ }
84
+ let size = ((axis.ticks && axis.ticks.size) || 10) + (axis.gap || 5);
85
+ let longest = (values || []).reduce((acc, v) => {
86
+ let txt = v == null ? "" : String(v);
87
+ return txt.length > acc.length ? txt : acc;
88
+ }, "");
89
+ if(longest && self.ctx) {
90
+ self.ctx.font = Array.isArray(axis.font) ? axis.font[0] : (axis.font || self.ctx.font);
91
+ let dpr = (typeof devicePixelRatio === "number" && devicePixelRatio > 0) ? devicePixelRatio : 1;
92
+ size += self.ctx.measureText(longest).width / dpr;
93
+ }
94
+ return Math.max(50, Math.ceil(size));
95
+ }
96
+
66
97
  /************************************************************
67
98
  * The axes the host asked for -- at least the X and the Y,
68
99
  * the two uPlot always draws -- with the ink it did not ask
@@ -75,11 +106,17 @@ function yui_uplot_axes(axes)
75
106
  while(list.length < 2) {
76
107
  list.push({});
77
108
  }
78
- return list.map((ax) => {
109
+ return list.map((ax, i) => {
79
110
  let a = Object.assign({}, ax || {});
80
111
  if(a.stroke === undefined) {
81
112
  a.stroke = yui_uplot_axis_ink;
82
113
  }
114
+ /* A vertical axis (uPlot's sides 1 and 3; the Y default is 3)
115
+ * as wide as its labels, unless the host sized it */
116
+ let vertical = i > 0 && (a.side === undefined || a.side === 1 || a.side === 3);
117
+ if(vertical && a.size === undefined) {
118
+ a.size = yui_uplot_axis_size;
119
+ }
83
120
  a.grid = Object.assign({stroke: yui_uplot_grid_ink}, a.grid || {});
84
121
  a.ticks = Object.assign({stroke: yui_uplot_grid_ink}, a.ticks || {});
85
122
  return a;
@@ -88,6 +125,7 @@ function yui_uplot_axes(axes)
88
125
 
89
126
  export {
90
127
  yui_uplot_axes,
128
+ yui_uplot_axis_size,
91
129
  yui_uplot_axis_ink,
92
130
  yui_uplot_grid_ink,
93
131
  YUI_UPLOT_PALETTE,