billboard.js 3.9.4 → 3.10.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 +2 -2
- package/dist/billboard.css +2 -2
- package/dist/billboard.js +2742 -2516
- package/dist/billboard.min.css +2 -2
- package/dist/billboard.min.js +2 -2
- package/dist/billboard.pkgd.js +2936 -2704
- package/dist/billboard.pkgd.min.js +4 -4
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +15 -15
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +205 -186
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.js +231 -226
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +172 -152
- package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.js +161 -142
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/{billboardjs-plugin-bubblecompare.js → billboardjs-plugin-bubblecompare.pkgd.js} +52 -32
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +12 -0
- package/dist/plugin/pkgd/{billboardjs-plugin-sparkline.js → billboardjs-plugin-sparkline.pkgd.js} +239 -200
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +12 -0
- package/dist/plugin/pkgd/{billboardjs-plugin-stanford.js → billboardjs-plugin-stanford.pkgd.js} +301 -277
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +12 -0
- package/dist/plugin/pkgd/{billboardjs-plugin-tableview.js → billboardjs-plugin-tableview.pkgd.js} +206 -166
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +12 -0
- package/dist/plugin/pkgd/{billboardjs-plugin-textoverlap.js → billboardjs-plugin-textoverlap.pkgd.js} +308 -278
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +12 -0
- package/dist/theme/dark.css +5 -4
- package/dist/theme/dark.min.css +2 -2
- package/dist/theme/datalab.css +5 -4
- package/dist/theme/datalab.min.css +2 -2
- package/dist/theme/graph.css +5 -4
- package/dist/theme/graph.min.css +2 -2
- package/dist/theme/insight.css +5 -4
- package/dist/theme/insight.min.css +2 -2
- package/dist-esm/billboard.js +718 -509
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +3 -3
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +15 -9
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +21 -28
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +17 -11
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +13 -7
- package/package.json +32 -32
- package/src/Chart/api/axis.ts +4 -0
- package/src/Chart/api/category.ts +8 -4
- package/src/Chart/api/export.ts +1 -2
- package/src/Chart/api/subchart.ts +162 -89
- package/src/Chart/api/zoom.ts +69 -79
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +0 -8
- package/src/ChartInternal/data/IData.ts +4 -1
- package/src/ChartInternal/data/convert.helper.ts +1 -15
- package/src/ChartInternal/data/data.ts +8 -2
- package/src/ChartInternal/interactions/eventrect.ts +3 -4
- package/src/ChartInternal/interactions/flow.ts +1 -7
- package/src/ChartInternal/interactions/interaction.ts +11 -5
- package/src/ChartInternal/interactions/subchart.ts +36 -30
- package/src/ChartInternal/interactions/zoom.ts +13 -3
- package/src/ChartInternal/internals/category.ts +2 -2
- package/src/ChartInternal/internals/clip.ts +4 -5
- package/src/ChartInternal/internals/color.ts +49 -23
- package/src/ChartInternal/internals/domain.ts +46 -10
- package/src/ChartInternal/internals/grid.ts +57 -86
- package/src/ChartInternal/internals/redraw.ts +1 -6
- package/src/ChartInternal/internals/region.ts +35 -12
- package/src/ChartInternal/internals/selection.ts +1 -1
- package/src/ChartInternal/internals/text.ts +1 -26
- package/src/ChartInternal/internals/title.ts +10 -48
- package/src/ChartInternal/internals/tooltip.ts +50 -54
- package/src/ChartInternal/shape/arc.ts +2 -2
- package/src/ChartInternal/shape/candlestick.ts +2 -17
- package/src/ChartInternal/shape/point.ts +36 -8
- package/src/ChartInternal/shape/radar.ts +1 -1
- package/src/ChartInternal/shape/shape.ts +50 -4
- package/src/ChartInternal/shape/treemap.ts +2 -2
- package/src/Plugin/bubblecompare/index.ts +1 -1
- package/src/Plugin/sparkline/index.ts +2 -2
- package/src/Plugin/stanford/Elements.ts +10 -2
- package/src/Plugin/stanford/index.ts +1 -24
- package/src/Plugin/tableview/index.ts +2 -2
- package/src/config/Options/axis/x.ts +1 -0
- package/src/config/Options/common/main.ts +12 -2
- package/src/config/Options/common/point.ts +41 -0
- package/src/config/Options/common/tooltip.ts +10 -10
- package/src/config/Options/data/axis.ts +3 -1
- package/src/config/Options/data/data.ts +10 -2
- package/src/config/Options/shape/area.ts +10 -4
- package/src/config/Options/shape/bar.ts +10 -4
- package/src/config/Store/State.ts +3 -0
- package/src/module/Cache.ts +7 -5
- package/src/module/browser.ts +34 -14
- package/src/module/util.ts +8 -4
- package/src/module/worker.ts +24 -13
- package/src/scss/billboard.scss +4 -2
- package/src/scss/theme/dark.scss +4 -2
- package/src/scss/theme/datalab.scss +4 -2
- package/src/scss/theme/graph.scss +4 -2
- package/src/scss/theme/insight.scss +4 -2
- package/types/chart.d.ts +11 -0
- package/types/options.d.ts +9 -3
- package/types/options.shape.d.ts +26 -0
- package/types/types.d.ts +15 -1
|
@@ -28,6 +28,26 @@ import CLASS from "../../config/classes";
|
|
|
28
28
|
import {capitalize, getPointer, getRectSegList, getUnique, isObjectType, isNumber, isValue, isUndefined, notEmpty} from "../../module/util";
|
|
29
29
|
import type {IDataRow, IDataIndice, TIndices} from "../data/IData";
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Get grouped data point function for y coordinate
|
|
33
|
+
* - Note: Grouped(stacking) works only for line and bar types
|
|
34
|
+
* @param {object} d data vlaue
|
|
35
|
+
* @returns {Function|undefined}
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
function getGroupedDataPointsFn(d) {
|
|
39
|
+
const $$ = this;
|
|
40
|
+
let fn;
|
|
41
|
+
|
|
42
|
+
if ($$.isLineType(d)) {
|
|
43
|
+
fn = $$.generateGetLinePoints($$.getShapeIndices($$.isLineType));
|
|
44
|
+
} else if ($$.isBarType(d)) {
|
|
45
|
+
fn = $$.generateGetBarPoints($$.getShapeIndices($$.isBarType));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return fn;
|
|
49
|
+
}
|
|
50
|
+
|
|
31
51
|
export interface IOffset {
|
|
32
52
|
_$width: number;
|
|
33
53
|
_$total: number[]
|
|
@@ -87,7 +107,7 @@ export default {
|
|
|
87
107
|
},
|
|
88
108
|
|
|
89
109
|
/**
|
|
90
|
-
* Get shape's indices according it's position
|
|
110
|
+
* Get shape's indices according it's position within each axis tick.
|
|
91
111
|
*
|
|
92
112
|
* From the below example, indices will be:
|
|
93
113
|
* ==> {data1: 0, data2: 0, data3: 1, data4: 1, __max__: 1}
|
|
@@ -125,11 +145,16 @@ export default {
|
|
|
125
145
|
continue;
|
|
126
146
|
}
|
|
127
147
|
|
|
128
|
-
for (let k = 0,
|
|
129
|
-
if (
|
|
130
|
-
ind[d.id] = ind[
|
|
148
|
+
for (let k = 0, key; (key = groups[k]); k++) {
|
|
149
|
+
if (key in ind) {
|
|
150
|
+
ind[d.id] = ind[key];
|
|
131
151
|
break;
|
|
132
152
|
}
|
|
153
|
+
|
|
154
|
+
// for same grouped data, add other data to same indices
|
|
155
|
+
if (d.id !== key && xKey) {
|
|
156
|
+
ind[key] = ind[d.id] ?? i[xKey];
|
|
157
|
+
}
|
|
133
158
|
}
|
|
134
159
|
}
|
|
135
160
|
|
|
@@ -371,6 +396,27 @@ export default {
|
|
|
371
396
|
};
|
|
372
397
|
},
|
|
373
398
|
|
|
399
|
+
/**
|
|
400
|
+
* Get data's y coordinate
|
|
401
|
+
* @param {object} d Target data
|
|
402
|
+
* @param {number} i Index number
|
|
403
|
+
* @returns {number} y coordinate
|
|
404
|
+
* @private
|
|
405
|
+
*/
|
|
406
|
+
circleY(d: IDataRow, i: number): number {
|
|
407
|
+
const $$ = this;
|
|
408
|
+
const id = d.id;
|
|
409
|
+
let points;
|
|
410
|
+
|
|
411
|
+
if ($$.isGrouped(id)) {
|
|
412
|
+
points = getGroupedDataPointsFn.bind($$)(d);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return points ?
|
|
416
|
+
points(d, i)[0][1] :
|
|
417
|
+
$$.getYScaleById(id)($$.getBaseValue(d));
|
|
418
|
+
},
|
|
419
|
+
|
|
374
420
|
getBarW(type, axis, targetsNum: number): number | IOffset {
|
|
375
421
|
const $$ = this;
|
|
376
422
|
const {config, org, scale} = $$;
|
|
@@ -122,12 +122,12 @@ export default {
|
|
|
122
122
|
const isTouch = state.inputType === "touch";
|
|
123
123
|
|
|
124
124
|
$el.treemap
|
|
125
|
-
.on(isTouch ? "touchstart" : "mousemove", event => {
|
|
125
|
+
.on(isTouch ? "touchstart" : "mouseover mousemove", event => {
|
|
126
126
|
const data = getTarget(event);
|
|
127
127
|
|
|
128
128
|
if (data) {
|
|
129
129
|
$$.showTooltip([data], event.currentTarget);
|
|
130
|
-
event.type
|
|
130
|
+
/^(touchstart|mouseover)$/.test(event.type) && $$.setOverOut(true, data);
|
|
131
131
|
}
|
|
132
132
|
})
|
|
133
133
|
.on(isTouch ? "touchend" : "mouseout", event => {
|
|
@@ -76,7 +76,7 @@ export default class BubbleCompare extends Plugin {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
changeCursorPoint(): void {
|
|
79
|
-
this.$$.$el.
|
|
79
|
+
this.$$.$el.eventRect.style("cursor", "pointer");
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
findClosest(values, pos): number {
|
|
@@ -222,7 +222,7 @@ export default class Sparkline extends Plugin {
|
|
|
222
222
|
|
|
223
223
|
$$.state.event = e;
|
|
224
224
|
|
|
225
|
-
if ($$.
|
|
225
|
+
if ($$.isPointFocusOnly() && d) {
|
|
226
226
|
$$.showCircleFocus?.([d]);
|
|
227
227
|
}
|
|
228
228
|
|
|
@@ -235,7 +235,7 @@ export default class Sparkline extends Plugin {
|
|
|
235
235
|
|
|
236
236
|
$$.state.event = e;
|
|
237
237
|
|
|
238
|
-
$$.
|
|
238
|
+
$$.isPointFocusOnly() ?
|
|
239
239
|
$$.hideCircleFocus() : $$.unexpandCircles();
|
|
240
240
|
|
|
241
241
|
$$.hideTooltip();
|
|
@@ -58,9 +58,17 @@ export default class Elements {
|
|
|
58
58
|
.select("line")
|
|
59
59
|
.transition()
|
|
60
60
|
.duration(duration)
|
|
61
|
-
.attr("x1", d =>
|
|
61
|
+
.attr("x1", d => {
|
|
62
|
+
const v = isRotated ? yvCustom(d, "y1") : xvCustom(d, "x1");
|
|
63
|
+
|
|
64
|
+
return v;
|
|
65
|
+
})
|
|
62
66
|
.attr("x2", d => (isRotated ? yvCustom(d, "y2") : xvCustom(d, "x2")))
|
|
63
|
-
.attr("y1", d =>
|
|
67
|
+
.attr("y1", d => {
|
|
68
|
+
const v = isRotated ? xvCustom(d, "x1") : yvCustom(d, "y1");
|
|
69
|
+
|
|
70
|
+
return v;
|
|
71
|
+
})
|
|
64
72
|
.attr("y2", d => (isRotated ? xvCustom(d, "x2") : yvCustom(d, "y2")))
|
|
65
73
|
.transition()
|
|
66
74
|
.style("opacity", null);
|
|
@@ -12,7 +12,7 @@ import Plugin from "../Plugin";
|
|
|
12
12
|
import Options from "./Options";
|
|
13
13
|
import Elements from "./Elements";
|
|
14
14
|
import ColorScale from "./ColorScale";
|
|
15
|
-
import {compareEpochs, isEmpty, isFunction,
|
|
15
|
+
import {compareEpochs, isEmpty, isFunction, pointInRegion} from "./util";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Stanford diagram plugin
|
|
@@ -173,29 +173,6 @@ export default class Stanford extends Plugin {
|
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
xvCustom(d, xyValue): number {
|
|
177
|
-
const $$ = this;
|
|
178
|
-
const {axis, config} = $$;
|
|
179
|
-
let value = xyValue ? d[xyValue] : $$.getBaseValue(d);
|
|
180
|
-
|
|
181
|
-
if (axis.isTimeSeries()) {
|
|
182
|
-
value = parseDate.call($$, value);
|
|
183
|
-
} else if (axis.isCategorized() && isString(value)) {
|
|
184
|
-
value = config.axis_x_categories.indexOf(d.value);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return Math.ceil($$.scale.x(value));
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
yvCustom(d, xyValue): number {
|
|
191
|
-
const $$ = this;
|
|
192
|
-
const {scale} = $$;
|
|
193
|
-
const yScale = d.axis && d.axis === "y2" ? scale.y2 : scale.y;
|
|
194
|
-
const value = xyValue ? d[xyValue] : $$.getBaseValue(d);
|
|
195
|
-
|
|
196
|
-
return Math.ceil(yScale(value));
|
|
197
|
-
}
|
|
198
|
-
|
|
199
176
|
initStanfordData(): void {
|
|
200
177
|
const {config} = this;
|
|
201
178
|
const target = this.$$.data.targets[0];
|
|
@@ -139,7 +139,7 @@ export default class TableView extends Plugin {
|
|
|
139
139
|
}</tr>`;
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
-
const rx =
|
|
142
|
+
const rx = /(<\/?(script|img)[^>]*>|<[^>]+><\/[^>]+>)/ig;
|
|
143
143
|
const r = tplProcess(tpl.body, {
|
|
144
144
|
...config,
|
|
145
145
|
title: config.title || $$.config.title_text || "",
|
|
@@ -158,7 +158,7 @@ export default class TableView extends Plugin {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
$willDestroy(): void {
|
|
161
|
-
this.element.parentNode
|
|
161
|
+
this.element.parentNode?.removeChild(this.element);
|
|
162
162
|
|
|
163
163
|
// remove default css style when left one chart instance
|
|
164
164
|
if (this.$$.charts.length === 1) {
|
|
@@ -46,6 +46,7 @@ export default {
|
|
|
46
46
|
* - **log** type:
|
|
47
47
|
* - the x values specified by [`data.x`](#.data%25E2%2580%25A4x)(or by any equivalent option), must be exclusively-positive.
|
|
48
48
|
* - x axis min value should be >= 0.
|
|
49
|
+
* - for 'category' type, `data.xs` option isn't supported.
|
|
49
50
|
*
|
|
50
51
|
* @name axis․x․type
|
|
51
52
|
* @memberof Options
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
+
import type {RegionsType} from "../../../../types/types";
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* main config options
|
|
7
9
|
*/
|
|
@@ -395,15 +397,23 @@ export default {
|
|
|
395
397
|
* @memberof Options
|
|
396
398
|
* @type {Array}
|
|
397
399
|
* @default []
|
|
400
|
+
* @see [Demo](https://naver.github.io/billboard.js/demo/#Region.RegionLabel)
|
|
398
401
|
* @example
|
|
399
402
|
* regions: [
|
|
400
403
|
* {
|
|
401
404
|
* axis: "x",
|
|
402
405
|
* start: 1,
|
|
403
406
|
* end: 4,
|
|
404
|
-
* class: "region-1-4"
|
|
407
|
+
* class: "region-1-4",
|
|
408
|
+
* label: {
|
|
409
|
+
* text: "Region Text",
|
|
410
|
+
* x: 5, // position relative of the initial x coordinate
|
|
411
|
+
* y: 5, // position relative of the initial y coordinate
|
|
412
|
+
* color: "red", // color string
|
|
413
|
+
* rotated: true // make text to show in vertical or horizontal
|
|
414
|
+
* }
|
|
405
415
|
* }
|
|
406
416
|
* ]
|
|
407
417
|
*/
|
|
408
|
-
regions: <
|
|
418
|
+
regions: <RegionsType[]> []
|
|
409
419
|
};
|
|
@@ -17,6 +17,13 @@ export default {
|
|
|
17
17
|
* @property {boolean} [point.show=true] Whether to show each point in line.
|
|
18
18
|
* @property {number|Function} [point.r=2.5] The radius size of each point.
|
|
19
19
|
* - **NOTE:** Disabled for 'bubble' type
|
|
20
|
+
* @property {boolean|object} [point.radialGradient=false] Set the radial gradient on point.<br><br>
|
|
21
|
+
* Or customize by giving below object value:
|
|
22
|
+
* - cx {number}: `cx` value (default: `0.3`)
|
|
23
|
+
* - cy {number}: `cy` value (default: `0.3`)
|
|
24
|
+
* - r {number}: `r` value (default: `0.7`)
|
|
25
|
+
* - stops {Array}: Each item should be having `[offset, stop-color, stop-opacity]` values.
|
|
26
|
+
* - (default: `[[0.1, $DATA_COLOR, 1], [0.9, $DATA_COLOR, 0]]`)
|
|
20
27
|
* @property {boolean} [point.focus.expand.enabled=true] Whether to expand each point on focus.
|
|
21
28
|
* @property {number} [point.focus.expand.r=point.r*1.75] The radius size of each point on focus.
|
|
22
29
|
* - **NOTE:** For 'bubble' type, the default is `bubbleSize*1.15`
|
|
@@ -59,6 +66,7 @@ export default {
|
|
|
59
66
|
* (ex. `<polygon points='2.5 0 0 5 5 5'></polygon>`)
|
|
60
67
|
* @see [Demo: point type](https://naver.github.io/billboard.js/demo/#Point.RectanglePoints)
|
|
61
68
|
* @see [Demo: point focus only](https://naver.github.io/billboard.js/demo/#Point.FocusOnly)
|
|
69
|
+
* @see [Demo: point radialGradient](https://naver.github.io/billboard.js/demo/#Point.RadialGradientPoint)
|
|
62
70
|
* @see [Demo: point sensitivity](https://naver.github.io/billboard.js/demo/#Point.PointSensitivity)
|
|
63
71
|
* @example
|
|
64
72
|
* point: {
|
|
@@ -71,6 +79,32 @@ export default {
|
|
|
71
79
|
* return r;
|
|
72
80
|
* },
|
|
73
81
|
*
|
|
82
|
+
* // will generate follwing radialGradient:
|
|
83
|
+
* // for more info: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/radialGradient
|
|
84
|
+
* // <radualGradient cx="0.3" cy="0.3" r="0.7">
|
|
85
|
+
* // <stop offset="0.1" stop-color="$DATA_COLOR" stop-opacity="1"></stop>
|
|
86
|
+
* // <stop offset="0.9" stop-color="$DATA_COLOR" stop-opacity="0"></stop>
|
|
87
|
+
* // </radialrGradient>
|
|
88
|
+
* radialGradient: true,
|
|
89
|
+
*
|
|
90
|
+
* // Or customized gradient
|
|
91
|
+
* radialGradient: {
|
|
92
|
+
* cx: 0.3, // cx attributes
|
|
93
|
+
* cy: 0.5, // cy attributes
|
|
94
|
+
* r: 0.7, // r attributes
|
|
95
|
+
* stops: [
|
|
96
|
+
* // offset, stop-color, stop-opacity
|
|
97
|
+
* [0, "#7cb5ec", 1],
|
|
98
|
+
*
|
|
99
|
+
* // setting 'null' for stop-color, will set its original data color
|
|
100
|
+
* [0.5, null, 0],
|
|
101
|
+
*
|
|
102
|
+
* // setting 'function' for stop-color, will pass data id as argument.
|
|
103
|
+
* // It should return color string or null value
|
|
104
|
+
* [1, function(id) { return id === "data1" ? "red" : "blue"; }, 0],
|
|
105
|
+
* ]
|
|
106
|
+
* },
|
|
107
|
+
*
|
|
74
108
|
* focus: {
|
|
75
109
|
* expand: {
|
|
76
110
|
* enabled: true,
|
|
@@ -117,6 +151,13 @@ export default {
|
|
|
117
151
|
*/
|
|
118
152
|
point_show: true,
|
|
119
153
|
point_r: 2.5,
|
|
154
|
+
point_radialGradient: <
|
|
155
|
+
boolean | {
|
|
156
|
+
cx?: number;
|
|
157
|
+
cy?: number;
|
|
158
|
+
r?: number;
|
|
159
|
+
stops?: [number, string | null | Function, number]
|
|
160
|
+
}> false,
|
|
120
161
|
point_sensitivity: <number|"radius"|((d: IDataPoint) => number)> 10,
|
|
121
162
|
point_focus_expand_enabled: true,
|
|
122
163
|
point_focus_expand_r: <number|undefined> undefined,
|
|
@@ -22,9 +22,9 @@ export default {
|
|
|
22
22
|
* Specified function receives x of the data point to show.
|
|
23
23
|
* @property {Function} [tooltip.format.name] Set format for the name of each data in tooltip.<br>
|
|
24
24
|
* Specified function receives name, ratio, id and index of the data point to show. ratio will be undefined if the chart is not donut/pie/gauge.
|
|
25
|
-
* @property {Function} [tooltip.format.value] Set format for the value of each data in tooltip. If undefined returned, the row of that value will be skipped to be called.
|
|
25
|
+
* @property {Function} [tooltip.format.value] Set format for the value of each data value in tooltip. If undefined returned, the row of that value will be skipped to be called.
|
|
26
26
|
* - Will pass following arguments to the given function:
|
|
27
|
-
* - `value {string}`: Value of the data point
|
|
27
|
+
* - `value {string}`: Value of the data point. If data row contains multiple or ranged(ex. candlestick, area range, etc.) value, formatter will be called as value length.
|
|
28
28
|
* - `ratio {number}`: Ratio of the data point in the `pie/donut/gauge` and `area/bar` when contains grouped data. Otherwise is `undefined`.
|
|
29
29
|
* - `id {string}`: id of the data point
|
|
30
30
|
* - `index {number}`: Index of the data point
|
|
@@ -63,7 +63,7 @@ export default {
|
|
|
63
63
|
* - The value array length should match with the data length
|
|
64
64
|
* @property {boolean} [tooltip.init.show=false] Show tooltip at the initialization.
|
|
65
65
|
* @property {number} [tooltip.init.x=0] Set x Axis index(or index for Arc(donut, gauge, pie) types) to be shown at the initialization.
|
|
66
|
-
* @property {object} [tooltip.init.position
|
|
66
|
+
* @property {object} [tooltip.init.position] Set the position of tooltip at the initialization.
|
|
67
67
|
* @property {Function} [tooltip.onshow] Set a callback that will be invoked before the tooltip is shown.
|
|
68
68
|
* @property {Function} [tooltip.onhide] Set a callback that will be invoked before the tooltip is hidden.
|
|
69
69
|
* @property {Function} [tooltip.onshown] Set a callback that will be invoked after the tooltip is shown
|
|
@@ -89,6 +89,9 @@ export default {
|
|
|
89
89
|
* format: {
|
|
90
90
|
* title: function(x) { return "Data " + x; },
|
|
91
91
|
* name: function(name, ratio, id, index) { return name; },
|
|
92
|
+
*
|
|
93
|
+
* // If data row contains multiple or ranged(ex. candlestick, area range, etc.) value,
|
|
94
|
+
* // formatter will be called as value length times.
|
|
92
95
|
* value: function(value, ratio, id, index) { return ratio; }
|
|
93
96
|
* },
|
|
94
97
|
* position: function(data, width, height, element, pos) {
|
|
@@ -155,10 +158,10 @@ export default {
|
|
|
155
158
|
* // show at the initialization
|
|
156
159
|
* init: {
|
|
157
160
|
* show: true,
|
|
158
|
-
* x: 2, // x Axis index(or index for Arc(donut, gauge, pie) types)
|
|
161
|
+
* x: 2, // x Axis index (or index for Arc(donut, gauge, pie) types)
|
|
159
162
|
* position: {
|
|
160
|
-
* top: "150px",
|
|
161
|
-
* left:
|
|
163
|
+
* top: "150px", // specify as number or as string with 'px' unit string
|
|
164
|
+
* left: 250 // specify as number or as string with 'px' unit string
|
|
162
165
|
* }
|
|
163
166
|
* },
|
|
164
167
|
*
|
|
@@ -212,10 +215,7 @@ export default {
|
|
|
212
215
|
> {},
|
|
213
216
|
tooltip_init_show: false,
|
|
214
217
|
tooltip_init_x: 0,
|
|
215
|
-
tooltip_init_position:
|
|
216
|
-
top: "0px",
|
|
217
|
-
left: "50px"
|
|
218
|
-
},
|
|
218
|
+
tooltip_init_position: undefined,
|
|
219
219
|
tooltip_linked: false,
|
|
220
220
|
tooltip_linked_name: "",
|
|
221
221
|
tooltip_onshow: () => {},
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
+
import type {DataRegionsType} from "../../../../types/types";
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* Axis based chart data config options
|
|
7
9
|
*/
|
|
@@ -128,7 +130,7 @@ export default {
|
|
|
128
130
|
* }
|
|
129
131
|
* }
|
|
130
132
|
*/
|
|
131
|
-
data_regions: <
|
|
133
|
+
data_regions: <DataRegionsType> {},
|
|
132
134
|
|
|
133
135
|
/**
|
|
134
136
|
* Set the stacking to be normalized
|
|
@@ -655,7 +655,11 @@ export default {
|
|
|
655
655
|
* {name: "www.site4.com", upload: 400, download: 100, total: 500}
|
|
656
656
|
* ],
|
|
657
657
|
* keys: {
|
|
658
|
-
* //
|
|
658
|
+
* // case 1: specify 'x' key for category axis
|
|
659
|
+
* x: "name", // 'name' key will be used as category x axis values
|
|
660
|
+
* value: ["upload", "download"]
|
|
661
|
+
*
|
|
662
|
+
* // case 2: without 'x' key for non-category axis
|
|
659
663
|
* value: ["upload", "download"]
|
|
660
664
|
* }
|
|
661
665
|
* }
|
|
@@ -857,7 +861,11 @@ export default {
|
|
|
857
861
|
* {name: "www.site4.com", upload: 400, download: 100, total: 500}
|
|
858
862
|
* ],
|
|
859
863
|
* keys: {
|
|
860
|
-
* //
|
|
864
|
+
* // case 1: specify 'x' key for category axis
|
|
865
|
+
* x: "name", // 'name' key will be used as category x axis values
|
|
866
|
+
* value: ["upload", "download"]
|
|
867
|
+
*
|
|
868
|
+
* // case 2: without 'x' key for non-category axis
|
|
861
869
|
* value: ["upload", "download"]
|
|
862
870
|
* }
|
|
863
871
|
* }
|
|
@@ -18,9 +18,10 @@ export default {
|
|
|
18
18
|
* @property {boolean} [area.front=true] Set area node to be positioned over line node.
|
|
19
19
|
* @property {boolean|object} [area.linearGradient=false] Set the linear gradient on area.<br><br>
|
|
20
20
|
* Or customize by giving below object value:
|
|
21
|
-
* - x {Array}: `x1`, `x2` value
|
|
22
|
-
* - y {Array}: `y1`, `y2` value
|
|
21
|
+
* - x {Array}: `x1`, `x2` value (default: `[0, 0]`)
|
|
22
|
+
* - y {Array}: `y1`, `y2` value (default: `[0, 1]`)
|
|
23
23
|
* - stops {Array}: Each item should be having `[offset, stop-color, stop-opacity]` values.
|
|
24
|
+
* - (default: `[[0, $DATA_COLOR, 1], [1, $DATA_COLOR, 0]]`)
|
|
24
25
|
* @property {boolean} [area.zerobased=true] Set if min or max value will be 0 on area chart.
|
|
25
26
|
* @see [MDN's <linearGradient>](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient), [<stop>](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/stop)
|
|
26
27
|
* @see [Demo](https://naver.github.io/billboard.js/demo/#Chart.AreaChart)
|
|
@@ -37,6 +38,7 @@ export default {
|
|
|
37
38
|
* front: false,
|
|
38
39
|
*
|
|
39
40
|
* // will generate follwing linearGradient:
|
|
41
|
+
* // for more info: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient
|
|
40
42
|
* // <linearGradient x1="0" x2="0" y1="0" y2="1">
|
|
41
43
|
* // <stop offset="0" stop-color="$DATA_COLOR" stop-opacity="1"></stop>
|
|
42
44
|
* // <stop offset="1" stop-color="$DATA_COLOR" stop-opacity="0"></stop>
|
|
@@ -65,7 +67,11 @@ export default {
|
|
|
65
67
|
area_below: false,
|
|
66
68
|
area_front: true,
|
|
67
69
|
area_linearGradient: <
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
boolean | {
|
|
71
|
+
x?: [number, number];
|
|
72
|
+
y?:[number, number];
|
|
73
|
+
stops?: [number, string | null | Function, number]
|
|
74
|
+
}
|
|
75
|
+
> false,
|
|
70
76
|
area_zerobased: true
|
|
71
77
|
};
|
|
@@ -17,9 +17,10 @@ export default {
|
|
|
17
17
|
* @property {number} [bar.label.threshold=0] Set threshold ratio to show/hide labels.
|
|
18
18
|
* @property {boolean|object} [bar.linearGradient=false] Set the linear gradient on bar.<br><br>
|
|
19
19
|
* Or customize by giving below object value:
|
|
20
|
-
* - x {Array}: `x1`, `x2` value
|
|
21
|
-
* - y {Array}: `y1`, `y2` value
|
|
20
|
+
* - x {Array}: `x1`, `x2` value (default: `[0, 0]`)
|
|
21
|
+
* - y {Array}: `y1`, `y2` value (default: `[0, 1]`)
|
|
22
22
|
* - stops {Array}: Each item should be having `[offset, stop-color, stop-opacity]` values.
|
|
23
|
+
* - (default: `[[0, $DATA_COLOR, 1], [1, $DATA_COLOR, 0]]`)
|
|
23
24
|
* @property {boolean} [bar.overlap=false] Bars will be rendered at same position, which will be overlapped each other. (for non-grouped bars only)
|
|
24
25
|
* @property {number} [bar.padding=0] The padding pixel value between each bar.
|
|
25
26
|
* @property {number} [bar.radius] Set the radius of bar edge in pixel.
|
|
@@ -53,6 +54,7 @@ export default {
|
|
|
53
54
|
* },
|
|
54
55
|
*
|
|
55
56
|
* // will generate follwing linearGradient:
|
|
57
|
+
* // for more info: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient
|
|
56
58
|
* // <linearGradient x1="0" x2="0" y1="0" y2="1">
|
|
57
59
|
* // <stop offset="0" stop-color="$DATA_COLOR" stop-opacity="1"></stop>
|
|
58
60
|
* // <stop offset="1" stop-color="$DATA_COLOR" stop-opacity="0"></stop>
|
|
@@ -121,8 +123,12 @@ export default {
|
|
|
121
123
|
bar_indices_removeNull: false,
|
|
122
124
|
bar_label_threshold: 0,
|
|
123
125
|
bar_linearGradient: <
|
|
124
|
-
|
|
125
|
-
|
|
126
|
+
boolean | {
|
|
127
|
+
x?: [number, number];
|
|
128
|
+
y?:[number, number];
|
|
129
|
+
stops?: [number, string | null | Function, number]
|
|
130
|
+
}
|
|
131
|
+
> false,
|
|
126
132
|
bar_overlap: false,
|
|
127
133
|
bar_padding: 0,
|
|
128
134
|
bar_radius: <number|{ratio: number}|undefined> undefined,
|
package/src/module/Cache.ts
CHANGED
|
@@ -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 {
|
|
5
|
+
import {isString, isValue} from "./util";
|
|
6
6
|
import type {DataRow} from "../../types/types";
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -45,7 +45,8 @@ export default class Cache {
|
|
|
45
45
|
* @private
|
|
46
46
|
*/
|
|
47
47
|
remove(key: string | string[]) {
|
|
48
|
-
|
|
48
|
+
(isString(key) ? [key] : key)
|
|
49
|
+
.forEach(v => delete this.cache[v]);
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
/**
|
|
@@ -55,8 +56,9 @@ export default class Cache {
|
|
|
55
56
|
* @returns {*}
|
|
56
57
|
* @private
|
|
57
58
|
*/
|
|
58
|
-
get(key: string, isDataType = false): any | null {
|
|
59
|
-
|
|
59
|
+
get(key: string|string[], isDataType = false): any | null {
|
|
60
|
+
// when is isDataType, key should be string array
|
|
61
|
+
if (isDataType && Array.isArray(key)) {
|
|
60
62
|
const targets: any[] = [];
|
|
61
63
|
|
|
62
64
|
for (let i = 0, id; (id = key[i]); i++) {
|
|
@@ -67,7 +69,7 @@ export default class Cache {
|
|
|
67
69
|
|
|
68
70
|
return targets;
|
|
69
71
|
} else {
|
|
70
|
-
const value = this.cache[key];
|
|
72
|
+
const value = this.cache[key as string];
|
|
71
73
|
|
|
72
74
|
return isValue(value) ? value : null;
|
|
73
75
|
}
|
package/src/module/browser.ts
CHANGED
|
@@ -14,22 +14,42 @@ export {
|
|
|
14
14
|
requestIdleCallback, cancelIdleCallback
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Get global object
|
|
19
|
+
* @returns {object} window object
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
function getGlobal() {
|
|
23
|
+
return (typeof globalThis === "object" && globalThis !== null && globalThis.Object === Object && globalThis) ||
|
|
19
24
|
(typeof global === "object" && global !== null && global.Object === Object && global) ||
|
|
20
|
-
(typeof self === "object" && self !== null && self.Object === Object && self)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
})();
|
|
24
|
-
/* eslint-enable no-new-func, no-undef */
|
|
25
|
+
(typeof self === "object" && self !== null && self.Object === Object && self) ||
|
|
26
|
+
Function("return this")();
|
|
27
|
+
}
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Get fallback object
|
|
31
|
+
* @param {object} w global object
|
|
32
|
+
* @returns {Array} fallback object array
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
function getFallback(w) {
|
|
36
|
+
const hasRAF = typeof w?.requestAnimationFrame === "function";
|
|
37
|
+
const hasRIC = typeof w?.requestIdleCallback === "function";
|
|
29
38
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
return [
|
|
40
|
+
hasRAF ? w.requestAnimationFrame : (cb => setTimeout(cb, 1)),
|
|
41
|
+
hasRAF ? w.cancelAnimationFrame : (id => clearTimeout(id)),
|
|
42
|
+
hasRIC ? w.requestIdleCallback : requestAnimationFrame,
|
|
43
|
+
hasRIC ? w.cancelIdleCallback : cancelAnimationFrame
|
|
44
|
+
];
|
|
45
|
+
}
|
|
34
46
|
|
|
47
|
+
const win = getGlobal();
|
|
35
48
|
const doc = win?.document;
|
|
49
|
+
|
|
50
|
+
const [
|
|
51
|
+
requestAnimationFrame,
|
|
52
|
+
cancelAnimationFrame,
|
|
53
|
+
requestIdleCallback,
|
|
54
|
+
cancelIdleCallback
|
|
55
|
+
] = getFallback(win);
|
package/src/module/util.ts
CHANGED
|
@@ -53,7 +53,7 @@ export {
|
|
|
53
53
|
notEmpty,
|
|
54
54
|
parseDate,
|
|
55
55
|
runUntil,
|
|
56
|
-
|
|
56
|
+
sanitize,
|
|
57
57
|
setTextValue,
|
|
58
58
|
sortValue,
|
|
59
59
|
toArray,
|
|
@@ -168,9 +168,9 @@ function endall(transition, cb: Function): void {
|
|
|
168
168
|
* @returns {string}
|
|
169
169
|
* @private
|
|
170
170
|
*/
|
|
171
|
-
function
|
|
171
|
+
function sanitize(str: string): string {
|
|
172
172
|
return isString(str) ?
|
|
173
|
-
str.replace(
|
|
173
|
+
str.replace(/<(script|img)?/ig, "<").replace(/(script)?>/ig, ">") : str;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
/**
|
|
@@ -266,7 +266,11 @@ function getPathBox(
|
|
|
266
266
|
*/
|
|
267
267
|
function getPointer(event, element?: Element): number[] {
|
|
268
268
|
const touches = event && (event.touches || (event.sourceEvent && event.sourceEvent.touches))?.[0];
|
|
269
|
-
|
|
269
|
+
let pointer = [0, 0];
|
|
270
|
+
|
|
271
|
+
try {
|
|
272
|
+
pointer = d3Pointer(touches || event, element);
|
|
273
|
+
} catch (e) {}
|
|
270
274
|
|
|
271
275
|
return pointer.map(v => (isNaN(v) ? 0 : v));
|
|
272
276
|
}
|