billboard.js 3.7.4 → 3.8.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/dist/billboard.css +1 -1
- package/dist/billboard.js +420 -256
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +2 -2
- package/dist/billboard.pkgd.js +2115 -1544
- package/dist/billboard.pkgd.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +22 -19
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.js +22 -19
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +22 -19
- package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.js +22 -19
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +1696 -1289
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +1717 -1307
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +1718 -1308
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +1719 -1309
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +1752 -1325
- package/dist/theme/datalab.css +1 -1
- package/dist/theme/datalab.min.css +1 -1
- package/dist/theme/graph.css +1 -1
- package/dist/theme/graph.min.css +1 -1
- package/dist/theme/insight.css +1 -1
- package/dist/theme/insight.min.css +1 -1
- package/dist-esm/billboard.js +359 -211
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +4 -9
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +6 -11
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +7 -12
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -7
- package/package.json +33 -33
- package/src/Chart/api/focus.ts +4 -4
- package/src/Chart/api/grid.ts +206 -0
- package/src/Chart/api/load.ts +31 -21
- package/src/Chart/api/regions.ts +28 -24
- package/src/Chart/api/zoom.ts +18 -3
- package/src/ChartInternal/Axis/Axis.ts +1 -0
- package/src/ChartInternal/Axis/AxisRenderer.ts +7 -2
- package/src/ChartInternal/ChartInternal.ts +1 -1
- package/src/ChartInternal/data/IData.ts +1 -1
- package/src/ChartInternal/data/convert.ts +6 -3
- package/src/ChartInternal/data/data.ts +22 -19
- package/src/ChartInternal/data/load.ts +19 -4
- package/src/ChartInternal/interactions/eventrect.ts +5 -0
- package/src/ChartInternal/interactions/subchart.ts +3 -2
- package/src/ChartInternal/interactions/zoom.ts +10 -3
- package/src/ChartInternal/internals/clip.ts +3 -2
- package/src/ChartInternal/internals/domain.ts +17 -8
- package/src/ChartInternal/internals/legend.ts +4 -1
- package/src/ChartInternal/internals/redraw.ts +0 -16
- package/src/ChartInternal/internals/scale.ts +7 -4
- package/src/ChartInternal/internals/size.axis.ts +14 -4
- package/src/ChartInternal/internals/size.ts +41 -18
- package/src/ChartInternal/internals/transform.ts +1 -1
- package/src/ChartInternal/internals/type.ts +10 -0
- package/src/ChartInternal/shape/bar.ts +2 -3
- package/src/config/Options/axis/x.ts +17 -0
- package/src/config/Options/axis/y.ts +2 -1
- package/src/config/Options/axis/y2.ts +2 -1
- package/src/config/Options/common/main.ts +19 -1
- package/src/config/Options/data/axis.ts +10 -1
- package/src/config/resolver/axis.ts +2 -4
- package/src/module/browser.ts +13 -5
- package/src/module/generator.ts +3 -3
- package/src/module/util.ts +7 -4
- package/types/axis.d.ts +8 -7
- package/types/chart.d.ts +6 -1
- package/types/options.d.ts +6 -0
- package/src/Chart/api/grid.x.ts +0 -90
- package/src/Chart/api/grid.y.ts +0 -92
|
@@ -50,7 +50,7 @@ export default {
|
|
|
50
50
|
const $$ = this;
|
|
51
51
|
const scale = $$.scale.zoom || getScale($$.axis.getAxisType("x"), min, max);
|
|
52
52
|
|
|
53
|
-
return $$.
|
|
53
|
+
return $$.getCustomizedXScale(
|
|
54
54
|
domain ? scale.domain(domain) : scale,
|
|
55
55
|
offset
|
|
56
56
|
);
|
|
@@ -89,15 +89,16 @@ export default {
|
|
|
89
89
|
},
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
|
-
* Get customized scale
|
|
92
|
+
* Get customized x axis scale
|
|
93
93
|
* @param {d3.scaleLinear|d3.scaleTime} scaleValue Scale function
|
|
94
94
|
* @param {Function} offsetValue Offset getter to be sum
|
|
95
95
|
* @returns {Function} Scale function
|
|
96
96
|
* @private
|
|
97
97
|
*/
|
|
98
|
-
|
|
98
|
+
getCustomizedXScale(scaleValue: Function | any, offsetValue): Function {
|
|
99
99
|
const $$ = this;
|
|
100
100
|
const offset = offsetValue || (() => $$.axis.x.tickOffset());
|
|
101
|
+
const isInverted = $$.config.axis_x_inverted;
|
|
101
102
|
const scale = function(d, raw) {
|
|
102
103
|
const v = scaleValue(d) + offset();
|
|
103
104
|
|
|
@@ -120,7 +121,9 @@ export default {
|
|
|
120
121
|
if (!arguments.length) {
|
|
121
122
|
domain = this.orgDomain();
|
|
122
123
|
|
|
123
|
-
return
|
|
124
|
+
return isInverted ?
|
|
125
|
+
[domain[0] + 1, domain[1]] :
|
|
126
|
+
[domain[0], domain[1] + 1];
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
scaleValue.domain(domain);
|
|
@@ -29,7 +29,9 @@ export default {
|
|
|
29
29
|
const gap = width === 0 ? 0.5 : 0;
|
|
30
30
|
|
|
31
31
|
return width + (
|
|
32
|
-
|
|
32
|
+
$$.config.padding?.mode === "fit" ?
|
|
33
|
+
position.isInner ? (10 + gap) : 10 :
|
|
34
|
+
position.isInner ? (20 + gap) : 40
|
|
33
35
|
);
|
|
34
36
|
} else {
|
|
35
37
|
return 40;
|
|
@@ -41,7 +43,10 @@ export default {
|
|
|
41
43
|
const {config, state} = $$;
|
|
42
44
|
const {current, rotatedPadding, isLegendRight, isLegendInset} = state;
|
|
43
45
|
const isRotated = config.axis_rotated;
|
|
44
|
-
|
|
46
|
+
const isFitPadding = config.padding?.mode === "fit";
|
|
47
|
+
const isInner = config[`axis_${id}_inner`];
|
|
48
|
+
const hasLabelText = config[`axis_${id}_label`].text;
|
|
49
|
+
let h = config.padding?.mode === "fit" ? (isInner && !hasLabelText ? (id === "y" ? 1 : 0) : 20) : 30;
|
|
45
50
|
|
|
46
51
|
if (id === "x" && !config.axis_x_show) {
|
|
47
52
|
return 8;
|
|
@@ -58,7 +63,7 @@ export default {
|
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
if (id === "y2" && !config.axis_y2_show) {
|
|
61
|
-
return rotatedPadding.top;
|
|
66
|
+
return isFitPadding ? 0 : rotatedPadding.top;
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
const rotate = $$.getAxisTickRotate(id);
|
|
@@ -84,7 +89,12 @@ export default {
|
|
|
84
89
|
},
|
|
85
90
|
|
|
86
91
|
getEventRectWidth(): number {
|
|
87
|
-
|
|
92
|
+
const $$ = this;
|
|
93
|
+
const {config, axis} = $$;
|
|
94
|
+
const isInverted = config.axis_x_inverted;
|
|
95
|
+
const tickInterval = axis.x.tickInterval();
|
|
96
|
+
|
|
97
|
+
return Math.max(0, isInverted ? Math.abs(tickInterval) : tickInterval);
|
|
88
98
|
},
|
|
89
99
|
|
|
90
100
|
/**
|
|
@@ -69,20 +69,26 @@ export default {
|
|
|
69
69
|
const $$ = this;
|
|
70
70
|
const {config, state: {hasAxis}} = $$;
|
|
71
71
|
const isRotated = config.axis_rotated;
|
|
72
|
+
const isFitPadding = config.padding?.mode === "fit";
|
|
72
73
|
const axisId = isRotated ? "x" : "y";
|
|
73
74
|
const axesLen = hasAxis ? config[`axis_${axisId}_axes`].length : 0;
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
let axisWidth = hasAxis ? $$.getAxisWidthByAxisId(axisId, withoutRecompute) : 0;
|
|
76
|
+
|
|
77
|
+
if (!isFitPadding) {
|
|
78
|
+
axisWidth = ceil10(axisWidth);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let padding = config[`axis_${axisId}_inner`] || !config[`axis_${axisId}_show`] ? 0 : axisWidth;
|
|
76
82
|
|
|
77
83
|
if (isValue(config.padding_left)) {
|
|
78
|
-
padding = config.padding_left;
|
|
84
|
+
padding = config.padding_left + (isFitPadding && isRotated ? axisWidth : 0);
|
|
79
85
|
} else if (hasAxis && isRotated) {
|
|
80
86
|
padding = !config.axis_x_show ?
|
|
81
|
-
1 : Math.max(
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
padding
|
|
87
|
+
1 : (isFitPadding ? axisWidth : Math.max(axisWidth, 40));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (hasAxis && (isFitPadding || config[`axis_${axisId}_inner`]) && config[`axis_${axisId}_label`].text) {
|
|
91
|
+
padding += $$.axis.getAxisLabelPosition("y").isOuter ? 20 : 0;
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
return padding + (axisWidth * axesLen);
|
|
@@ -91,25 +97,41 @@ export default {
|
|
|
91
97
|
getCurrentPaddingRight(withXAxisTickTextOverflow = false): number {
|
|
92
98
|
const $$ = this;
|
|
93
99
|
const {config, state: {hasAxis}} = $$;
|
|
94
|
-
const
|
|
100
|
+
const isRotated = config.axis_rotated;
|
|
101
|
+
const isFitPadding = config.padding?.mode === "fit";
|
|
102
|
+
const defaultPadding = isFitPadding ? 2 : 10;
|
|
95
103
|
const legendWidthOnRight = $$.state.isLegendRight ? $$.getLegendWidth() + 20 : 0;
|
|
96
104
|
const axesLen = hasAxis ? config.axis_y2_axes.length : 0;
|
|
97
|
-
const
|
|
105
|
+
const axisLabelWidth = $$.axis?.getAxisLabelPosition("y2").isOuter ? 20 : 0;
|
|
98
106
|
const xAxisTickTextOverflow = withXAxisTickTextOverflow ?
|
|
99
107
|
$$.axis.getXAxisTickTextY2Overflow(defaultPadding) : 0;
|
|
100
|
-
let
|
|
108
|
+
let axisWidth = hasAxis && !config.axis_y2_inner ? $$.getAxisWidthByAxisId("y2") : 1;
|
|
109
|
+
|
|
110
|
+
if (!isFitPadding) {
|
|
111
|
+
axisWidth = ceil10(axisWidth);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let padding = isRotated ? 0 : Math.max(axisWidth + legendWidthOnRight, xAxisTickTextOverflow);
|
|
101
115
|
|
|
102
116
|
if (isValue(config.padding_right)) {
|
|
103
|
-
padding = config.padding_right + (hasAxis ? 1 : 0); // 1 is needed not to hide tick line
|
|
104
|
-
|
|
117
|
+
// padding = config.padding_right + (hasAxis ? 1 : 0); // 1 is needed not to hide tick line
|
|
118
|
+
|
|
119
|
+
padding = config.padding_right +
|
|
120
|
+
(isFitPadding && (isRotated || !config.axis_y2_show ? defaultPadding : padding)) +
|
|
121
|
+
(hasAxis && !isFitPadding ? 1 : 0); // 1 is needed not to hide tick line
|
|
122
|
+
} else if ($$.axis && isRotated) {
|
|
105
123
|
padding = defaultPadding + legendWidthOnRight;
|
|
106
|
-
} else if ($$.axis && (!config.axis_y2_show || config.axis_y2_inner)) {
|
|
124
|
+
} else if ($$.axis && (!config.axis_y2_show || config.axis_y2_inner)) {
|
|
107
125
|
padding = Math.max(
|
|
108
|
-
|
|
126
|
+
(isFitPadding && !config.axis_y2_show ? 2 : 1) + legendWidthOnRight + axisLabelWidth,
|
|
109
127
|
xAxisTickTextOverflow
|
|
110
128
|
);
|
|
111
|
-
}
|
|
112
|
-
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (hasAxis && !isRotated && isFitPadding &&
|
|
132
|
+
config.axis_y2_show && !config.axis_y2_inner && config.axis_y2_label.text
|
|
133
|
+
) {
|
|
134
|
+
padding += axisLabelWidth;
|
|
113
135
|
}
|
|
114
136
|
|
|
115
137
|
return padding + (axisWidth * axesLen);
|
|
@@ -282,6 +304,7 @@ export default {
|
|
|
282
304
|
const {config, state, $el: {legend}} = $$;
|
|
283
305
|
const isRotated = config.axis_rotated;
|
|
284
306
|
const isNonAxis = $$.hasArcType() || state.hasTreemap;
|
|
307
|
+
const isFitPadding = config.padding?.mode === "fit";
|
|
285
308
|
|
|
286
309
|
!isInit && $$.setContainerSize();
|
|
287
310
|
|
|
@@ -311,7 +334,7 @@ export default {
|
|
|
311
334
|
bottom: $$.getHorizontalAxisHeight("y") + legendHeightForBottom + padding.bottom,
|
|
312
335
|
left: subchartHeight + (isNonAxis ? 0 : padding.left)
|
|
313
336
|
} : {
|
|
314
|
-
top: 4 + padding.top, // for top tick text
|
|
337
|
+
top: (isFitPadding ? 0 : 4) + padding.top, // for top tick text
|
|
315
338
|
right: isNonAxis ? 0 : $$.getCurrentPaddingRight(true),
|
|
316
339
|
bottom: xAxisHeight + subchartHeight + legendHeightForBottom + padding.bottom,
|
|
317
340
|
left: isNonAxis ? 0 : padding.left
|
|
@@ -37,7 +37,7 @@ export default {
|
|
|
37
37
|
y = isRotated ? state.height + padding : 0;
|
|
38
38
|
} else if (target === "y2") {
|
|
39
39
|
x = isRotated ? 0 : state.width + padding;
|
|
40
|
-
y = isRotated ? 1 - padding : 0;
|
|
40
|
+
y = isRotated && padding ? 1 - padding : 0;
|
|
41
41
|
} else if (target === "subX") {
|
|
42
42
|
x = 0;
|
|
43
43
|
y = isRotated ? 0 : state.height2;
|
|
@@ -6,6 +6,16 @@ import {isArray, isNumber, isString} from "../../module/util";
|
|
|
6
6
|
import {TYPE, TYPE_BY_CATEGORY} from "../../config/const";
|
|
7
7
|
|
|
8
8
|
export default {
|
|
9
|
+
/**
|
|
10
|
+
* Check if the given chart type is valid
|
|
11
|
+
* @param {string} type Chart type string
|
|
12
|
+
* @returns {boolean}
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
isValidChartType(type: string): boolean {
|
|
16
|
+
return !!(type && Object.values(TYPE).indexOf(type) > -1);
|
|
17
|
+
},
|
|
18
|
+
|
|
9
19
|
setTargetType(targetIds: string[], type: string): void {
|
|
10
20
|
const $$ = this;
|
|
11
21
|
const {config, state: {withoutFadeIn}} = $$;
|
|
@@ -180,14 +180,13 @@ export default {
|
|
|
180
180
|
let radius = 0;
|
|
181
181
|
|
|
182
182
|
const isGrouped = $$.isGrouped(d.id);
|
|
183
|
-
// const hasRadius = d.value !== 0 && getRadius;
|
|
184
183
|
const isRadiusData = getRadius && isGrouped ? $$.isStackingRadiusData(d) : false;
|
|
185
184
|
|
|
186
|
-
if (getRadius
|
|
185
|
+
if (getRadius) {
|
|
187
186
|
const index = isRotated ? indexY : indexX;
|
|
188
187
|
const barW = points[2][index] - points[0][index];
|
|
189
188
|
|
|
190
|
-
radius = getRadius(barW);
|
|
189
|
+
radius = !isGrouped || isRadiusData ? getRadius(barW) : 0;
|
|
191
190
|
|
|
192
191
|
const arc = `a${radius},${radius} ${isNegative ? `1 0 0` : `0 0 1`} `;
|
|
193
192
|
|
|
@@ -510,6 +510,23 @@ export default {
|
|
|
510
510
|
*/
|
|
511
511
|
axis_x_min: <number|undefined> undefined,
|
|
512
512
|
|
|
513
|
+
/**
|
|
514
|
+
* Change the direction of x axis.<br><br>
|
|
515
|
+
* If true set, the direction will be `right -> left`.
|
|
516
|
+
* @name axis․x․inverted
|
|
517
|
+
* @memberof Options
|
|
518
|
+
* @type {boolean}
|
|
519
|
+
* @default false
|
|
520
|
+
* @see [Demo](https://naver.github.io/billboard.js/demo/#Axis.InvertedAxis)
|
|
521
|
+
* @example
|
|
522
|
+
* axis: {
|
|
523
|
+
* x: {
|
|
524
|
+
* inverted: true
|
|
525
|
+
* }
|
|
526
|
+
* }
|
|
527
|
+
*/
|
|
528
|
+
axis_x_inverted: false,
|
|
529
|
+
|
|
513
530
|
/**
|
|
514
531
|
* Set padding for x axis.<br><br>
|
|
515
532
|
* If this option is set, the range of x axis will increase/decrease according to the values.
|
|
@@ -96,11 +96,12 @@ export default {
|
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
98
|
* Change the direction of y axis.<br><br>
|
|
99
|
-
* If true set, the direction will be
|
|
99
|
+
* If true set, the direction will be `top -> bottom`.
|
|
100
100
|
* @name axis․y․inverted
|
|
101
101
|
* @memberof Options
|
|
102
102
|
* @type {boolean}
|
|
103
103
|
* @default false
|
|
104
|
+
* @see [Demo](https://naver.github.io/billboard.js/demo/#Axis.InvertedAxis)
|
|
104
105
|
* @example
|
|
105
106
|
* axis: {
|
|
106
107
|
* y: {
|
|
@@ -83,11 +83,12 @@ export default {
|
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* Change the direction of y2 axis.<br><br>
|
|
86
|
-
* If true set, the direction will be
|
|
86
|
+
* If true set, the direction will be `top -> bottom`.
|
|
87
87
|
* @name axis․y2․inverted
|
|
88
88
|
* @memberof Options
|
|
89
89
|
* @type {boolean}
|
|
90
90
|
* @default false
|
|
91
|
+
* @see [Demo](https://naver.github.io/billboard.js/demo/#Axis.InvertedAxis)
|
|
91
92
|
* @example
|
|
92
93
|
* axis: {
|
|
93
94
|
* y2: {
|
|
@@ -114,15 +114,30 @@ export default {
|
|
|
114
114
|
* - `false`: Remove padding completely and make shape to fully occupy the container element.
|
|
115
115
|
* - In this case, axes and subchart will be hidden.
|
|
116
116
|
* - To adjust some padding from this state, use `axis.[x|y].padding` option.
|
|
117
|
+
* @property {string} [padding.mode] padding mode
|
|
118
|
+
* - `"fit"`: Reduce padding as much as possible to make chart fit to the container element for chart types w/axis.<br>When specified, all padding values will be relative from fitted value.
|
|
117
119
|
* @property {number} [padding.top] padding on the top of chart
|
|
118
120
|
* @property {number} [padding.right] padding on the right of chart
|
|
119
121
|
* @property {number} [padding.bottom] padding on the bottom of chart
|
|
120
122
|
* @property {number} [padding.left] padding on the left of chart
|
|
121
123
|
* @see [Demo](https://naver.github.io/billboard.js/demo/#ChartOptions.Padding)
|
|
124
|
+
* @see [Demo: Fit padding](https://naver.github.io/billboard.js/demo/#ChartOptions.FitPadding)
|
|
122
125
|
* @example
|
|
123
126
|
* // remove padding completely.
|
|
124
127
|
* padding: false,
|
|
125
128
|
*
|
|
129
|
+
* padding: {
|
|
130
|
+
* // specifying mode value, will reduce padding and make fit to the container element.
|
|
131
|
+
* mode: "fit"
|
|
132
|
+
*
|
|
133
|
+
* // when mode is "fit", all padding values will be relative from fitted value.
|
|
134
|
+
* // so, 0 will be initial fitted value.
|
|
135
|
+
* top: 20,
|
|
136
|
+
* right: 20,
|
|
137
|
+
* bottom: 20,
|
|
138
|
+
* left: 20
|
|
139
|
+
* }
|
|
140
|
+
*
|
|
126
141
|
* // or specify padding value for each side
|
|
127
142
|
* padding: {
|
|
128
143
|
* top: 20,
|
|
@@ -132,6 +147,7 @@ export default {
|
|
|
132
147
|
* }
|
|
133
148
|
*/
|
|
134
149
|
padding: true,
|
|
150
|
+
padding_mode: <"fit"|undefined> undefined,
|
|
135
151
|
padding_left: <number|undefined> undefined,
|
|
136
152
|
padding_right: <number|undefined> undefined,
|
|
137
153
|
padding_top: <number|undefined> undefined,
|
|
@@ -146,7 +162,9 @@ export default {
|
|
|
146
162
|
* @property {boolean} [resize.auto=true] Set chart resize automatically on viewport changes.
|
|
147
163
|
* @property {boolean|number} [resize.timer=true] Set resize timer option.
|
|
148
164
|
* - **NOTE:**
|
|
149
|
-
* - The resize function will be called using:
|
|
165
|
+
* - The resize function will be called using:
|
|
166
|
+
* - true: `setTimeout()`
|
|
167
|
+
* - false: `requestIdleCallback()`
|
|
150
168
|
* - Given number(delay in ms) value, resize function will be triggered using `setTimer()` with given delay.
|
|
151
169
|
* @example
|
|
152
170
|
* resize: {
|
|
@@ -63,13 +63,22 @@ export default {
|
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Sort on x axis.
|
|
66
|
+
* - **NOTE:** This option works for lineish(area/line/spline/step) types only.
|
|
66
67
|
* @name data․xSort
|
|
67
68
|
* @memberof Options
|
|
68
69
|
* @type {boolean}
|
|
69
70
|
* @default true
|
|
71
|
+
* @see [Demo](https://naver.github.io/billboard.js/demo/#Data.DataXSort)
|
|
70
72
|
* @example
|
|
71
73
|
* data: {
|
|
72
|
-
* xSort: false
|
|
74
|
+
* xSort: false,
|
|
75
|
+
* x: "x",
|
|
76
|
+
* columns: [
|
|
77
|
+
* // The line graph will start to be drawn following the x axis sequence
|
|
78
|
+
* // Below data, wil start drawing x=1: 200, x=2: 300, x=3: 100
|
|
79
|
+
* ["x", 3, 1, 2],
|
|
80
|
+
* ["data1", 100, 200, 300]
|
|
81
|
+
* ]
|
|
73
82
|
* }
|
|
74
83
|
*/
|
|
75
84
|
data_xSort: true,
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
// Chart
|
|
9
9
|
import apiAxis from "../../Chart/api/axis";
|
|
10
10
|
import apiCategory from "../../Chart/api/category";
|
|
11
|
-
import
|
|
12
|
-
import apiYGrid from "../../Chart/api/grid.y";
|
|
11
|
+
import apiGrid from "../../Chart/api/grid";
|
|
13
12
|
import apiGroup from "../../Chart/api/group";
|
|
14
13
|
import apiRegion from "../../Chart/api/regions";
|
|
15
14
|
import apiX from "../../Chart/api/x";
|
|
@@ -33,9 +32,8 @@ import optGrid from "../Options/common/grid";
|
|
|
33
32
|
export const api = [
|
|
34
33
|
apiAxis,
|
|
35
34
|
apiCategory,
|
|
36
|
-
apiXGrid,
|
|
37
|
-
apiYGrid,
|
|
38
35
|
apiFlow,
|
|
36
|
+
apiGrid,
|
|
39
37
|
apiGroup,
|
|
40
38
|
apiRegion,
|
|
41
39
|
apiX
|
package/src/module/browser.ts
CHANGED
|
@@ -7,7 +7,12 @@
|
|
|
7
7
|
* @private
|
|
8
8
|
*/
|
|
9
9
|
/* eslint-disable no-new-func, no-undef */
|
|
10
|
-
export {
|
|
10
|
+
export {
|
|
11
|
+
win as window,
|
|
12
|
+
doc as document,
|
|
13
|
+
requestAnimationFrame, cancelAnimationFrame,
|
|
14
|
+
requestIdleCallback, cancelIdleCallback
|
|
15
|
+
};
|
|
11
16
|
|
|
12
17
|
const win = (() => {
|
|
13
18
|
const root = (typeof globalThis === "object" && globalThis !== null && globalThis.Object === Object && globalThis) ||
|
|
@@ -19,9 +24,12 @@ const win = (() => {
|
|
|
19
24
|
/* eslint-enable no-new-func, no-undef */
|
|
20
25
|
|
|
21
26
|
// fallback for non-supported environments
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
win.requestAnimationFrame = win.requestAnimationFrame || (cb => setTimeout(cb, 1));
|
|
27
|
+
const hasRAF = typeof win.requestAnimationFrame === "function";
|
|
28
|
+
const hasRIC = typeof win.requestIdleCallback === "function";
|
|
25
29
|
|
|
26
|
-
const
|
|
30
|
+
const requestAnimationFrame = hasRAF ? win.requestAnimationFrame : (cb => setTimeout(cb, 1));
|
|
31
|
+
const cancelAnimationFrame = hasRAF ? win.cancelAnimationFrame : (id => clearTimeout(id));
|
|
32
|
+
const requestIdleCallback = hasRIC ? win.requestIdleCallback : requestAnimationFrame;
|
|
33
|
+
const cancelIdleCallback = hasRIC ? win.cancelIdleCallback : cancelAnimationFrame;
|
|
27
34
|
|
|
35
|
+
const doc = win?.document;
|
package/src/module/generator.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
5
|
import type {d3Transition} from "../../types/types";
|
|
6
|
-
import {window} from "./browser";
|
|
6
|
+
import {window, requestIdleCallback} from "./browser";
|
|
7
7
|
import {isArray, isNumber, isTabVisible, runUntil} from "./util";
|
|
8
8
|
|
|
9
9
|
const {setTimeout, clearTimeout} = window;
|
|
@@ -15,14 +15,14 @@ const {setTimeout, clearTimeout} = window;
|
|
|
15
15
|
* @private
|
|
16
16
|
*/
|
|
17
17
|
export function generateResize(option: boolean|number) {
|
|
18
|
-
const fn:
|
|
18
|
+
const fn: Function[] = [];
|
|
19
19
|
let timeout;
|
|
20
20
|
|
|
21
21
|
const callResizeFn = function() {
|
|
22
22
|
// Delay all resize functions call, to prevent unintended excessive call from resize event
|
|
23
23
|
callResizeFn.clear();
|
|
24
24
|
|
|
25
|
-
if (option === false
|
|
25
|
+
if (option === false) {
|
|
26
26
|
requestIdleCallback(() => {
|
|
27
27
|
fn.forEach((f: Function) => f());
|
|
28
28
|
}, {timeout: 200});
|
package/src/module/util.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import {pointer as d3Pointer} from "d3-selection";
|
|
7
7
|
import {brushSelection as d3BrushSelection} from "d3-brush";
|
|
8
8
|
import type {d3Selection} from "../../types/types";
|
|
9
|
-
import {document, window} from "./browser";
|
|
9
|
+
import {document, window, requestAnimationFrame} from "./browser";
|
|
10
10
|
|
|
11
11
|
export {
|
|
12
12
|
addCssRules,
|
|
@@ -320,8 +320,11 @@ function getBoundingRect(node): {
|
|
|
320
320
|
* @returns {number|string}
|
|
321
321
|
* @private
|
|
322
322
|
*/
|
|
323
|
-
function getRandom(asStr
|
|
324
|
-
const
|
|
323
|
+
function getRandom(asStr = true, min = 0, max = 10000) {
|
|
324
|
+
const crpt = window.crypto || window.msCrypto;
|
|
325
|
+
const rand = crpt ?
|
|
326
|
+
min + crpt.getRandomValues(new Uint32Array(1))[0] % (max - min + 1) :
|
|
327
|
+
Math.floor(Math.random() * (max - min) + min);
|
|
325
328
|
|
|
326
329
|
return asStr ? String(rand) : rand;
|
|
327
330
|
}
|
|
@@ -805,7 +808,7 @@ function convertInputType(mouse: boolean, touch: boolean): "mouse" | "touch" | n
|
|
|
805
808
|
*/
|
|
806
809
|
function runUntil(fn: Function, conditionFn: Function): void {
|
|
807
810
|
if (conditionFn() === false) {
|
|
808
|
-
|
|
811
|
+
requestAnimationFrame(() => runUntil(fn, conditionFn));
|
|
809
812
|
} else {
|
|
810
813
|
fn();
|
|
811
814
|
}
|
package/types/axis.d.ts
CHANGED
|
@@ -24,6 +24,12 @@ export interface AxisConfigurationBase {
|
|
|
24
24
|
* Set additional axes for Axis
|
|
25
25
|
*/
|
|
26
26
|
axes?: AxesConfiguration[];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Change the direction of axis.
|
|
30
|
+
* If true set, the direction will be from: right -> left for x axis / top -> bottom for y/y2 axis.
|
|
31
|
+
*/
|
|
32
|
+
inverted?: boolean;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
export interface xAxisConfiguration extends AxisConfigurationBase {
|
|
@@ -135,12 +141,6 @@ export interface yAxisConfigurationBase extends AxisConfigurationBase {
|
|
|
135
141
|
*/
|
|
136
142
|
min?: number;
|
|
137
143
|
|
|
138
|
-
/**
|
|
139
|
-
* Change the direction of y axis.
|
|
140
|
-
* If true set, the direction will be from the top to the bottom.
|
|
141
|
-
*/
|
|
142
|
-
inverted?: boolean;
|
|
143
|
-
|
|
144
144
|
/**
|
|
145
145
|
* Set center value of y axis.
|
|
146
146
|
*/
|
|
@@ -352,7 +352,8 @@ export interface YTickConfiguration {
|
|
|
352
352
|
* Set formatter for y axis tick text.
|
|
353
353
|
* This option accepts d3.format object as well as a function you define.
|
|
354
354
|
*/
|
|
355
|
-
format?: ((this: Chart, x: number) => string | number) |
|
|
355
|
+
format?: ((this: Chart, x: number) => string | number) |
|
|
356
|
+
((this: Chart, x: Date) => string | number);
|
|
356
357
|
|
|
357
358
|
/**
|
|
358
359
|
* Setting for culling ticks.
|
package/types/chart.d.ts
CHANGED
|
@@ -364,6 +364,7 @@ export interface Chart {
|
|
|
364
364
|
types?: { [key: string]: string };
|
|
365
365
|
unload?: boolean | ArrayOrString;
|
|
366
366
|
done?: (this: Chart) => void;
|
|
367
|
+
resizeAfter?: boolean;
|
|
367
368
|
}): void;
|
|
368
369
|
|
|
369
370
|
/**
|
|
@@ -378,7 +379,11 @@ export interface Chart {
|
|
|
378
379
|
* - If you call load API soon after/before unload, unload param of load should be used. Otherwise chart will not be rendered properly because of cancel of animation.
|
|
379
380
|
* - done will be called after data loaded, but it's not after rendering. It's because rendering will finish after some transition and there is some time lag between loading and rendering.
|
|
380
381
|
*/
|
|
381
|
-
unload(this: Chart,
|
|
382
|
+
unload(this: Chart, args?: TargetIds | {
|
|
383
|
+
ids?: TargetIds,
|
|
384
|
+
done?: (this: Chart) => void,
|
|
385
|
+
resizeAfter?: boolean;
|
|
386
|
+
}): void;
|
|
382
387
|
|
|
383
388
|
/**
|
|
384
389
|
* Flow data to the chart. By this API, you can append new data points to the chart.
|
package/types/options.d.ts
CHANGED
|
@@ -113,6 +113,12 @@ export interface ChartOptions {
|
|
|
113
113
|
* - To adjust some padding from this state, use `axis.[x|y].padding` option.
|
|
114
114
|
*/
|
|
115
115
|
padding?: boolean | {
|
|
116
|
+
/**
|
|
117
|
+
* Padding mode
|
|
118
|
+
* - `"fit"`: Reduce padding as much as possible to make chart fit to the container element for chart types w/axis.<br>When specified, all padding values will be relative from fitted value.
|
|
119
|
+
*/
|
|
120
|
+
mode?: "fit";
|
|
121
|
+
|
|
116
122
|
/**
|
|
117
123
|
* The padding on the top of the chart.
|
|
118
124
|
*/
|
package/src/Chart/api/grid.x.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
-
* billboard.js project is licensed under the MIT license
|
|
4
|
-
*/
|
|
5
|
-
import {extend} from "../../module/util";
|
|
6
|
-
|
|
7
|
-
type GridsParam = {value?: number, class?: string, text?: string}[];
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Update x grid lines.
|
|
11
|
-
* @function xgrids
|
|
12
|
-
* @instance
|
|
13
|
-
* @memberof Chart
|
|
14
|
-
* @param {Array} grids X grid lines will be replaced with this argument. The format of this argument is the same as grid.x.lines.
|
|
15
|
-
* @returns {object}
|
|
16
|
-
* @example
|
|
17
|
-
* // Show 2 x grid lines
|
|
18
|
-
* chart.xgrids([
|
|
19
|
-
* {value: 1, text: "Label 1"},
|
|
20
|
-
* {value: 4, text: "Label 4"}
|
|
21
|
-
* ]);
|
|
22
|
-
* // --> Returns: [{value: 1, text: "Label 1"}, {value: 4, text: "Label 4"}]
|
|
23
|
-
*/
|
|
24
|
-
const xgrids = function(grids: GridsParam): GridsParam {
|
|
25
|
-
const $$ = this.internal;
|
|
26
|
-
const {config} = $$;
|
|
27
|
-
|
|
28
|
-
if (!grids) {
|
|
29
|
-
return config.grid_x_lines;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
config.grid_x_lines = grids;
|
|
33
|
-
$$.redrawWithoutRescale();
|
|
34
|
-
|
|
35
|
-
return config.grid_x_lines;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
extend(xgrids, {
|
|
39
|
-
/**
|
|
40
|
-
* Add x grid lines.<br>
|
|
41
|
-
* This API adds new x grid lines instead of replacing like xgrids.
|
|
42
|
-
* @function xgrids․add
|
|
43
|
-
* @instance
|
|
44
|
-
* @memberof Chart
|
|
45
|
-
* @param {Array|object} grids New x grid lines will be added. The format of this argument is the same as grid.x.lines and it's possible to give an Object if only one line will be added.
|
|
46
|
-
* @returns {object}
|
|
47
|
-
* @example
|
|
48
|
-
* // Add a new x grid line
|
|
49
|
-
* chart.xgrids.add(
|
|
50
|
-
* {value: 4, text: "Label 4"}
|
|
51
|
-
* );
|
|
52
|
-
*
|
|
53
|
-
* // Add new x grid lines
|
|
54
|
-
* chart.xgrids.add([
|
|
55
|
-
* {value: 2, text: "Label 2"},
|
|
56
|
-
* {value: 4, text: "Label 4"}
|
|
57
|
-
* ]);
|
|
58
|
-
*/
|
|
59
|
-
add: function(grids: GridsParam): GridsParam {
|
|
60
|
-
return this.xgrids(
|
|
61
|
-
this.internal.config.grid_x_lines
|
|
62
|
-
.concat(grids || [])
|
|
63
|
-
);
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Remove x grid lines.<br>
|
|
68
|
-
* This API removes x grid lines.
|
|
69
|
-
* @function xgrids․remove
|
|
70
|
-
* @instance
|
|
71
|
-
* @memberof Chart
|
|
72
|
-
* @param {object} params This argument should include value or class. If value is given, the x grid lines that have specified x value will be removed. If class is given, the x grid lines that have specified class will be removed. If args is not given, all of x grid lines will be removed.
|
|
73
|
-
* @example
|
|
74
|
-
* // x grid line on x = 2 will be removed
|
|
75
|
-
* chart.xgrids.remove({value: 2});
|
|
76
|
-
*
|
|
77
|
-
* // x grid lines that have 'grid-A' will be removed
|
|
78
|
-
* chart.xgrids.remove({
|
|
79
|
-
* class: "grid-A"
|
|
80
|
-
* });
|
|
81
|
-
*
|
|
82
|
-
* // all of x grid lines will be removed
|
|
83
|
-
* chart.xgrids.remove();
|
|
84
|
-
*/
|
|
85
|
-
remove: function(params?: GridsParam): void { // TODO: multiple
|
|
86
|
-
this.internal.removeGridLines(params, true);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
export default {xgrids};
|