billboard.js 3.11.3 → 3.12.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.
- package/README.md +1 -5
- package/dist/billboard.css +5 -1
- package/dist/billboard.js +19433 -24307
- package/dist/billboard.min.css +2 -2
- package/dist/billboard.min.js +26 -3
- package/dist/billboard.pkgd.js +22302 -29071
- package/dist/billboard.pkgd.min.js +33 -3
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +77 -175
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -3
- package/dist/plugin/billboardjs-plugin-sparkline.js +423 -1134
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +4 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +660 -1524
- package/dist/plugin/billboardjs-plugin-stanford.min.js +15 -3
- package/dist/plugin/billboardjs-plugin-tableview.js +503 -1175
- package/dist/plugin/billboardjs-plugin-tableview.min.js +30 -3
- package/dist/plugin/billboardjs-plugin-textoverlap.js +351 -1055
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +4 -3
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +339 -1324
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +5 -3
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +1701 -3424
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +7 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +2385 -4462
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +18 -3
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +1783 -3467
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +33 -3
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +2031 -3979
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +7 -3
- package/dist/theme/dark.css +5 -1
- package/dist/theme/dark.min.css +2 -2
- package/dist/theme/datalab.css +5 -1
- package/dist/theme/datalab.min.css +2 -2
- package/dist/theme/graph.css +5 -1
- package/dist/theme/graph.min.css +2 -2
- package/dist/theme/insight.css +5 -1
- package/dist/theme/insight.min.css +2 -2
- package/dist/theme/modern.css +5 -1
- package/dist/theme/modern.min.css +3 -4
- package/dist-esm/billboard.js +9035 -8651
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +19 -25
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +149 -148
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +295 -286
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +235 -234
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +40 -41
- package/package.json +24 -44
- package/src/Chart/api/axis.ts +6 -13
- package/src/Chart/api/chart.ts +12 -11
- package/src/Chart/api/data.ts +8 -7
- package/src/Chart/api/export.ts +28 -21
- package/src/Chart/api/flow.ts +4 -2
- package/src/Chart/api/grid.ts +1 -5
- package/src/Chart/api/load.ts +2 -2
- package/src/Chart/api/regions.ts +29 -5
- package/src/Chart/api/selection.ts +2 -2
- package/src/Chart/api/show.ts +2 -3
- package/src/Chart/api/subchart.ts +2 -2
- package/src/Chart/api/tooltip.ts +5 -7
- package/src/Chart/api/x.ts +2 -2
- package/src/Chart/api/zoom.ts +2 -2
- package/src/ChartInternal/Axis/Axis.ts +119 -44
- package/src/ChartInternal/Axis/AxisRenderer.ts +53 -38
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +2 -2
- package/src/ChartInternal/ChartInternal.ts +79 -51
- package/src/ChartInternal/data/IData.ts +24 -31
- package/src/ChartInternal/data/convert.helper.ts +66 -68
- package/src/ChartInternal/data/convert.ts +11 -11
- package/src/ChartInternal/data/data.ts +40 -23
- package/src/ChartInternal/data/load.ts +7 -6
- package/src/ChartInternal/interactions/drag.ts +2 -1
- package/src/ChartInternal/interactions/eventrect.ts +54 -25
- package/src/ChartInternal/interactions/flow.ts +14 -4
- package/src/ChartInternal/interactions/interaction.ts +34 -12
- package/src/ChartInternal/interactions/subchart.ts +27 -25
- package/src/ChartInternal/interactions/zoom.ts +29 -18
- package/src/ChartInternal/internals/category.ts +1 -1
- package/src/ChartInternal/internals/class.ts +5 -5
- package/src/ChartInternal/internals/clip.ts +8 -4
- package/src/ChartInternal/internals/color.ts +70 -42
- package/src/ChartInternal/internals/domain.ts +59 -28
- package/src/ChartInternal/internals/format.ts +5 -5
- package/src/ChartInternal/internals/grid.ts +130 -47
- package/src/ChartInternal/internals/legend.ts +93 -61
- package/src/ChartInternal/internals/redraw.ts +3 -2
- package/src/ChartInternal/internals/region.ts +5 -3
- package/src/ChartInternal/internals/scale.ts +28 -15
- package/src/ChartInternal/internals/selection.ts +14 -13
- package/src/ChartInternal/internals/size.axis.ts +18 -10
- package/src/ChartInternal/internals/size.ts +97 -66
- package/src/ChartInternal/internals/style.ts +21 -19
- package/src/ChartInternal/internals/text.ts +64 -39
- package/src/ChartInternal/internals/title.ts +2 -2
- package/src/ChartInternal/internals/tooltip.ts +73 -28
- package/src/ChartInternal/internals/transform.ts +2 -2
- package/src/ChartInternal/internals/type.ts +12 -12
- package/src/ChartInternal/shape/arc.ts +78 -44
- package/src/ChartInternal/shape/area.ts +19 -22
- package/src/ChartInternal/shape/bar.ts +41 -31
- package/src/ChartInternal/shape/bubble.ts +5 -5
- package/src/ChartInternal/shape/candlestick.ts +15 -13
- package/src/ChartInternal/shape/gauge.ts +16 -9
- package/src/ChartInternal/shape/line.ts +62 -46
- package/src/ChartInternal/shape/point.common.ts +1 -4
- package/src/ChartInternal/shape/point.ts +52 -32
- package/src/ChartInternal/shape/polar.ts +4 -2
- package/src/ChartInternal/shape/radar.ts +40 -22
- package/src/ChartInternal/shape/shape.ts +84 -58
- package/src/ChartInternal/shape/treemap.ts +29 -20
- package/src/Plugin/bubblecompare/index.ts +1 -3
- package/src/Plugin/sparkline/index.ts +3 -4
- package/src/Plugin/stanford/ColorScale.ts +3 -2
- package/src/Plugin/stanford/Elements.ts +15 -6
- package/src/Plugin/stanford/Options.ts +5 -5
- package/src/Plugin/stanford/index.ts +13 -9
- package/src/Plugin/tableview/Options.ts +1 -1
- package/src/Plugin/tableview/const.ts +1 -4
- package/src/Plugin/tableview/index.ts +11 -9
- package/src/Plugin/textoverlap/index.ts +4 -6
- package/src/config/Options/Options.ts +3 -3
- package/src/config/Options/axis/axis.ts +36 -0
- package/src/config/Options/axis/x.ts +12 -13
- package/src/config/Options/axis/y.ts +13 -13
- package/src/config/Options/axis/y2.ts +23 -10
- package/src/config/Options/common/color.ts +4 -4
- package/src/config/Options/common/grid.ts +4 -4
- package/src/config/Options/common/legend.ts +12 -13
- package/src/config/Options/common/main.ts +23 -23
- package/src/config/Options/common/point.ts +17 -18
- package/src/config/Options/common/title.ts +2 -2
- package/src/config/Options/common/tooltip.ts +13 -11
- package/src/config/Options/data/axis.ts +2 -2
- package/src/config/Options/data/data.ts +45 -45
- package/src/config/Options/interaction/interaction.ts +1 -1
- package/src/config/Options/interaction/subchart.ts +2 -2
- package/src/config/Options/interaction/zoom.ts +9 -9
- package/src/config/Options/shape/arc.ts +10 -13
- package/src/config/Options/shape/area.ts +5 -7
- package/src/config/Options/shape/bar.ts +8 -10
- package/src/config/Options/shape/bubble.ts +1 -1
- package/src/config/Options/shape/candlestick.ts +2 -2
- package/src/config/Options/shape/donut.ts +4 -4
- package/src/config/Options/shape/gauge.ts +6 -6
- package/src/config/Options/shape/line.ts +3 -3
- package/src/config/Options/shape/pie.ts +5 -5
- package/src/config/Options/shape/polar.ts +3 -3
- package/src/config/Options/shape/radar.ts +2 -2
- package/src/config/Options/shape/scatter.ts +1 -1
- package/src/config/Options/shape/treemap.ts +1 -1
- package/src/config/Store/Element.ts +8 -5
- package/src/config/Store/State.ts +19 -13
- package/src/config/classes.ts +6 -4
- package/src/config/config.ts +1 -1
- package/src/config/resolver/axis.ts +4 -4
- package/src/config/resolver/interaction.ts +3 -7
- package/src/config/resolver/shape.ts +11 -12
- package/src/core.ts +2 -3
- package/src/index.esm.ts +2 -6
- package/src/index.ts +2 -2
- package/src/module/Cache.ts +2 -3
- package/src/module/browser.ts +15 -10
- package/src/module/error.ts +9 -8
- package/src/module/generator.ts +3 -5
- package/src/module/util.ts +60 -37
- package/src/module/worker.ts +14 -11
- package/src/scss/billboard.scss +6 -0
- package/src/scss/theme/dark.scss +6 -0
- package/src/scss/theme/datalab.scss +6 -0
- package/src/scss/theme/graph.scss +6 -0
- package/src/scss/theme/insight.scss +6 -0
- package/src/scss/theme/modern.scss +6 -0
- package/types/axis.d.ts +7 -0
- package/types/options.d.ts +7 -0
- package/types/options.shape.d.ts +7 -0
|
@@ -3,16 +3,29 @@
|
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
5
|
import {
|
|
6
|
-
axisTop as d3AxisTop,
|
|
7
6
|
axisBottom as d3AxisBottom,
|
|
8
7
|
axisLeft as d3AxisLeft,
|
|
9
|
-
axisRight as d3AxisRight
|
|
8
|
+
axisRight as d3AxisRight,
|
|
9
|
+
axisTop as d3AxisTop
|
|
10
10
|
} from "d3-axis";
|
|
11
|
-
import AxisRenderer from "./AxisRenderer";
|
|
12
|
-
import {getScale} from "../internals/scale";
|
|
13
|
-
import {$AXIS} from "../../config/classes";
|
|
14
|
-
import {capitalize, isArray, isFunction, isString, isValue, isEmpty, isNumber, isObjectType, mergeObj, notEmpty, parseDate, sortValue} from "../../module/util";
|
|
15
11
|
import type {AxisType} from "../../../types/types";
|
|
12
|
+
import {$AXIS} from "../../config/classes";
|
|
13
|
+
import {
|
|
14
|
+
capitalize,
|
|
15
|
+
isArray,
|
|
16
|
+
isEmpty,
|
|
17
|
+
isFunction,
|
|
18
|
+
isNumber,
|
|
19
|
+
isObjectType,
|
|
20
|
+
isString,
|
|
21
|
+
isValue,
|
|
22
|
+
mergeObj,
|
|
23
|
+
notEmpty,
|
|
24
|
+
parseDate,
|
|
25
|
+
sortValue
|
|
26
|
+
} from "../../module/util";
|
|
27
|
+
import {getScale} from "../internals/scale";
|
|
28
|
+
import AxisRenderer from "./AxisRenderer";
|
|
16
29
|
|
|
17
30
|
export default {
|
|
18
31
|
getAxisInstance: function() {
|
|
@@ -30,7 +43,9 @@ class Axis {
|
|
|
30
43
|
|
|
31
44
|
private axesList = {};
|
|
32
45
|
public tick = {
|
|
33
|
-
x: null,
|
|
46
|
+
x: null,
|
|
47
|
+
y: null,
|
|
48
|
+
y2: null
|
|
34
49
|
};
|
|
35
50
|
public xs = [];
|
|
36
51
|
private orient = {
|
|
@@ -128,6 +143,8 @@ class Axis {
|
|
|
128
143
|
|
|
129
144
|
this.generateAxes(v);
|
|
130
145
|
});
|
|
146
|
+
|
|
147
|
+
config.axis_tooltip && this.setAxisTooltip();
|
|
131
148
|
}
|
|
132
149
|
|
|
133
150
|
/**
|
|
@@ -182,7 +199,9 @@ class Axis {
|
|
|
182
199
|
axes.push(
|
|
183
200
|
d3Axis(scale)
|
|
184
201
|
.ticks(tick.count)
|
|
185
|
-
.tickFormat(
|
|
202
|
+
.tickFormat(
|
|
203
|
+
isFunction(tick.format) ? tick.format.bind($$.api) : ((x: any) => x)
|
|
204
|
+
)
|
|
186
205
|
.tickValues(tick.values)
|
|
187
206
|
.tickSizeOuter(tick.outer === false ? 0 : 6)
|
|
188
207
|
);
|
|
@@ -254,10 +273,11 @@ class Axis {
|
|
|
254
273
|
id,
|
|
255
274
|
scale,
|
|
256
275
|
outerTick,
|
|
257
|
-
|
|
258
276
|
// do not transit x Axis on zoom and resizing
|
|
259
277
|
// https://github.com/naver/billboard.js/issues/1949
|
|
260
|
-
id === "x" && ($$.scale.zoom || $$.config.subchart_show || $$.state.resizing) ?
|
|
278
|
+
id === "x" && ($$.scale.zoom || $$.config.subchart_show || $$.state.resizing) ?
|
|
279
|
+
true :
|
|
280
|
+
noTransition
|
|
261
281
|
);
|
|
262
282
|
}
|
|
263
283
|
|
|
@@ -386,7 +406,7 @@ class Axis {
|
|
|
386
406
|
return axis;
|
|
387
407
|
}
|
|
388
408
|
|
|
389
|
-
getXAxisTickFormat(forSubchart
|
|
409
|
+
getXAxisTickFormat(forSubchart?: boolean): Function {
|
|
390
410
|
const $$ = this.owner;
|
|
391
411
|
const {config, format} = $$;
|
|
392
412
|
// enable different tick format for x and subX - subX format defaults to x format if not defined
|
|
@@ -405,15 +425,13 @@ class Axis {
|
|
|
405
425
|
}
|
|
406
426
|
} else {
|
|
407
427
|
currFormat = isTimeSeries ? format.defaultAxisTime : (
|
|
408
|
-
isCategorized ?
|
|
409
|
-
$$.categoryName : v => (v < 0 ? v.toFixed(0) : v)
|
|
428
|
+
isCategorized ? $$.categoryName : v => (v < 0 ? v.toFixed(0) : v)
|
|
410
429
|
);
|
|
411
430
|
}
|
|
412
431
|
|
|
413
|
-
return isFunction(currFormat) ?
|
|
414
|
-
currFormat.apply($$, isCategorized ?
|
|
415
|
-
|
|
416
|
-
) : currFormat;
|
|
432
|
+
return isFunction(currFormat) ?
|
|
433
|
+
v => currFormat.apply($$, isCategorized ? [v, $$.categoryName(v)] : [v]) :
|
|
434
|
+
currFormat;
|
|
417
435
|
}
|
|
418
436
|
|
|
419
437
|
getTickValues(id: string) {
|
|
@@ -453,7 +471,8 @@ class Axis {
|
|
|
453
471
|
const isRotated = this.owner.config.axis_rotated;
|
|
454
472
|
const option = this.getLabelOptionByAxisId(id);
|
|
455
473
|
const position = (isObjectType(option) && option.position) ?
|
|
456
|
-
option.position :
|
|
474
|
+
option.position :
|
|
475
|
+
defaultPosition[+!isRotated];
|
|
457
476
|
|
|
458
477
|
const has = v => !!~position.indexOf(v);
|
|
459
478
|
|
|
@@ -470,7 +489,8 @@ class Axis {
|
|
|
470
489
|
}
|
|
471
490
|
|
|
472
491
|
getAxisLabelPosition(id: string) {
|
|
473
|
-
return this.getLabelPosition(id,
|
|
492
|
+
return this.getLabelPosition(id,
|
|
493
|
+
id === "x" ? ["inner-top", "inner-right"] : ["inner-right", "inner-top"]);
|
|
474
494
|
}
|
|
475
495
|
|
|
476
496
|
getLabelPositionById(id: string) {
|
|
@@ -564,12 +584,11 @@ class Axis {
|
|
|
564
584
|
dy = dy[2];
|
|
565
585
|
}
|
|
566
586
|
} else {
|
|
567
|
-
dy = isInner ?
|
|
568
|
-
dy[
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
) * (id === "y" ? -1 : 1);
|
|
587
|
+
dy = isInner ? dy[3] : (
|
|
588
|
+
dy[4] + (
|
|
589
|
+
config[`axis_${id}_inner`] ? 0 : (maxTickWidth + dy[4])
|
|
590
|
+
)
|
|
591
|
+
) * (id === "y" ? -1 : 1);
|
|
573
592
|
}
|
|
574
593
|
}
|
|
575
594
|
|
|
@@ -593,9 +612,11 @@ class Axis {
|
|
|
593
612
|
height: 0
|
|
594
613
|
};
|
|
595
614
|
|
|
596
|
-
if (
|
|
597
|
-
|
|
598
|
-
|
|
615
|
+
if (
|
|
616
|
+
withoutRecompute || !config[`${configPrefix}_show`] || (
|
|
617
|
+
currentTickMax.width > 0 && $$.filterTargetsToShow().length === 0
|
|
618
|
+
)
|
|
619
|
+
) {
|
|
599
620
|
return currentTickMax;
|
|
600
621
|
}
|
|
601
622
|
|
|
@@ -639,7 +660,8 @@ class Axis {
|
|
|
639
660
|
domain,
|
|
640
661
|
tickCount,
|
|
641
662
|
isYAxis ? this.isTimeSeriesY() : this.isTimeSeries()
|
|
642
|
-
)
|
|
663
|
+
)
|
|
664
|
+
);
|
|
643
665
|
}
|
|
644
666
|
|
|
645
667
|
!isYAxis && this.updateXAxisTickValues(targetsToShow, axis);
|
|
@@ -684,7 +706,8 @@ class Axis {
|
|
|
684
706
|
const xAxisTickRotate = $$.getAxisTickRotate("x");
|
|
685
707
|
const positiveRotation = xAxisTickRotate > 0 && xAxisTickRotate < 90;
|
|
686
708
|
|
|
687
|
-
if (
|
|
709
|
+
if (
|
|
710
|
+
(axis.isCategorized() || axis.isTimeSeries()) &&
|
|
688
711
|
config.axis_x_tick_fit &&
|
|
689
712
|
(!config.axis_x_tick_culling || isEmpty(config.axis_x_tick_culling)) &&
|
|
690
713
|
!config.axis_x_tick_multiline &&
|
|
@@ -692,9 +715,11 @@ class Axis {
|
|
|
692
715
|
) {
|
|
693
716
|
const y2AxisWidth = (config.axis_y2_show && current.maxTickSize.y2.width) || 0;
|
|
694
717
|
const legendWidth = (isLegendRight && legendItemWidth) || 0;
|
|
695
|
-
const widthWithoutCurrentPaddingLeft = current.width -
|
|
718
|
+
const widthWithoutCurrentPaddingLeft = current.width -
|
|
719
|
+
$$.getCurrentPaddingByDirection("left");
|
|
696
720
|
const maxOverflow = this.getXAxisTickMaxOverflow(
|
|
697
|
-
xAxisTickRotate,
|
|
721
|
+
xAxisTickRotate,
|
|
722
|
+
widthWithoutCurrentPaddingLeft - defaultPadding
|
|
698
723
|
) - y2AxisWidth - legendWidth;
|
|
699
724
|
const xAxisTickTextY2Overflow = Math.max(0, maxOverflow) +
|
|
700
725
|
defaultPadding; // for display inconsistencies between browsers
|
|
@@ -719,7 +744,8 @@ class Axis {
|
|
|
719
744
|
|
|
720
745
|
for (let i = 0; i < tickCount; i++) {
|
|
721
746
|
const tickIndex = i + 1;
|
|
722
|
-
const rotatedTickTextWidth = Math.cos(Math.PI * xAxisTickRotate / 180) *
|
|
747
|
+
const rotatedTickTextWidth = Math.cos(Math.PI * xAxisTickRotate / 180) *
|
|
748
|
+
tickTextWidths[i];
|
|
723
749
|
const ticksBeforeTickText = tickIndex - (isTimeSeries ? 1 : 0.5) + left;
|
|
724
750
|
|
|
725
751
|
// Skip ticks if there are no ticks before them
|
|
@@ -727,7 +753,8 @@ class Axis {
|
|
|
727
753
|
continue;
|
|
728
754
|
}
|
|
729
755
|
|
|
730
|
-
const xAxisLengthWithoutTickTextWidth = widthWithoutCurrentPaddingLeft -
|
|
756
|
+
const xAxisLengthWithoutTickTextWidth = widthWithoutCurrentPaddingLeft -
|
|
757
|
+
rotatedTickTextWidth;
|
|
731
758
|
const tickLength = xAxisLengthWithoutTickTextWidth / ticksBeforeTickText;
|
|
732
759
|
const remainingTicks = remaining - tickIndex;
|
|
733
760
|
|
|
@@ -745,13 +772,14 @@ class Axis {
|
|
|
745
772
|
!isTimeSeries &&
|
|
746
773
|
config.axis_x_tick_count <= filteredTargets.length && filteredTargets[0].values.length
|
|
747
774
|
) {
|
|
748
|
-
const scale = getScale($$.axis.getAxisType("x"), 0,
|
|
775
|
+
const scale = getScale($$.axis.getAxisType("x"), 0,
|
|
776
|
+
widthWithoutCurrentPaddingLeft - maxOverflow)
|
|
749
777
|
.domain([
|
|
750
778
|
left * -1,
|
|
751
779
|
$$.getXDomainMax($$.data.targets) + 1 + right
|
|
752
780
|
]);
|
|
753
781
|
|
|
754
|
-
tickOffset =
|
|
782
|
+
tickOffset = Math.ceil((scale(1) - scale(0)) / 2);
|
|
755
783
|
}
|
|
756
784
|
|
|
757
785
|
return maxOverflow + tickOffset;
|
|
@@ -789,8 +817,8 @@ class Axis {
|
|
|
789
817
|
* @returns {number} Padding value in scale
|
|
790
818
|
* @private
|
|
791
819
|
*/
|
|
792
|
-
getPadding(padding: number | {[key: string]: number},
|
|
793
|
-
|
|
820
|
+
getPadding(padding: number | {[key: string]: number}, key: string, defaultValue: number,
|
|
821
|
+
domainLength: number): number {
|
|
794
822
|
const p = isNumber(padding) ? padding : padding[key];
|
|
795
823
|
|
|
796
824
|
if (!isValue(p)) {
|
|
@@ -799,7 +827,8 @@ class Axis {
|
|
|
799
827
|
|
|
800
828
|
return this.owner.convertPixelToScale(
|
|
801
829
|
/(bottom|top)/.test(key) ? "y" : "x",
|
|
802
|
-
p,
|
|
830
|
+
p,
|
|
831
|
+
domainLength
|
|
803
832
|
);
|
|
804
833
|
}
|
|
805
834
|
|
|
@@ -899,7 +928,8 @@ class Axis {
|
|
|
899
928
|
|
|
900
929
|
if (scale.x && targetsToShow.length) {
|
|
901
930
|
!hasZoom &&
|
|
902
|
-
$$.updateXDomain(targetsToShow, wth.UpdateXDomain, wth.UpdateOrgXDomain,
|
|
931
|
+
$$.updateXDomain(targetsToShow, wth.UpdateXDomain, wth.UpdateOrgXDomain,
|
|
932
|
+
wth.TrimXDomain);
|
|
903
933
|
|
|
904
934
|
if (!config.axis_x_tick_values) {
|
|
905
935
|
this.updateXAxisTickValues(targetsToShow);
|
|
@@ -964,7 +994,6 @@ class Axis {
|
|
|
964
994
|
const $$ = this.owner;
|
|
965
995
|
const {config, state: {clip, current}, $el} = $$;
|
|
966
996
|
|
|
967
|
-
|
|
968
997
|
["subX", "x", "y", "y2"].forEach(type => {
|
|
969
998
|
const axis = $el.axis[type];
|
|
970
999
|
|
|
@@ -992,10 +1021,12 @@ class Axis {
|
|
|
992
1021
|
|
|
993
1022
|
tickNodes
|
|
994
1023
|
.each(function(d) {
|
|
995
|
-
const node =
|
|
1024
|
+
const node = lines ? this.querySelector("text") : this;
|
|
996
1025
|
|
|
997
1026
|
if (node) {
|
|
998
|
-
node.style.display = tickValues.indexOf(d) % intervalForCulling ?
|
|
1027
|
+
node.style.display = tickValues.indexOf(d) % intervalForCulling ?
|
|
1028
|
+
"none" :
|
|
1029
|
+
null;
|
|
999
1030
|
}
|
|
1000
1031
|
});
|
|
1001
1032
|
} else {
|
|
@@ -1004,7 +1035,9 @@ class Axis {
|
|
|
1004
1035
|
|
|
1005
1036
|
// set/unset x_axis_tick_clippath
|
|
1006
1037
|
if (type === "x") {
|
|
1007
|
-
const clipPath = current.maxTickSize.x.clipPath ?
|
|
1038
|
+
const clipPath = current.maxTickSize.x.clipPath ?
|
|
1039
|
+
clip.pathXAxisTickTexts :
|
|
1040
|
+
null;
|
|
1008
1041
|
|
|
1009
1042
|
$el.svg.selectAll(`.${$AXIS.axisX} .tick text`)
|
|
1010
1043
|
.attr("clip-path", clipPath);
|
|
@@ -1012,4 +1045,46 @@ class Axis {
|
|
|
1012
1045
|
}
|
|
1013
1046
|
});
|
|
1014
1047
|
}
|
|
1048
|
+
|
|
1049
|
+
/**
|
|
1050
|
+
* Set axis tooltip
|
|
1051
|
+
* @private
|
|
1052
|
+
*/
|
|
1053
|
+
setAxisTooltip(): void {
|
|
1054
|
+
const $$ = this.owner;
|
|
1055
|
+
const {config: {axis_rotated: isRotated, axis_tooltip}, $el: {axis, axisTooltip}} = $$;
|
|
1056
|
+
const bgColor = axis_tooltip.backgroundColor ?? "black";
|
|
1057
|
+
|
|
1058
|
+
$$.generateTextBGColorFilter(
|
|
1059
|
+
bgColor,
|
|
1060
|
+
{
|
|
1061
|
+
x: -0.15,
|
|
1062
|
+
y: -0.2,
|
|
1063
|
+
width: 1.3,
|
|
1064
|
+
height: 1.3
|
|
1065
|
+
}
|
|
1066
|
+
);
|
|
1067
|
+
|
|
1068
|
+
["x", "y", "y2"].forEach(v => {
|
|
1069
|
+
axisTooltip[v] = axis[v]?.append("text")
|
|
1070
|
+
.classed($AXIS[`axis${v.toUpperCase()}Tooltip`], true)
|
|
1071
|
+
.attr("filter", $$.updateTextBGColor({id: v}, bgColor));
|
|
1072
|
+
|
|
1073
|
+
if (isRotated) {
|
|
1074
|
+
const pos = v === "x" ? "x" : "y";
|
|
1075
|
+
const val = v === "y" ? "1.15em" : (v === "x" ? "-0.3em" : "-0.4em");
|
|
1076
|
+
|
|
1077
|
+
axisTooltip[v]?.attr(pos, val)
|
|
1078
|
+
.attr(`d${v === "x" ? "y" : "x"}`, v === "x" ? "0.4em" : "-1.3em")
|
|
1079
|
+
.style("text-anchor", v === "x" ? "end" : null);
|
|
1080
|
+
} else {
|
|
1081
|
+
const pos = v === "x" ? "y" : "x";
|
|
1082
|
+
const val = v === "x" ? "1.15em" : `${v === "y" ? "-" : ""}0.4em`;
|
|
1083
|
+
|
|
1084
|
+
axisTooltip[v]?.attr(pos, val)
|
|
1085
|
+
.attr(`d${v === "x" ? "x" : "y"}`, v === "x" ? "-1em" : "0.3em")
|
|
1086
|
+
.style("text-anchor", v === "y" ? "end" : null);
|
|
1087
|
+
}
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1015
1090
|
}
|
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import {select as d3Select} from "d3-selection";
|
|
7
7
|
import type {d3Selection} from "../../../types/types";
|
|
8
|
+
import {isArray, isFunction, isNumber, isString, toArray} from "../../module/util";
|
|
8
9
|
import Helper from "./AxisRendererHelper";
|
|
9
|
-
import {isArray, toArray, isFunction, isString, isNumber} from "../../module/util";
|
|
10
10
|
|
|
11
11
|
export default class AxisRenderer {
|
|
12
12
|
private helper;
|
|
13
13
|
private config;
|
|
14
14
|
private params;
|
|
15
15
|
private g;
|
|
16
|
-
private generatedTicks: (Date|number)[];
|
|
16
|
+
private generatedTicks: (Date | number)[];
|
|
17
17
|
|
|
18
18
|
constructor(params: any = {}) {
|
|
19
19
|
const config = {
|
|
@@ -71,7 +71,8 @@ export default class AxisRenderer {
|
|
|
71
71
|
// // get the axis' tick position configuration
|
|
72
72
|
const id = params.id;
|
|
73
73
|
const tickTextPos = id && /^(x|y|y2)$/.test(id) ?
|
|
74
|
-
params.config[`axis_${id}_tick_text_position`] :
|
|
74
|
+
params.config[`axis_${id}_tick_text_position`] :
|
|
75
|
+
{x: 0, y: 0};
|
|
75
76
|
|
|
76
77
|
// tick visiblity
|
|
77
78
|
const prefix = id === "subX" ? `subchart_axis_x` : `axis_${id}`;
|
|
@@ -91,8 +92,7 @@ export default class AxisRenderer {
|
|
|
91
92
|
$g = g;
|
|
92
93
|
this.__chart__ = scale1;
|
|
93
94
|
|
|
94
|
-
config.tickOffset = params.isCategory ?
|
|
95
|
-
Math.ceil((scale1(1) - scale1(0)) / 2) : 0;
|
|
95
|
+
config.tickOffset = params.isCategory ? Math.ceil((scale1(1) - scale1(0)) / 2) : 0;
|
|
96
96
|
|
|
97
97
|
// update selection - data join
|
|
98
98
|
const path = g.selectAll(".domain").data([0]);
|
|
@@ -143,9 +143,11 @@ export default class AxisRenderer {
|
|
|
143
143
|
.selectAll("tspan")
|
|
144
144
|
.data((d, index) => {
|
|
145
145
|
const split = params.tickMultiline ?
|
|
146
|
-
splitTickText(d, scale1, ticks, isLeftRight, sizeFor1Char.w) :
|
|
146
|
+
splitTickText(d, scale1, ticks, isLeftRight, sizeFor1Char.w) :
|
|
147
|
+
(
|
|
147
148
|
isArray(helper.textFormatted(d)) ?
|
|
148
|
-
helper.textFormatted(d).concat() :
|
|
149
|
+
helper.textFormatted(d).concat() :
|
|
150
|
+
[helper.textFormatted(d)]
|
|
149
151
|
);
|
|
150
152
|
|
|
151
153
|
counts[index] = split.length;
|
|
@@ -168,7 +170,8 @@ export default class AxisRenderer {
|
|
|
168
170
|
let dx = 0;
|
|
169
171
|
|
|
170
172
|
if (/(top|bottom)/.test(orient) && rotate) {
|
|
171
|
-
dx = 8 * Math.sin(Math.PI * (rotate / 180)) *
|
|
173
|
+
dx = 8 * Math.sin(Math.PI * (rotate / 180)) *
|
|
174
|
+
(orient === "top" ? -1 : 1);
|
|
172
175
|
}
|
|
173
176
|
|
|
174
177
|
return dx + (tickTextPos.x || 0);
|
|
@@ -181,13 +184,13 @@ export default class AxisRenderer {
|
|
|
181
184
|
dy = sizeFor1Char.h;
|
|
182
185
|
|
|
183
186
|
if (i === 0) {
|
|
184
|
-
dy = isLeftRight ?
|
|
187
|
+
dy = isLeftRight ?
|
|
188
|
+
-((counts[d.index] - 1) * (sizeFor1Char.h / 2) - 3) :
|
|
185
189
|
(tickTextPos.y === 0 ? defValue : 0);
|
|
186
190
|
}
|
|
187
191
|
}
|
|
188
192
|
|
|
189
|
-
return isNumber(dy) && tickTextPos.y ?
|
|
190
|
-
dy + tickTextPos.y : dy || defValue;
|
|
193
|
+
return isNumber(dy) && tickTextPos.y ? dy + tickTextPos.y : dy || defValue;
|
|
191
194
|
});
|
|
192
195
|
|
|
193
196
|
const lineUpdate = tick.select("line");
|
|
@@ -238,7 +241,7 @@ export default class AxisRenderer {
|
|
|
238
241
|
* @returns {Array} Generated ticks
|
|
239
242
|
* @private
|
|
240
243
|
*/
|
|
241
|
-
getGeneratedTicks(count: number): (Date|number)[] {
|
|
244
|
+
getGeneratedTicks(count: number): (Date | number)[] {
|
|
242
245
|
const len = this.generatedTicks?.length - 1;
|
|
243
246
|
let res = this.generatedTicks;
|
|
244
247
|
|
|
@@ -248,7 +251,7 @@ export default class AxisRenderer {
|
|
|
248
251
|
res = this.generatedTicks
|
|
249
252
|
.map((v, i) => (i % interval === 0 ? v : null))
|
|
250
253
|
.filter(v => v !== null)
|
|
251
|
-
.splice(0, count) as (Date|number)[];
|
|
254
|
+
.splice(0, count) as (Date | number)[];
|
|
252
255
|
}
|
|
253
256
|
|
|
254
257
|
return res;
|
|
@@ -313,10 +316,12 @@ export default class AxisRenderer {
|
|
|
313
316
|
return r ? 11.5 - 2.5 * r2 * (r > 0 ? 1 : -1) : tickLength;
|
|
314
317
|
};
|
|
315
318
|
|
|
316
|
-
const {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
319
|
+
const {
|
|
320
|
+
config: {
|
|
321
|
+
axis_rotated: isRotated,
|
|
322
|
+
axis_x_tick_text_inner: inner
|
|
323
|
+
}
|
|
324
|
+
} = this.params.owner;
|
|
320
325
|
|
|
321
326
|
switch (orient) {
|
|
322
327
|
case "bottom":
|
|
@@ -332,7 +337,9 @@ export default class AxisRenderer {
|
|
|
332
337
|
.style("text-anchor", (d, i, {length}) => {
|
|
333
338
|
if (!isRotated && i === 0 && (inner === true || inner.first)) {
|
|
334
339
|
return "start";
|
|
335
|
-
} else if (
|
|
340
|
+
} else if (
|
|
341
|
+
!isRotated && i === length - 1 && (inner === true || inner.last)
|
|
342
|
+
) {
|
|
336
343
|
return "end";
|
|
337
344
|
}
|
|
338
345
|
|
|
@@ -379,7 +386,8 @@ export default class AxisRenderer {
|
|
|
379
386
|
const {params} = this;
|
|
380
387
|
const tickText = this.helper.textFormatted(d);
|
|
381
388
|
const splitted = isString(tickText) && tickText.indexOf("\n") > -1 ?
|
|
382
|
-
tickText.split("\n") :
|
|
389
|
+
tickText.split("\n") :
|
|
390
|
+
[];
|
|
383
391
|
|
|
384
392
|
if (splitted.length) {
|
|
385
393
|
return splitted;
|
|
@@ -393,13 +401,15 @@ export default class AxisRenderer {
|
|
|
393
401
|
|
|
394
402
|
if (!tickWidth || tickWidth <= 0) {
|
|
395
403
|
tickWidth = isLeftRight ? 95 : (
|
|
396
|
-
params.isCategory ?
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
404
|
+
params.isCategory ?
|
|
405
|
+
(
|
|
406
|
+
Math.ceil(
|
|
407
|
+
params.isInverted ?
|
|
408
|
+
scale(ticks[0]) - scale(ticks[1]) :
|
|
409
|
+
scale(ticks[1]) - scale(ticks[0])
|
|
410
|
+
) - 12
|
|
411
|
+
) :
|
|
412
|
+
110
|
|
403
413
|
);
|
|
404
414
|
}
|
|
405
415
|
|
|
@@ -449,11 +459,13 @@ export default class AxisRenderer {
|
|
|
449
459
|
}
|
|
450
460
|
|
|
451
461
|
this.config.orient = x in {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
462
|
+
top: 1,
|
|
463
|
+
right: 1,
|
|
464
|
+
bottom: 1,
|
|
465
|
+
left: 1
|
|
466
|
+
} ?
|
|
467
|
+
String(x) :
|
|
468
|
+
"bottom";
|
|
457
469
|
|
|
458
470
|
return this;
|
|
459
471
|
}
|
|
@@ -513,13 +525,14 @@ export default class AxisRenderer {
|
|
|
513
525
|
interval = length / (size || this.g.selectAll("line").size());
|
|
514
526
|
|
|
515
527
|
// get the interval by its values
|
|
516
|
-
const intervalByValue = tickValues ?
|
|
517
|
-
|
|
518
|
-
|
|
528
|
+
const intervalByValue = tickValues ?
|
|
529
|
+
tickValues
|
|
530
|
+
.map((v, i, arr) => {
|
|
531
|
+
const next = i + 1;
|
|
519
532
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
533
|
+
return next < arr.length ? scale(arr[next]) - scale(v) : null;
|
|
534
|
+
}).filter(Boolean) :
|
|
535
|
+
[];
|
|
523
536
|
|
|
524
537
|
interval = Math.min(...intervalByValue, interval);
|
|
525
538
|
}
|
|
@@ -551,7 +564,9 @@ export default class AxisRenderer {
|
|
|
551
564
|
return this;
|
|
552
565
|
}
|
|
553
566
|
|
|
554
|
-
tickValues(
|
|
567
|
+
tickValues(
|
|
568
|
+
x?: (number | Date | string)[] | Function
|
|
569
|
+
): AxisRenderer | (number | Date | string)[] {
|
|
555
570
|
const {config} = this;
|
|
556
571
|
|
|
557
572
|
if (isFunction(x)) {
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
* @ignore
|
|
5
5
|
*/
|
|
6
|
-
import {getScale} from "../internals/scale";
|
|
7
|
-
import {isDefined, isNumber, isString, isValue} from "../../module/util";
|
|
8
6
|
import type {d3Selection} from "../../../types/types";
|
|
7
|
+
import {isDefined, isNumber, isString, isValue} from "../../module/util";
|
|
8
|
+
import {getScale} from "../internals/scale";
|
|
9
9
|
|
|
10
10
|
export default class AxisRendererHelper {
|
|
11
11
|
private owner;
|