billboard.js 3.9.2 → 3.10.0-next.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.
Files changed (91) hide show
  1. package/README.md +2 -2
  2. package/dist/billboard.css +2 -2
  3. package/dist/billboard.js +2705 -2529
  4. package/dist/billboard.min.css +2 -2
  5. package/dist/billboard.min.js +2 -2
  6. package/dist/billboard.pkgd.js +3516 -3329
  7. package/dist/billboard.pkgd.min.js +4 -4
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.js +15 -15
  9. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  10. package/dist/plugin/billboardjs-plugin-sparkline.js +215 -196
  11. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-stanford.js +244 -239
  13. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  14. package/dist/plugin/billboardjs-plugin-tableview.js +184 -164
  15. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  16. package/dist/plugin/billboardjs-plugin-textoverlap.js +170 -151
  17. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  18. package/dist/plugin/pkgd/{billboardjs-plugin-bubblecompare.js → billboardjs-plugin-bubblecompare.pkgd.js} +667 -642
  19. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +12 -0
  20. package/dist/plugin/pkgd/{billboardjs-plugin-sparkline.js → billboardjs-plugin-sparkline.pkgd.js} +864 -820
  21. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +12 -0
  22. package/dist/plugin/pkgd/{billboardjs-plugin-stanford.js → billboardjs-plugin-stanford.pkgd.js} +929 -900
  23. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +12 -0
  24. package/dist/plugin/pkgd/{billboardjs-plugin-tableview.js → billboardjs-plugin-tableview.pkgd.js} +833 -788
  25. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +12 -0
  26. package/dist/plugin/pkgd/{billboardjs-plugin-textoverlap.js → billboardjs-plugin-textoverlap.pkgd.js} +932 -897
  27. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +12 -0
  28. package/dist/theme/dark.css +5 -4
  29. package/dist/theme/dark.min.css +2 -2
  30. package/dist/theme/datalab.css +5 -4
  31. package/dist/theme/datalab.min.css +2 -2
  32. package/dist/theme/graph.css +5 -4
  33. package/dist/theme/graph.min.css +2 -2
  34. package/dist/theme/insight.css +5 -4
  35. package/dist/theme/insight.min.css +2 -2
  36. package/dist-esm/billboard.js +605 -468
  37. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +3 -3
  38. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +13 -7
  39. package/dist-esm/plugin/billboardjs-plugin-stanford.js +21 -28
  40. package/dist-esm/plugin/billboardjs-plugin-tableview.js +17 -11
  41. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +13 -7
  42. package/package.json +31 -31
  43. package/src/Chart/api/axis.ts +4 -0
  44. package/src/Chart/api/category.ts +8 -4
  45. package/src/Chart/api/export.ts +1 -2
  46. package/src/Chart/api/subchart.ts +162 -89
  47. package/src/Chart/api/zoom.ts +69 -79
  48. package/src/ChartInternal/Axis/AxisRendererHelper.ts +0 -8
  49. package/src/ChartInternal/data/IData.ts +4 -1
  50. package/src/ChartInternal/data/convert.helper.ts +1 -15
  51. package/src/ChartInternal/data/data.ts +8 -2
  52. package/src/ChartInternal/interactions/eventrect.ts +0 -1
  53. package/src/ChartInternal/interactions/flow.ts +1 -7
  54. package/src/ChartInternal/interactions/interaction.ts +10 -4
  55. package/src/ChartInternal/interactions/subchart.ts +36 -30
  56. package/src/ChartInternal/interactions/zoom.ts +13 -3
  57. package/src/ChartInternal/internals/category.ts +2 -2
  58. package/src/ChartInternal/internals/clip.ts +4 -4
  59. package/src/ChartInternal/internals/domain.ts +46 -10
  60. package/src/ChartInternal/internals/grid.ts +57 -86
  61. package/src/ChartInternal/internals/redraw.ts +0 -5
  62. package/src/ChartInternal/internals/region.ts +35 -12
  63. package/src/ChartInternal/internals/text.ts +1 -26
  64. package/src/ChartInternal/internals/title.ts +10 -48
  65. package/src/ChartInternal/internals/tooltip.ts +47 -51
  66. package/src/ChartInternal/shape/arc.ts +16 -6
  67. package/src/ChartInternal/shape/candlestick.ts +2 -17
  68. package/src/ChartInternal/shape/shape.ts +50 -4
  69. package/src/ChartInternal/shape/treemap.ts +2 -2
  70. package/src/Plugin/bubblecompare/index.ts +1 -1
  71. package/src/Plugin/stanford/Elements.ts +10 -2
  72. package/src/Plugin/stanford/index.ts +1 -24
  73. package/src/Plugin/tableview/index.ts +2 -2
  74. package/src/config/Options/axis/x.ts +1 -0
  75. package/src/config/Options/common/main.ts +12 -2
  76. package/src/config/Options/common/tooltip.ts +10 -10
  77. package/src/config/Options/data/axis.ts +3 -1
  78. package/src/config/Options/data/data.ts +10 -2
  79. package/src/config/Store/State.ts +3 -0
  80. package/src/module/Cache.ts +7 -5
  81. package/src/module/browser.ts +34 -14
  82. package/src/module/util.ts +8 -4
  83. package/src/module/worker.ts +24 -13
  84. package/src/scss/billboard.scss +4 -2
  85. package/src/scss/theme/dark.scss +4 -2
  86. package/src/scss/theme/datalab.scss +4 -2
  87. package/src/scss/theme/graph.scss +4 -2
  88. package/src/scss/theme/insight.scss +4 -2
  89. package/types/chart.d.ts +11 -0
  90. package/types/options.d.ts +3 -3
  91. package/types/types.d.ts +15 -1
