billboard.js 3.14.3 → 3.15.0-next.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.
- package/README.md +4 -2
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +155 -102
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +10 -10
- package/dist/billboard.pkgd.js +1367 -1014
- package/dist/billboard.pkgd.min.js +14 -14
- 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 +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-tableview.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-textoverlap.js +9 -9
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +3 -3
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +1204 -914
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +5 -5
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +1205 -915
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +7 -7
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +1206 -916
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +14 -14
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +1207 -917
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +8 -8
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +1215 -918
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +6 -6
- package/dist/theme/dark.css +1 -1
- package/dist/theme/dark.min.css +1 -1
- 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/theme/modern.css +1 -1
- package/dist/theme/modern.min.css +1 -1
- package/dist-esm/billboard.js +555 -482
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +4 -4
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +15 -88
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +13 -86
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +10 -83
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +7 -70
- package/package.json +28 -28
- package/src/Chart/api/chart.ts +2 -0
- package/src/Chart/api/regions.ts +2 -2
- package/src/ChartInternal/Axis/Axis.ts +68 -60
- package/src/ChartInternal/ChartInternal.ts +9 -4
- package/src/ChartInternal/interactions/interaction.ts +1 -1
- package/src/ChartInternal/internals/region.ts +69 -56
- package/src/config/Options/axis/y2.ts +13 -0
- package/src/config/Options/common/main.ts +32 -11
- package/types/options.d.ts +3 -1
- package/types/types.d.ts +0 -14
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
5
|
import {select as d3Select} from "d3-selection"; // selection
|
|
6
|
-
import type {
|
|
6
|
+
import type {RegionOptions} from "../../../types/options";
|
|
7
|
+
import type {AxisType} from "../../../types/types";
|
|
7
8
|
import {$REGION} from "../../config/classes";
|
|
8
|
-
import {isValue, parseDate} from "../../module/util";
|
|
9
|
+
import {getBoundingRect, isString, isValue, parseDate} from "../../module/util";
|
|
9
10
|
|
|
10
11
|
export default {
|
|
11
12
|
initRegion(): void {
|
|
@@ -63,27 +64,42 @@ export default {
|
|
|
63
64
|
redrawRegion(withTransition: boolean) {
|
|
64
65
|
const $$ = this;
|
|
65
66
|
const {$el: {region}, $T} = $$;
|
|
67
|
+
const regionX = $$.regionX.bind($$);
|
|
68
|
+
const regionY = $$.regionY.bind($$);
|
|
69
|
+
const attr = ["width", "height"];
|
|
66
70
|
let regions = region.list.select("rect");
|
|
67
71
|
let label = region.list.selectAll("text");
|
|
68
72
|
|
|
69
73
|
regions = $T(regions, withTransition)
|
|
70
|
-
.attr("x",
|
|
71
|
-
.attr("y",
|
|
74
|
+
.attr("x", regionX)
|
|
75
|
+
.attr("y", regionY)
|
|
72
76
|
.attr("width", $$.regionWidth.bind($$))
|
|
73
77
|
.attr("height", $$.regionHeight.bind($$));
|
|
74
78
|
|
|
75
79
|
label = $T(label, withTransition)
|
|
76
|
-
.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
.text(d => d.label?.text)
|
|
81
|
+
.attr("transform", ({label}) => label.rotated ? ` rotate(-90)` : null)
|
|
82
|
+
.attr("transform", function(d) {
|
|
83
|
+
const {x = 0, y = 0, center = false, rotated = false} = d.label ?? {};
|
|
84
|
+
const rect = this.previousElementSibling;
|
|
85
|
+
const pos = {x: 0, y: 0};
|
|
86
|
+
|
|
87
|
+
if (isString(center)) {
|
|
88
|
+
["x", "y"].forEach((v, i) => {
|
|
89
|
+
if (center.indexOf(v) > -1) {
|
|
90
|
+
pos[v] =
|
|
91
|
+
(+rect.getAttribute(attr[i]) - getBoundingRect(this)[attr[i]]) / 2;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return `translate(${regionX(d) + pos.x + x}, ${regionY(d) + pos.y + y})${
|
|
80
97
|
rotated ? ` rotate(-90)` : ``
|
|
81
98
|
}`;
|
|
82
99
|
})
|
|
83
|
-
.attr("text-anchor",
|
|
100
|
+
.attr("text-anchor", ({label}) => label?.rotated ? "end" : null)
|
|
84
101
|
.attr("dy", "1em")
|
|
85
|
-
.style("fill",
|
|
86
|
-
.text(d => d.label?.text);
|
|
102
|
+
.style("fill", ({label}) => label?.color ?? null);
|
|
87
103
|
|
|
88
104
|
return [
|
|
89
105
|
regions
|
|
@@ -98,76 +114,73 @@ export default {
|
|
|
98
114
|
];
|
|
99
115
|
},
|
|
100
116
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const isRotated = config.axis_rotated;
|
|
105
|
-
const isX = type === "x";
|
|
106
|
-
let key = "start";
|
|
107
|
-
let currScale;
|
|
108
|
-
let pos = 0;
|
|
109
|
-
|
|
110
|
-
if (d.axis === "y" || d.axis === "y2") {
|
|
111
|
-
if (!isX) {
|
|
112
|
-
key = "end";
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if ((isX ? isRotated : !isRotated) && key in d) {
|
|
116
|
-
currScale = scale[d.axis];
|
|
117
|
-
pos = currScale(d[key]);
|
|
118
|
-
}
|
|
119
|
-
} else if ((isX ? !isRotated : isRotated) && key in d) {
|
|
120
|
-
currScale = scale.zoom || scale.x;
|
|
121
|
-
pos = currScale($$.axis.isTimeSeries() ? parseDate.call($$, d[key]) : d[key]);
|
|
122
|
-
}
|
|
117
|
+
regionX(d: RegionOptions): number {
|
|
118
|
+
return this.getRegionSize("x", d);
|
|
119
|
+
},
|
|
123
120
|
|
|
124
|
-
|
|
121
|
+
regionY(d: RegionOptions): number {
|
|
122
|
+
return this.getRegionSize("y", d);
|
|
125
123
|
},
|
|
126
124
|
|
|
127
|
-
|
|
128
|
-
return this.
|
|
125
|
+
regionWidth(d: RegionOptions): number {
|
|
126
|
+
return this.getRegionSize("width", d);
|
|
129
127
|
},
|
|
130
128
|
|
|
131
|
-
|
|
132
|
-
return this.
|
|
129
|
+
regionHeight(d: RegionOptions): number {
|
|
130
|
+
return this.getRegionSize("height", d);
|
|
133
131
|
},
|
|
134
132
|
|
|
135
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Get Region size according start/end position
|
|
135
|
+
* @param {string} type Type string
|
|
136
|
+
* @param {ojbect} d Data object
|
|
137
|
+
* @returns {number}
|
|
138
|
+
* @private
|
|
139
|
+
*/
|
|
140
|
+
getRegionSize(type: AxisType | "width" | "height", d: RegionOptions): number {
|
|
136
141
|
const $$ = this;
|
|
137
142
|
const {config, scale, state} = $$;
|
|
138
143
|
const isRotated = config.axis_rotated;
|
|
139
|
-
const
|
|
140
|
-
|
|
144
|
+
const isAxisType = /(x|y|y2)/.test(type);
|
|
145
|
+
|
|
146
|
+
const isType = isAxisType ? type === "x" : type === "width";
|
|
147
|
+
const start = !isAxisType && $$[isType ? "regionX" : "regionY"](d);
|
|
148
|
+
let key = isAxisType ? "start" : "end";
|
|
149
|
+
let pos = isAxisType ? 0 : state[type];
|
|
141
150
|
let currScale;
|
|
142
|
-
let key = "end";
|
|
143
|
-
let end = state[type];
|
|
144
151
|
|
|
145
152
|
if (d.axis === "y" || d.axis === "y2") {
|
|
146
|
-
if (!
|
|
153
|
+
if (!isAxisType && !isType) {
|
|
147
154
|
key = "start";
|
|
155
|
+
} else if (isAxisType && !isType) {
|
|
156
|
+
key = "end";
|
|
148
157
|
}
|
|
149
158
|
|
|
150
|
-
if ((
|
|
159
|
+
if ((isType ? isRotated : !isRotated) && key in d) {
|
|
151
160
|
currScale = scale[d.axis];
|
|
152
|
-
end = currScale(d[key]);
|
|
153
161
|
}
|
|
154
|
-
} else if ((
|
|
162
|
+
} else if ((isType ? !isRotated : isRotated) && key in d) {
|
|
155
163
|
currScale = scale.zoom || scale.x;
|
|
156
|
-
end = currScale($$.axis.isTimeSeries() ? parseDate.call($$, d[key]) : d[key]);
|
|
157
164
|
}
|
|
158
165
|
|
|
159
|
-
|
|
160
|
-
|
|
166
|
+
if (currScale) {
|
|
167
|
+
let offset = 0;
|
|
168
|
+
pos = d[key];
|
|
161
169
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
170
|
+
if ($$.axis.isTimeSeries(d.axis)) {
|
|
171
|
+
pos = parseDate.call($$, pos);
|
|
172
|
+
} else if (/(x|width)/.test(type) && $$.axis.isCategorized() && isNaN(pos)) {
|
|
173
|
+
pos = config.axis_x_categories.indexOf(pos);
|
|
174
|
+
offset = $$.axis.x.tickOffset() * (key === "start" ? -1 : 1);
|
|
175
|
+
}
|
|
165
176
|
|
|
166
|
-
|
|
167
|
-
|
|
177
|
+
pos = currScale(pos) + offset;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return isAxisType ? pos : pos < start ? 0 : pos - start;
|
|
168
181
|
},
|
|
169
182
|
|
|
170
|
-
isRegionOnX(d:
|
|
183
|
+
isRegionOnX(d: RegionOptions): boolean {
|
|
171
184
|
return !d.axis || d.axis === "x";
|
|
172
185
|
}
|
|
173
186
|
};
|
|
@@ -6,6 +6,19 @@
|
|
|
6
6
|
* y2 Axis config options
|
|
7
7
|
*/
|
|
8
8
|
export default {
|
|
9
|
+
/**
|
|
10
|
+
* Set clip-path attribute for y2 axis element
|
|
11
|
+
* - **NOTE**: `clip-path` attribute for y2 Axis is set only when `axis.y2.inner` option is true.
|
|
12
|
+
* @name axis․y2․clipPath
|
|
13
|
+
* @memberof Options
|
|
14
|
+
* @type {boolean}
|
|
15
|
+
* @default true
|
|
16
|
+
* @example
|
|
17
|
+
* // don't set 'clip-path' attribute
|
|
18
|
+
* clipPath: false
|
|
19
|
+
*/
|
|
20
|
+
axis_y2_clipPath: true,
|
|
21
|
+
|
|
9
22
|
/**
|
|
10
23
|
* Show or hide y2 axis.
|
|
11
24
|
* - **NOTE**:
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
5
|
+
import type {RegionOptions} from "../../../../types/options";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* main config options
|
|
@@ -166,6 +166,7 @@ export default {
|
|
|
166
166
|
* - **NOTE:** Available options
|
|
167
167
|
* - true: Enables automatic resize.
|
|
168
168
|
* - false: Disables automatic resize.
|
|
169
|
+
* - "parent": Enables automatic resize when the parent node is resized.
|
|
169
170
|
* - "viewBox": Enables automatic resize, and size will be fixed based on the viewbox.
|
|
170
171
|
* @property {boolean|number} [resize.timer=true] Set resize timer option.
|
|
171
172
|
* - **NOTE:** Available options
|
|
@@ -173,11 +174,15 @@ export default {
|
|
|
173
174
|
* - true: `setTimeout()`
|
|
174
175
|
* - false: `requestIdleCallback()`
|
|
175
176
|
* - Given number(delay in ms) value, resize function will be triggered using `setTimeout()` with given delay.
|
|
176
|
-
* @see [Demo](https://naver.github.io/billboard.js/demo/#ChartOptions.
|
|
177
|
+
* @see [Demo: resize "parent"](https://naver.github.io/billboard.js/demo/#ChartOptions.resizeParent)
|
|
178
|
+
* @see [Demo: resize "viewBox"](https://naver.github.io/billboard.js/demo/#ChartOptions.resizeViewBox)
|
|
177
179
|
* @example
|
|
178
180
|
* resize: {
|
|
179
181
|
* auto: false,
|
|
180
182
|
*
|
|
183
|
+
* // set resize based on parent node width value
|
|
184
|
+
* auto: "parent",
|
|
185
|
+
*
|
|
181
186
|
* // set resize based on viewBox value
|
|
182
187
|
* auto: "viewBox",
|
|
183
188
|
*
|
|
@@ -191,7 +196,7 @@ export default {
|
|
|
191
196
|
* timer: 100
|
|
192
197
|
* }
|
|
193
198
|
*/
|
|
194
|
-
resize_auto: <boolean | "viewBox">true,
|
|
199
|
+
resize_auto: <boolean | "parent" | "viewBox">true,
|
|
195
200
|
resize_timer: true,
|
|
196
201
|
|
|
197
202
|
/**
|
|
@@ -399,17 +404,32 @@ export default {
|
|
|
399
404
|
|
|
400
405
|
/**
|
|
401
406
|
* Show rectangles inside the chart.<br><br>
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
* If
|
|
406
|
-
* If
|
|
407
|
-
* If class is set, the region element will have it as class.
|
|
407
|
+
* - **NOTE:**<br>
|
|
408
|
+
* - axis must be x, y or y2. start and end should be the value where regions start and end.
|
|
409
|
+
* - If not specified, the edge values will be used.
|
|
410
|
+
* - If timeseries x axis, date string, Date object and unixtime integer can be used.
|
|
411
|
+
* - If category x axis, category name can be used for start and end.
|
|
412
|
+
* - If class is set, the region element will have it as class.
|
|
413
|
+
*
|
|
414
|
+
* This option accept array of object with below values:
|
|
415
|
+
* - `axis {string}`: 'x', 'y', or 'y2'
|
|
416
|
+
* - `[start] {number|Date|string}`: Start position of the region. If not set, the start will be the edge of the chart.
|
|
417
|
+
* - `[end] {number|Date|string}`: End position of the region. If not set, the end will be the edge of the chart.
|
|
418
|
+
* - `[class] {string}`: Class value to apply to the region.
|
|
419
|
+
* - `[label] {object}` Lable text option.
|
|
420
|
+
* - `text {string}`: Text value.
|
|
421
|
+
* - `x {number}`: x Position.
|
|
422
|
+
* - `y {number}`: y Position.
|
|
423
|
+
* - `center {string}`: Align label at the center. Allowed values are 'x', 'y', 'xy'.
|
|
424
|
+
* - `color {string}`: Color string.
|
|
425
|
+
* - `rotated (boolean)`: Whether rotate label or not.
|
|
408
426
|
* @name regions
|
|
409
427
|
* @memberof Options
|
|
410
428
|
* @type {Array}
|
|
411
429
|
* @default []
|
|
412
|
-
* @see [Demo](https://naver.github.io/billboard.js/demo/#Region.
|
|
430
|
+
* @see [Demo: Regions](https://naver.github.io/billboard.js/demo/#Region.Region)
|
|
431
|
+
* @see [Demo: Regions Timeseries](https://naver.github.io/billboard.js/demo/#Region.RegionWithTimeseries)
|
|
432
|
+
* @see [Demo: Regions Label](https://naver.github.io/billboard.js/demo/#Region.RegionLabel)
|
|
413
433
|
* @example
|
|
414
434
|
* regions: [
|
|
415
435
|
* {
|
|
@@ -421,11 +441,12 @@ export default {
|
|
|
421
441
|
* text: "Region Text",
|
|
422
442
|
* x: 5, // position relative of the initial x coordinate
|
|
423
443
|
* y: 5, // position relative of the initial y coordinate
|
|
444
|
+
* center: "xy", // center text label in both direction.
|
|
424
445
|
* color: "red", // color string
|
|
425
446
|
* rotated: true // make text to show in vertical or horizontal
|
|
426
447
|
* }
|
|
427
448
|
* }
|
|
428
449
|
* ]
|
|
429
450
|
*/
|
|
430
|
-
regions: <
|
|
451
|
+
regions: <RegionOptions[]>[]
|
|
431
452
|
};
|
package/types/options.d.ts
CHANGED
|
@@ -163,9 +163,10 @@ export interface ChartOptions {
|
|
|
163
163
|
* - **NOTE:** Available options
|
|
164
164
|
* - true: Enables automatic resize.
|
|
165
165
|
* - false: Disables automatic resize.
|
|
166
|
+
* - "parent": Enables automatic resize when the parent node is resized.
|
|
166
167
|
* - "viewBox": Enables automatic resize, and size will be fixed based on the viewbox.
|
|
167
168
|
*/
|
|
168
|
-
auto?: boolean | "viewBox";
|
|
169
|
+
auto?: boolean | "parent" | "viewBox";
|
|
169
170
|
|
|
170
171
|
/**
|
|
171
172
|
* Set resize timer option.
|
|
@@ -424,6 +425,7 @@ export interface RegionOptions {
|
|
|
424
425
|
text?: string;
|
|
425
426
|
x?: number;
|
|
426
427
|
y?: number;
|
|
428
|
+
center?: "x" | "y" | "xy" | false;
|
|
427
429
|
color?: string;
|
|
428
430
|
rotated?: boolean;
|
|
429
431
|
}
|
package/types/types.d.ts
CHANGED
|
@@ -66,17 +66,3 @@ export interface DataRegionsType {
|
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
export interface RegionsType {
|
|
71
|
-
axis?: "x" | "y" | "y2";
|
|
72
|
-
start?: number;
|
|
73
|
-
end?: number;
|
|
74
|
-
class?: string;
|
|
75
|
-
label?: {
|
|
76
|
-
text: string;
|
|
77
|
-
x?: number;
|
|
78
|
-
y?: number;
|
|
79
|
-
color?: string;
|
|
80
|
-
rotated?: boolean;
|
|
81
|
-
};
|
|
82
|
-
}
|