@@ -18,9 +18,11 @@ export default {
18
18
  */
19
19
  initBrush(): void {
20
20
  const $$ = this;
21
- const {config, scale, $el: {subchart}} = $$;
21
+ const {config, scale, $el: {subchart}, state} = $$;
22
22
  const isRotated = config.axis_rotated;
23
+ const height = config.subchart_size_height;
23
24
  let lastDomain;
25
+ let lastSelection;
24
26
  let timeout;
25
27
 
26
28
  // set the brush
@@ -28,28 +30,27 @@ export default {
28
30
  isRotated ? d3BrushY() : d3BrushX()
29
31
  ).handleSize(5);
30
32
 
31
- const getBrushSize = () => {
32
- const brush = $$.$el.svg.select(`.${CLASS.brush} .overlay`);
33
- const brushSize = {width: 0, height: 0};
34
-
35
- if (brush.size()) {
36
- brushSize.width = +brush.attr("width");
37
- brushSize.height = +brush.attr("height");
38
- }
39
-
40
- return brushSize[isRotated ? "width" : "height"];
41
- };
42
-
43
33
  // bind brush event
44
34
  $$.brush.on("start brush end", event => {
45
- const {selection, target, type} = event;
35
+ const {selection, sourceEvent, target, type} = event;
46
36
 
47
37
  if (type === "start") {
48
38
  $$.state.inputType === "touch" && $$.hideTooltip();
39
+ lastSelection = sourceEvent ? selection : null;
40
+ // sourceEvent && (state.domain = null);
49
41
  }
50
42
 
43
+ // if (type === "brush") {
51
44
  if (/(start|brush)/.test(type)) {
52
- $$.redrawForBrush();
45
+ // when brush selection updates happens on one edge, update only chainging edge and
46
+ // is only for adjustment of given domain range to be used to return current domain range.
47
+ type === "brush" && sourceEvent && state.domain && lastSelection?.forEach((v, i) => {
48
+ if (v !== selection[i]) {
49
+ state.domain[i] = scale.x.orgDomain()[i];
50
+ }
51
+ });
52
+
53
+ $$.redrawForBrush(type !== "start");
53
54
  }
54
55
 
55
56
  if (type === "end") {
@@ -63,10 +64,9 @@ export default {
63
64
  } else {
64
65
  $$.brush.handle.attr("display", null)
65
66
  .attr("transform", (d, i) => {
66
- const pos = isRotated ?
67
- [33, selection[i] - (i === 0 ? 30 : 24)] : [selection[i], 3];
67
+ const pos = [selection[i], height / 2];
68
68
 
69
- return `translate(${pos})`;
69
+ return `translate(${isRotated ? pos.reverse() : pos})`;
70
70
  });
71
71
  }
72
72
  }
@@ -94,7 +94,7 @@ export default {
94
94
 
95
95
  // set the brush extent
96
96
  $$.brush.scale = function(scale) {
97
- const h = config.subchart_size_height || getBrushSize();
97
+ const h = config.subchart_size_height;
98
98
  let extent = $$.getExtent();
99
99
 
100
100
  if (!extent && scale.range) {
@@ -199,11 +199,11 @@ export default {
199
199
 
200
200
  // brush handle shape's path
201
201
  const path = isRotated ? [
202
- "M 5.2491724,29.749209 a 6,6 0 0 0 -5.50000003,-6.5 H -5.7508276 a 6,6 0 0 0 -6.0000004,6.5 z m -5.00000003,-2 H -6.7508276 m 6.99999997,-2 H -6.7508276Z",
203
- "M 5.2491724,23.249172 a 6,-6 0 0 1 -5.50000003,6.5 H -5.7508276 a 6,-6 0 0 1 -6.0000004,-6.5 z m -5.00000003,2 H -6.7508276 m 6.99999997,2 H -6.7508276Z"
202
+ "M8.5 0 a6 6 0 0 0 -6 -6.5 H-2.5 a 6 6 0 0 0 -6 6.5 z m-5 -2 H-3.5 m7 -2 H-3.5z",
203
+ "M8.5 0 a6 -6 0 0 1 -6 6.5 H-2.5 a 6 -6 0 0 1 -6 -6.5z m-5 2 H-3.5 m7 2 H-3.5z"
204
204
  ] : [
205
- "M 0 18 A 6 6 0 0 0 -6.5 23.5 V 29 A 6 6 0 0 0 0 35 Z M -2 23 V 30 M -4 23 V 30Z",
206
- "M 0 18 A 6 6 0 0 1 6.5 23.5 V 29 A 6 6 0 0 1 0 35 Z M 2 23 V 30 M 4 23 V 30Z"
205
+ "M0 -8.5 A6 6 0 0 0 -6.5 -3.5 V2.5 A6 6 0 0 0 0 8.5 Z M-2 -3.5 V3.5 M-4 -3.5 V3.5z",
206
+ "M0 -8.5 A6 6 0 0 1 6.5 -3.5 V2.5 A6 6 0 0 1 0 8.5 Z M2 -3.5 V3.5 M4 -3.5 V3.5z"
207
207
  ];
208
208
 
209
209
  $$.brush.handle = brush.selectAll(`.${customHandleClass}`)
@@ -320,23 +320,28 @@ export default {
320
320
  $$.redrawCircle(cx, cy, withTransition, undefined, true);
321
321
  }
322
322
 
323
- !state.rendered && initRange && $$.brush.move(
324
- $$.brush.getSelection(),
325
- initRange.map($$.scale.x)
326
- );
323
+ if (!state.rendered && initRange) {
324
+ state.domain = initRange;
325
+
326
+ $$.brush.move(
327
+ $$.brush.getSelection(),
328
+ initRange.map($$.scale.x)
329
+ );
330
+ }
327
331
  }
328
332
  }
329
333
  },
330
334
 
331
335
  /**
332
336
  * Redraw the brush.
337
+ * @param {boolean} [callCallbck=true] Call 'onbrush' callback or not.
333
338
  * @private
334
339
  */
335
- redrawForBrush() {
340
+ redrawForBrush(callCallbck = true): void {
336
341
  const $$ = this;
337
342
  const {config: {
338
343
  subchart_onbrush: onBrush, zoom_rescale: withY
339
- }, scale} = $$;
344
+ }, scale, state} = $$;
340
345
 
341
346
  $$.redraw({
342
347
  withTransition: false,
@@ -346,7 +351,8 @@ export default {
346
351
  withDimension: false
347
352
  });
348
353
 
349
- onBrush.bind($$.api)(scale.x.orgDomain());
354
+ callCallbck && state.rendered &&
355
+ onBrush.bind($$.api)(state.domain ?? scale.x.orgDomain());
350
356
  },
351
357
 
352
358
  /**
@@ -125,7 +125,7 @@ export default {
125
125
  * @private
126
126
  */
127
127
  // @ts-ignore
128
- zoom.getDomain = (): number|Date[] => {
128
+ zoom.getDomain = (): (number | Date)[] => {
129
129
  const domain = scale[scale.zoom ? "zoom" : "subX"].domain();
130
130
  const isCategorized = $$.axis.isCategorized();
131
131
 
@@ -135,6 +135,7 @@ export default {
135
135
 
136
136
  return domain;
137
137
  };
138
+
138
139
  $$.zoom = zoom;
139
140
  },
140
141
 
@@ -175,6 +176,7 @@ export default {
175
176
 
176
177
  if (event.sourceEvent) {
177
178
  state.zooming = true;
179
+ state.domain = undefined;
178
180
  }
179
181
 
180
182
  const isMousemove = sourceEvent?.type === "mousemove";
@@ -206,7 +208,11 @@ export default {
206
208
  $$.state.cancelClick = isMousemove;
207
209
 
208
210
  // do not call event cb when is .unzoom() is called
209
- !isUnZoom && callFn(config.zoom_onzoom, $$.api, $$.zoom.getDomain());
211
+ !isUnZoom && callFn(
212
+ config.zoom_onzoom,
213
+ $$.api,
214
+ $$.state.domain ?? $$.zoom.getDomain()
215
+ );
210
216
  },
211
217
 
212
218
  /**
@@ -239,7 +245,11 @@ export default {
239
245
  state.zooming = false;
240
246
 
241
247
  // do not call event cb when is .unzoom() is called
242
- !isUnZoom && (e || state.dragging) && callFn(config.zoom_onzoomend, $$.api, $$.zoom.getDomain());
248
+ !isUnZoom && (e || state.dragging) && callFn(
249
+ config.zoom_onzoomend,
250
+ $$.api,
251
+ $$.state.domain ?? $$.zoom.getDomain()
252
+ );
243
253
  },
244
254
 
245
255
  /**
@@ -10,8 +10,8 @@ export default {
10
10
  * @private
11
11
  */
12
12
  categoryName(i: number): string {
13
- const {axis_x_categories: categories} = this.config;
13
+ const {axis_x_categories} = this.config;
14
14
 
15
- return i < categories?.length ? categories[i] : i;
15
+ return axis_x_categories?.[i] ?? i;
16
16
  },
17
17
  };
@@ -57,13 +57,13 @@ export default {
57
57
  const isRotated = config.axis_rotated;
58
58
  const left = Math.max(30, margin.left) - (isRotated ? 0 : 20);
59
59
 
60
- const x = isRotated ? -(1 + left) : -(left - 1);
61
- const y = -Math.max(15, margin.top);
62
- const w = isRotated ? margin.left + 20 : width + 10 + left;
63
-
64
60
  // less than 20 is not enough to show the axis label 'outer' without legend
65
61
  const h = (isRotated ? (margin.top + height) + 10 : margin.bottom) + 20;
66
62
 
63
+ const x = isRotated ? -(1 + left) : -(left - 1);
64
+ const y = -Math.max(15, margin.bottom);
65
+ const w = isRotated ? margin.left + 20 : width + 10 + left;
66
+
67
67
  node
68
68
  .attr("x", x)
69
69
  .attr("y", y)
@@ -3,7 +3,7 @@
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
5
  import {TYPE, TYPE_BY_CATEGORY} from "../../config/const";
6
- import type {IData} from "../data/IData";
6
+ import type {IData, TDomainRange} from "../data/IData";
7
7
  import {brushEmpty, getBrushSelection, getMinMax, isDefined, notEmpty, isValue, isObject, isNumber, diffDomain, parseDate, sortValue} from "../../module/util";
8
8
 
9
9
  export default {
@@ -368,21 +368,25 @@ export default {
368
368
  },
369
369
 
370
370
  /**
371
- * Get zoom domain
371
+ * Get subchart/zoom domain
372
+ * @param {string} type "subX" or "zoom"
373
+ * @param {boolean} getCurrent Get current domain if true
372
374
  * @returns {Array} zoom domain
373
375
  * @private
374
376
  */
375
- getZoomDomain(): [number|Date, number|Date] {
377
+ getZoomDomain(type: "subX" | "zoom" = "zoom", getCurrent = false): TDomainRange {
376
378
  const $$ = this;
377
- const {config, org} = $$;
378
- let [min, max] = org.xDomain;
379
+ const {config, scale, org} = $$;
380
+ let [min, max] = getCurrent && scale[type] ? scale[type].domain() : org.xDomain;
379
381
 
380
- if (isDefined(config.zoom_x_min)) {
381
- min = getMinMax("min", [min, config.zoom_x_min]);
382
- }
382
+ if (type === "zoom") {
383
+ if (isDefined(config.zoom_x_min)) {
384
+ min = getMinMax("min", [min, config.zoom_x_min]);
385
+ }
383
386
 
384
- if (isDefined(config.zoom_x_max)) {
385
- max = getMinMax("max", [max, config.zoom_x_max]);
387
+ if (isDefined(config.zoom_x_max)) {
388
+ max = getMinMax("max", [max, config.zoom_x_max]);
389
+ }
386
390
  }
387
391
 
388
392
  return [min, max];
@@ -409,5 +413,37 @@ export default {
409
413
  }
410
414
 
411
415
  return domainLength * (pixels / state[length]);
416
+ },
417
+
418
+ /**
419
+ * Check if the given domain is within subchart/zoom range
420
+ * @param {Array} domain Target domain value
421
+ * @param {Array} current Current subchart/zoom domain value
422
+ * @param {Array} range subchart/zoom range value
423
+ * @returns {boolean}
424
+ * @private
425
+ */
426
+ withinRange<T = TDomainRange>(domain: T, current: T, range: T): boolean {
427
+ const $$ = this;
428
+ const isInverted = $$.config.axis_x_inverted;
429
+ const [min, max] = range as number[];
430
+
431
+ if (Array.isArray(domain)) {
432
+ const target = [...domain];
433
+
434
+ isInverted && target.reverse();
435
+
436
+ if (target[0] < target[1]) {
437
+ return domain.every((v, i) => (
438
+ i === 0 ? (
439
+ isInverted ? +v <= min : +v >= min
440
+ ) : (
441
+ isInverted ? +v >= max : +v <= max
442
+ )
443
+ ) && !(domain.every((v, i) => v === current[i])));
444
+ }
445
+ }
446
+
447
+ return false;
412
448
  }
413
449
  };
@@ -169,109 +169,65 @@ export default {
169
169
  grid.main.style("visibility", $$.hasArcType() ? "hidden" : null);
170
170
 
171
171
  $$.hideGridFocus();
172
- $$.updateXGridLines();
173
- $$.updateYGridLines();
172
+ $$.updateGridLines("x");
173
+ $$.updateGridLines("y");
174
174
  },
175
175
 
176
176
  /**
177
- * Update X Grid lines
177
+ * Update Grid lines
178
+ * @param {string} type x | y
178
179
  * @private
179
180
  */
180
- updateXGridLines(): void {
181
+ updateGridLines(type: "x" | "y"): void {
181
182
  const $$ = this;
182
183
  const {config, $el: {gridLines, main}, $T} = $$;
183
184
  const isRotated = config.axis_rotated;
185
+ const isX = type === "x";
184
186
 
185
- config.grid_x_show && $$.updateXGrid();
187
+ config[`grid_${type}_show`] && $$[`update${type.toUpperCase()}Grid`]();
186
188
 
187
- let xLines = main.select(`.${$GRID.xgridLines}`)
188
- .selectAll(`.${$GRID.xgridLine}`)
189
- .data(config.grid_x_lines);
189
+ let lines = main.select(`.${$GRID[`${type}gridLines`]}`)
190
+ .selectAll(`.${$GRID[`${type}gridLine`]}`)
191
+ .data(config[`grid_${type}_lines`]);
190
192
 
191
193
  // exit
192
- $T(xLines.exit())
194
+ $T(lines.exit())
193
195
  .style("opacity", "0")
194
196
  .remove();
195
197
 
196
198
  // enter
197
- const xgridLine = xLines.enter().append("g");
199
+ const gridLine = lines.enter().append("g");
198
200
 
199
- xgridLine.append("line")
201
+ gridLine.append("line")
200
202
  .style("opacity", "0");
201
203
 
202
- xgridLine.append("text")
203
- .attr("transform", isRotated ? null : "rotate(-90)")
204
- .attr("dy", -5)
205
- .style("opacity", "0");
204
+ lines = gridLine.merge(lines);
206
205
 
207
- xLines = xgridLine.merge(xLines);
206
+ lines.each(function(d) {
207
+ const g = d3Select(this);
208
208
 
209
- $T(xLines
210
- .attr("class", d => `${$GRID.xgridLine} ${d.class || ""}`.trim())
209
+ if (g.select("text").empty() && d.text) {
210
+ g.append("text")
211
+ .style("opacity", "0");
212
+ }
213
+ });
214
+
215
+ $T(lines
216
+ .attr("class", d => `${$GRID[`${type}gridLine`]} ${d.class || ""}`.trim())
211
217
  .select("text")
212
218
  .attr("text-anchor", getGridTextAnchor)
219
+ .attr("transform", () => (isX ?
220
+ (isRotated ? null : "rotate(-90)") :
221
+ (isRotated ? "rotate(-90)" : null)
222
+ ))
213
223
  .attr("dx", getGridTextDx)
214
- )
215
- .text(d => d.text)
216
- .style("opacity", null);
217
-
218
- gridLines.x = xLines;
219
- },
220
-
221
- /**
222
- * Update Y Grid lines
223
- * @private
224
- */
225
- updateYGridLines(): void {
226
- const $$ = this;
227
- const {config, state: {width, height}, $el, $T} = $$;
228
- const isRotated = config.axis_rotated;
229
-
230
- config.grid_y_show && $$.updateYGrid();
231
-
232
- let ygridLines = $el.main.select(`.${$GRID.ygridLines}`)
233
- .selectAll(`.${$GRID.ygridLine}`)
234
- .data(config.grid_y_lines);
235
-
236
- // exit
237
- $T(ygridLines.exit())
238
- .style("opacity", "0")
239
- .remove();
240
-
241
- // enter
242
- const ygridLine = ygridLines.enter().append("g");
243
-
244
- ygridLine.append("line")
245
- .style("opacity", "0");
246
-
247
- ygridLine.append("text")
248
- .attr("transform", isRotated ? "rotate(-90)" : "")
249
- .style("opacity", "0");
250
-
251
- ygridLines = ygridLine.merge(ygridLines);
252
-
253
- // update
254
- const yv = $$.yv.bind($$);
255
-
256
- $T(ygridLines
257
- .attr("class", d => `${$GRID.ygridLine} ${d.class || ""}`.trim())
258
- .select("line"))
259
- .attr("x1", isRotated ? yv : 0)
260
- .attr("x2", isRotated ? yv : width)
261
- .attr("y1", isRotated ? 0 : yv)
262
- .attr("y2", isRotated ? height : yv)
263
- .style("opacity", null);
264
-
265
- $T(ygridLines.select("text")
266
- .attr("text-anchor", getGridTextAnchor)
267
- .attr("dx", getGridTextDx))
268
224
  .attr("dy", -5)
269
- .attr("x", getGridTextX(isRotated, width, height))
270
- .attr("y", yv)
271
- .text(d => d.text)
272
- .style("opacity", null);
225
+ )
226
+ .text(function(d) {
227
+ return d.text ?? this.remove();
228
+ });
273
229
 
274
- $el.gridLines.y = ygridLines;
230
+ gridLines[type] = lines;
275
231
  },
276
232
 
277
233
  redrawGrid(withTransition: boolean): any[] {
@@ -283,24 +239,39 @@ export default {
283
239
  $T
284
240
  } = $$;
285
241
  const xv = $$.xv.bind($$);
242
+ const yv = $$.yv.bind($$);
286
243
 
287
- let lines = gridLines.x.select("line");
288
- let texts = gridLines.x.select("text");
244
+ let xLines = gridLines.x.select("line");
245
+ let xTexts = gridLines.x.select("text");
289
246
 
290
- lines = $T(lines, withTransition)
247
+ let yLines = gridLines.y.select("line");
248
+ let yTexts = gridLines.y.select("text");
249
+
250
+ xLines = $T(xLines, withTransition)
291
251
  .attr("x1", isRotated ? 0 : xv)
292
252
  .attr("x2", isRotated ? width : xv)
293
253
  .attr("y1", isRotated ? xv : 0)
294
254
  .attr("y2", isRotated ? xv : height);
295
255
 
296
- texts = $T(texts, withTransition)
256
+ xTexts = $T(xTexts, withTransition)
297
257
  .attr("x", getGridTextX(!isRotated, width, height))
298
- .attr("y", xv)
299
- .text(d => d.text);
258
+ .attr("y", xv);
259
+
260
+ yLines = $T(yLines, withTransition)
261
+ .attr("x1", isRotated ? yv : 0)
262
+ .attr("x2", isRotated ? yv : width)
263
+ .attr("y1", isRotated ? 0 : yv)
264
+ .attr("y2", isRotated ? height : yv);
265
+
266
+ yTexts = $T(yTexts, withTransition)
267
+ .attr("x", getGridTextX(isRotated, width, height))
268
+ .attr("y", yv);
300
269
 
301
270
  return [
302
- lines.style("opacity", null),
303
- texts.style("opacity", null)
271
+ xLines.style("opacity", null),
272
+ xTexts.style("opacity", null),
273
+ yLines.style("opacity", null),
274
+ yTexts.style("opacity", null)
304
275
  ];
305
276
  },
306
277
 
@@ -503,5 +474,5 @@ export default {
503
474
  const gridLines = `grid_${forX ? "x" : "y"}_lines`;
504
475
 
505
476
  config[gridLines] = config[gridLines].filter(toShow);
506
- },
477
+ }
507
478
  };
@@ -35,11 +35,6 @@ export default {
35
35
  $$.updateDimension(true);
36
36
  }
37
37
 
38
- // update circleY based on updated parameters
39
- if (!treemap && (!$$.hasArcType() || state.hasRadar)) {
40
- $$.updateCircleY && ($$.circleY = $$.updateCircleY());
41
- }
42
-
43
38
  // Data empty label positioning and text.
44
39
  config.data_empty_label_text && main.select(`text.${$TEXT.text}.${$COMMON.empty}`)
45
40
  .attr("x", state.width / 2)
@@ -5,10 +5,10 @@
5
5
  import {select as d3Select} from "d3-selection"; // selection
6
6
  import {$REGION} from "../../config/classes";
7
7
  import {isValue, parseDate} from "../../module/util";
8
- import type {AxisType} from "../../../types/types";
8
+ import type {AxisType, RegionsType} from "../../../types/types";
9
9
 
10
10
  export default {
11
- initRegion() {
11
+ initRegion(): void {
12
12
  const $$ = this;
13
13
  const {$el} = $$;
14
14
 
@@ -38,7 +38,8 @@ export default {
38
38
  .style("opacity", "0")
39
39
  .remove();
40
40
 
41
- const regionsEnter = regions.enter()
41
+ const regionsEnter = regions
42
+ .enter()
42
43
  .append("g");
43
44
 
44
45
  regionsEnter
@@ -48,12 +49,22 @@ export default {
48
49
  region.list = regionsEnter
49
50
  .merge(regions)
50
51
  .attr("class", $$.classRegion.bind($$));
52
+
53
+ region.list.each(function(d) {
54
+ const g = d3Select(this);
55
+
56
+ if (g.select("text").empty() && d.label?.text) {
57
+ d3Select(this).append("text")
58
+ .style("opacity", "0");
59
+ }
60
+ });
51
61
  },
52
62
 
53
- redrawRegion(withTransition) {
63
+ redrawRegion(withTransition: boolean) {
54
64
  const $$ = this;
55
65
  const {$el: {region}, $T} = $$;
56
66
  let regions = region.list.select("rect");
67
+ let label = region.list.selectAll("text");
57
68
 
58
69
  regions = $T(regions, withTransition)
59
70
  .attr("x", $$.regionX.bind($$))
@@ -61,6 +72,17 @@ export default {
61
72
  .attr("width", $$.regionWidth.bind($$))
62
73
  .attr("height", $$.regionHeight.bind($$));
63
74
 
75
+ label = $T(label, withTransition)
76
+ .attr("transform", d => {
77
+ const {x = 0, y = 0, rotated = false} = d.label ?? {};
78
+
79
+ return `translate(${$$.regionX.bind($$)(d) + x}, ${$$.regionY.bind($$)(d) + y})${rotated ? ` rotate(-90)` : ``}`;
80
+ })
81
+ .attr("text-anchor", d => (d.label?.rotated ? "end" : null))
82
+ .attr("dy", "1em")
83
+ .style("fill", d => d.label?.color ?? null)
84
+ .text(d => d.label?.text);
85
+
64
86
  return [
65
87
  regions
66
88
  .style("fill-opacity", d => (isValue(d.opacity) ? d.opacity : null))
@@ -69,11 +91,12 @@ export default {
69
91
  d3Select(this.parentNode)
70
92
  .selectAll("rect:not([x])")
71
93
  .remove();
72
- })
94
+ }),
95
+ label.style("opacity", null)
73
96
  ];
74
97
  },
75
98
 
76
- getRegionXY(type: AxisType, d): number {
99
+ getRegionXY(type: AxisType, d: RegionsType): number {
77
100
  const $$ = this;
78
101
  const {config, scale} = $$;
79
102
  const isRotated = config.axis_rotated;
@@ -99,15 +122,15 @@ export default {
99
122
  return pos;
100
123
  },
101
124
 
102
- regionX(d): number {
125
+ regionX(d: RegionsType): number {
103
126
  return this.getRegionXY("x", d);
104
127
  },
105
128
 
106
- regionY(d): number {
129
+ regionY(d: RegionsType): number {
107
130
  return this.getRegionXY("y", d);
108
131
  },
109
132
 
110
- getRegionSize(type, d): number {
133
+ getRegionSize(type: "width" | "height", d: RegionsType): number {
111
134
  const $$ = this;
112
135
  const {config, scale, state} = $$;
113
136
  const isRotated = config.axis_rotated;
@@ -134,15 +157,15 @@ export default {
134
157
  return end < start ? 0 : end - start;
135
158
  },
136
159
 
137
- regionWidth(d): number {
160
+ regionWidth(d: RegionsType): number {
138
161
  return this.getRegionSize("width", d);
139
162
  },
140
163
 
141
- regionHeight(d): number {
164
+ regionHeight(d: RegionsType): number {
142
165
  return this.getRegionSize("height", d);
143
166
  },
144
167
 
145
- isRegionOnX(d): boolean {
168
+ isRegionOnX(d: RegionsType): boolean {
146
169
  return !d.axis || d.axis === "x";
147
170
  },
148
171
  };
@@ -291,9 +291,6 @@ export default {
291
291
  const anchorString = getRotateAnchor(angle);
292
292
  const rotateString = angle ? `rotate(${angle})` : "";
293
293
 
294
-
295
- // $$.meetsLabelThreshold(ratio,
296
-
297
294
  $$.$el.text
298
295
  .style("fill", $$.getStylePropValue($$.updateTextColor))
299
296
  .attr("filter", $$.updateTextBacgroundColor.bind($$))
@@ -452,7 +449,7 @@ export default {
452
449
  */
453
450
  getXForText(points, d: IDataRow, textElement): number {
454
451
  const $$ = this;
455
- const {config, state} = $$;
452
+ const {config} = $$;
456
453
  const isRotated = config.axis_rotated;
457
454
  const isTreemapType = $$.isTreemapType(d);
458
455
  let xPos = points[0][0];
@@ -484,17 +481,6 @@ export default {
484
481
  }
485
482
  }
486
483
 
487
- // show labels regardless of the domain if value is null
488
- if (d.value === null) {
489
- if (xPos > state.width) {
490
- const {width} = getBoundingRect(textElement);
491
-
492
- xPos = state.width - width;
493
- } else if (xPos < 0) {
494
- xPos = 4;
495
- }
496
- }
497
-
498
484
  if (isRotated || isTreemapType) {
499
485
  xPos += $$.getCenteredTextPos(d, points, textElement, "x");
500
486
  }
@@ -572,17 +558,6 @@ export default {
572
558
  }
573
559
  }
574
560
 
575
- // show labels regardless of the domain if value is null
576
- if (d.value === null && !isRotated) {
577
- const boxHeight = rect.height;
578
-
579
- if (yPos < boxHeight) {
580
- yPos = boxHeight;
581
- } else if (yPos > state.height) {
582
- yPos = state.height - 4;
583
- }
584
- }
585
-
586
561
  if (!isRotated || isTreemapType) {
587
562
  yPos += $$.getCenteredTextPos(d, points, textElement, "y");
588
563
  }