billboard.js 3.7.5 → 3.8.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/dist/billboard.css +1 -1
- package/dist/billboard.js +468 -268
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +2 -2
- package/dist/billboard.pkgd.js +512 -284
- 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 +36 -19
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.js +35 -19
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +32 -18
- package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.js +33 -18
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +45 -17
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +80 -35
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +80 -36
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +77 -35
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +133 -69
- 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 +349 -213
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +10 -11
- 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 +28 -28
- 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/convert.ts +6 -3
- package/src/ChartInternal/data/data.ts +19 -15
- package/src/ChartInternal/data/load.ts +19 -4
- package/src/ChartInternal/interactions/eventrect.ts +3 -2
- 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/region.ts +9 -9
- 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/point.ts +3 -2
- package/src/Plugin/sparkline/index.ts +9 -1
- 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/resolver/axis.ts +2 -4
- package/src/module/browser.ts +13 -5
- package/src/module/generator.ts +3 -3
- package/src/module/util.ts +2 -2
- package/types/axis.d.ts +8 -7
- package/types/chart.d.ts +6 -1
- package/types/options.d.ts +7 -4
- package/src/Chart/api/grid.x.ts +0 -90
- package/src/Chart/api/grid.y.ts +0 -92
package/src/Chart/api/load.ts
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
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 {requestIdleCallback} from "../../module/browser";
|
|
6
6
|
import {isString, isArray} from "../../module/util";
|
|
7
|
+
import {callDone} from "../../ChartInternal/data/load";
|
|
7
8
|
|
|
8
9
|
export default {
|
|
9
10
|
/**
|
|
@@ -19,23 +20,29 @@ export default {
|
|
|
19
20
|
* @memberof Chart
|
|
20
21
|
* @param {object} args The object can consist with following members:<br>
|
|
21
22
|
*
|
|
22
|
-
* | Key | Description |
|
|
23
|
-
* | --- | --- |
|
|
24
|
-
* |
|
|
25
|
-
* |
|
|
26
|
-
* |
|
|
27
|
-
* |
|
|
28
|
-
* |
|
|
29
|
-
* |
|
|
30
|
-
* |
|
|
31
|
-
* |
|
|
32
|
-
* |
|
|
33
|
-
* |
|
|
34
|
-
* |
|
|
35
|
-
* |
|
|
36
|
-
* |
|
|
37
|
-
* |
|
|
38
|
-
* |
|
|
23
|
+
* | Key | Type | Description |
|
|
24
|
+
* | --- | --- | --- |
|
|
25
|
+
* | columns | Array | The `columns` data will be loaded. If data that has the same target id is given, the chart will be updated. Otherwise, new target will be added |
|
|
26
|
+
* | json | Array | The `json` data will be loaded. If data that has the same target id is given, the chart will be updated. Otherwise, new target will be added |
|
|
27
|
+
* | rows | Array | The `rows` data will be loaded. If data that has the same target id is given, the chart will be updated. Otherwise, new target will be added |
|
|
28
|
+
* | url | string | The data from `url` will be loaded. If data that has the same target id is given, the chart will be updated. Otherwise, new target will be added |
|
|
29
|
+
* | | | |
|
|
30
|
+
* | append | boolean | Load data appending it to the current dataseries.<br>If the existing chart has`x` value, should provide with corresponding `x` value for newly loaded data. |
|
|
31
|
+
* | axes | Object | The axes specified by data.axes will be updated. axes must be Object that has target id as keys. |
|
|
32
|
+
* | categories | Array | The categories specified by axis.x.categories or data.x will be updated. categories must be Array. |
|
|
33
|
+
* | classes | Object | The classes specified by data.classes will be updated. classes must be Object that has target id as keys. |
|
|
34
|
+
* | colors | Object | The colors specified by data.colors will be updated. colors must be Object that has target id as keys. |
|
|
35
|
+
* | data | Obejct | Data objects to be loaded. Checkout the example. |
|
|
36
|
+
* | done | Function | The specified function will be called after data loaded.|
|
|
37
|
+
* | headers | string | Set request header if loading via `data.url`.<br>@see [data․headers](Options.html#.data%25E2%2580%25A4headers) |
|
|
38
|
+
* | keys | Object | Choose which JSON objects keys correspond to desired data.<br>**NOTE:** Only for JSON object given as array.<br>@see [data․keys](Options.html#.data%25E2%2580%25A4keys) |
|
|
39
|
+
* | mimeType | string | Set 'json' if loading JSON via url.<br>@see [data․mimeType](Options.html#.data%25E2%2580%25A4mimeType) |
|
|
40
|
+
* | names | Object | Same as data.names() |
|
|
41
|
+
* | resizeAfter | boolean | Resize after the load. Default value is `false`.<br>- This option won't call `onresize` neither `onresized`.<br>- When set to 'true', will call `.flush(true)` at the end of load. |
|
|
42
|
+
* | type | string | The type of targets will be updated. |
|
|
43
|
+
* | types | Object | The types of targets will be updated. |
|
|
44
|
+
* | unload | Array | Specify the data will be unloaded before loading new data. If true given, all of data will be unloaded. If target ids given as String or Array, specified targets will be unloaded. If absent or false given, unload will not occur. |
|
|
45
|
+
* | xs | string | Same as data.xs option |
|
|
39
46
|
* @see [Demo](https://naver.github.io/billboard.js/demo/#Data.DataFromURL)
|
|
40
47
|
* @example
|
|
41
48
|
* // Load data1 and unload data2 and data3
|
|
@@ -47,6 +54,7 @@ export default {
|
|
|
47
54
|
* unload: ["data2", "data3"],
|
|
48
55
|
* url: "...",
|
|
49
56
|
* done: function() { ... }
|
|
57
|
+
* resizeAfter: true // will resize after load
|
|
50
58
|
* });
|
|
51
59
|
* @example
|
|
52
60
|
* const chart = bb.generate({
|
|
@@ -171,7 +179,7 @@ export default {
|
|
|
171
179
|
$$.unload($$.mapToTargetIds(args.unload === true ? null : args.unload), () => {
|
|
172
180
|
// to mitigate improper rendering for multiple consecutive calls
|
|
173
181
|
// https://github.com/naver/billboard.js/issues/2121
|
|
174
|
-
|
|
182
|
+
requestIdleCallback(() => $$.loadFromArgs(args));
|
|
175
183
|
});
|
|
176
184
|
} else {
|
|
177
185
|
$$.api.tooltip.hide();
|
|
@@ -193,13 +201,15 @@ export default {
|
|
|
193
201
|
* | --- | --- | --- |
|
|
194
202
|
* | ids | String | Array | Target id data to be unloaded. If not given, all data will be unloaded. |
|
|
195
203
|
* | done | Fuction | Callback after data is unloaded. |
|
|
204
|
+
* | resizeAfter | boolean | Resize after the unload. Default value is `false`.<br>- This option won't call `onresize` neither `onresized`.<br>- When set to 'true', will call `.flush(true)` at the end of unload. |
|
|
196
205
|
* @example
|
|
197
206
|
* // Unload data2 and data3
|
|
198
207
|
* chart.unload({
|
|
199
208
|
* ids: ["data2", "data3"],
|
|
200
209
|
* done: function() {
|
|
201
210
|
* // called after the unloaded
|
|
202
|
-
* }
|
|
211
|
+
* },
|
|
212
|
+
* resizeAfter: true // will resize after unload
|
|
203
213
|
* });
|
|
204
214
|
*/
|
|
205
215
|
unload(argsValue): void {
|
|
@@ -222,7 +232,7 @@ export default {
|
|
|
222
232
|
});
|
|
223
233
|
|
|
224
234
|
$$.cache.remove(ids);
|
|
225
|
-
args.done
|
|
235
|
+
callDone.call($$, args.done, args.resizeAfter);
|
|
226
236
|
});
|
|
227
237
|
}
|
|
228
238
|
};
|
package/src/Chart/api/regions.ts
CHANGED
|
@@ -3,9 +3,33 @@
|
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
5
|
import {$REGION} from "../../config/classes";
|
|
6
|
-
import {getOption, extend} from "../../module/util";
|
|
6
|
+
import {getOption, extend, isTabVisible} from "../../module/util";
|
|
7
7
|
|
|
8
|
-
type RegionsParam = {axis?:
|
|
8
|
+
type RegionsParam = {axis?: "add" | "update", class?: string, start?: number, end?: number}[];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Region add/update function
|
|
12
|
+
* @param {Array} regions Regions will be replaced with this argument. The format of this argument is the same as regions.
|
|
13
|
+
* @param {boolean} isAdd If true, add new regions, otherwise update regions
|
|
14
|
+
* @returns {Array} regions
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
function regionsFn(regions: RegionsParam, isAdd = false): RegionsParam {
|
|
18
|
+
const $$ = this.internal;
|
|
19
|
+
const {config} = $$;
|
|
20
|
+
const withTransition = config.transition_duration && isTabVisible();
|
|
21
|
+
|
|
22
|
+
if (!regions) {
|
|
23
|
+
return config.regions;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
config.regions = isAdd ? config.regions.concat(regions) : regions;
|
|
27
|
+
|
|
28
|
+
$$.updateRegion();
|
|
29
|
+
$$.redrawRegion(withTransition);
|
|
30
|
+
|
|
31
|
+
return isAdd ? config.regions : regions;
|
|
32
|
+
}
|
|
9
33
|
|
|
10
34
|
/**
|
|
11
35
|
* Update regions.
|
|
@@ -22,17 +46,7 @@ type RegionsParam = {axis?: string, class?: string, start?: number, end?: number
|
|
|
22
46
|
* ]);
|
|
23
47
|
*/
|
|
24
48
|
const regions = function(regions: RegionsParam): RegionsParam {
|
|
25
|
-
|
|
26
|
-
const {config} = $$;
|
|
27
|
-
|
|
28
|
-
if (!regions) {
|
|
29
|
-
return config.regions;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
config.regions = regions;
|
|
33
|
-
$$.redrawWithoutRescale();
|
|
34
|
-
|
|
35
|
-
return regions;
|
|
49
|
+
return regionsFn.bind(this)(regions);
|
|
36
50
|
};
|
|
37
51
|
|
|
38
52
|
extend(regions, {
|
|
@@ -57,17 +71,7 @@ extend(regions, {
|
|
|
57
71
|
*]);
|
|
58
72
|
*/
|
|
59
73
|
add: function(regions: RegionsParam): RegionsParam {
|
|
60
|
-
|
|
61
|
-
const {config} = $$;
|
|
62
|
-
|
|
63
|
-
if (!regions) {
|
|
64
|
-
return config.regions;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
config.regions = config.regions.concat(regions);
|
|
68
|
-
$$.redrawWithoutRescale();
|
|
69
|
-
|
|
70
|
-
return config.regions;
|
|
74
|
+
return regionsFn.bind(this)(regions, true);
|
|
71
75
|
},
|
|
72
76
|
|
|
73
77
|
/**
|
package/src/Chart/api/zoom.ts
CHANGED
|
@@ -10,14 +10,21 @@ import {extend, getMinMax, isDefined, isObject, parseDate} from "../../module/ut
|
|
|
10
10
|
* @param {Array} domain Target domain value
|
|
11
11
|
* @param {Array} current Current zoom domain value
|
|
12
12
|
* @param {Array} range Zoom range value
|
|
13
|
+
* @param {boolean} isInverted Whether the axis is inverted or not
|
|
13
14
|
* @returns {boolean}
|
|
14
15
|
* @private
|
|
15
16
|
*/
|
|
16
|
-
function withinRange(
|
|
17
|
+
function withinRange(
|
|
18
|
+
domain: (number|Date)[], current, range: number[], isInverted = false
|
|
19
|
+
): boolean {
|
|
17
20
|
const [min, max] = range;
|
|
18
21
|
|
|
19
22
|
return domain.every((v, i) => (
|
|
20
|
-
i === 0 ? (
|
|
23
|
+
i === 0 ? (
|
|
24
|
+
isInverted ? +v <= min : +v >= min
|
|
25
|
+
) : (
|
|
26
|
+
isInverted ? +v >= max : +v <= max
|
|
27
|
+
)
|
|
21
28
|
) && !(domain.every((v, i) => v === current[i])));
|
|
22
29
|
}
|
|
23
30
|
|
|
@@ -45,6 +52,7 @@ const zoom = function(domainValue?: (Date|number|string)[]): (Date|number)[]|und
|
|
|
45
52
|
const $$ = this.internal;
|
|
46
53
|
const {$el, axis, config, org, scale} = $$;
|
|
47
54
|
const isRotated = config.axis_rotated;
|
|
55
|
+
const isInverted = config.axis_x_inverted;
|
|
48
56
|
const isCategorized = axis.isCategorized();
|
|
49
57
|
let domain = domainValue;
|
|
50
58
|
|
|
@@ -53,7 +61,14 @@ const zoom = function(domainValue?: (Date|number|string)[]): (Date|number)[]|und
|
|
|
53
61
|
domain = domain.map(x => parseDate.bind($$)(x));
|
|
54
62
|
}
|
|
55
63
|
|
|
56
|
-
|
|
64
|
+
const isWithinRange = withinRange(
|
|
65
|
+
domain as (number|Date)[],
|
|
66
|
+
$$.getZoomDomain(true),
|
|
67
|
+
$$.getZoomDomain(),
|
|
68
|
+
isInverted
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
if (isWithinRange) {
|
|
57
72
|
if (isCategorized) {
|
|
58
73
|
domain = domain.map((v, i) => Number(v) + (i === 0 ? 0 : 1));
|
|
59
74
|
}
|
|
@@ -292,6 +292,7 @@ class Axis {
|
|
|
292
292
|
owner: $$
|
|
293
293
|
}, isX && {
|
|
294
294
|
isCategory,
|
|
295
|
+
isInverted: config.axis_x_inverted,
|
|
295
296
|
tickMultiline: config.axis_x_tick_multiline,
|
|
296
297
|
tickWidth: config.axis_x_tick_width,
|
|
297
298
|
tickTitle: isCategory && config.axis_x_tick_tooltip && $$.api.categories(),
|
|
@@ -379,8 +379,13 @@ export default class AxisRenderer {
|
|
|
379
379
|
|
|
380
380
|
if (!tickWidth || tickWidth <= 0) {
|
|
381
381
|
tickWidth = isLeftRight ? 95 : (
|
|
382
|
-
params.isCategory ?
|
|
383
|
-
|
|
382
|
+
params.isCategory ? (
|
|
383
|
+
Math.ceil(
|
|
384
|
+
params.isInverted ?
|
|
385
|
+
scale(ticks[0]) - scale(ticks[1]) :
|
|
386
|
+
scale(ticks[1]) - scale(ticks[0])
|
|
387
|
+
) - 12
|
|
388
|
+
) : 110
|
|
384
389
|
);
|
|
385
390
|
}
|
|
386
391
|
|
|
@@ -377,7 +377,7 @@ export default class ChartInternal {
|
|
|
377
377
|
|
|
378
378
|
// Set domains for each scale
|
|
379
379
|
if (x) {
|
|
380
|
-
x.domain(sortValue($$.getXDomain($$.data.targets)));
|
|
380
|
+
x.domain(sortValue($$.getXDomain($$.data.targets), !config.axis_x_inverted));
|
|
381
381
|
subX.domain(x.domain());
|
|
382
382
|
|
|
383
383
|
// Save original x domain for zoom update
|
|
@@ -76,6 +76,7 @@ export default {
|
|
|
76
76
|
convertDataToTargets(data: {[key:string]: number|null}[], appendXs: boolean): IData[] {
|
|
77
77
|
const $$ = this;
|
|
78
78
|
const {axis, config, state} = $$;
|
|
79
|
+
const chartType = config.data_type;
|
|
79
80
|
let isCategorized = false;
|
|
80
81
|
let isTimeSeries = false;
|
|
81
82
|
let isCustomX = false;
|
|
@@ -207,9 +208,11 @@ export default {
|
|
|
207
208
|
state.hasPositiveValue = $$.hasPositiveValueInTargets(targets);
|
|
208
209
|
|
|
209
210
|
// set target types
|
|
210
|
-
if (
|
|
211
|
-
$$.
|
|
212
|
-
.filter(id => !(id in config.data_types)
|
|
211
|
+
if (chartType && $$.isValidChartType(chartType)) {
|
|
212
|
+
const targetIds = $$.mapToIds(targets)
|
|
213
|
+
.filter(id => !(id in config.data_types) || !$$.isValidChartType(config.data_types[id]));
|
|
214
|
+
|
|
215
|
+
$$.setTargetType(targetIds, chartType);
|
|
213
216
|
}
|
|
214
217
|
|
|
215
218
|
// cache as original id keyed
|
|
@@ -397,6 +397,7 @@ export default {
|
|
|
397
397
|
getMaxDataCountTarget() {
|
|
398
398
|
let target = this.filterTargetsToShow() || [];
|
|
399
399
|
const length = target.length;
|
|
400
|
+
const isInverted = this.config.axis_x_inverted;
|
|
400
401
|
|
|
401
402
|
if (length > 1) {
|
|
402
403
|
target = target.map(t => t.values)
|
|
@@ -404,7 +405,7 @@ export default {
|
|
|
404
405
|
.map(v => v.x);
|
|
405
406
|
|
|
406
407
|
target = sortValue(getUnique(target))
|
|
407
|
-
.map((x, index) => ({x, index}));
|
|
408
|
+
.map((x, index, array) => ({x, index: isInverted ? array.length - index - 1 : index}));
|
|
408
409
|
} else if (length) {
|
|
409
410
|
target = target[0].values.concat();
|
|
410
411
|
}
|
|
@@ -795,32 +796,35 @@ export default {
|
|
|
795
796
|
const {axis, config} = $$;
|
|
796
797
|
const stepType = config.line_step_type;
|
|
797
798
|
const isCategorized = axis ? axis.isCategorized() : false;
|
|
798
|
-
|
|
799
799
|
const converted = isArray(values) ? values.concat() : [values];
|
|
800
800
|
|
|
801
801
|
if (!(isCategorized || /step\-(after|before)/.test(stepType))) {
|
|
802
802
|
return values;
|
|
803
803
|
}
|
|
804
804
|
|
|
805
|
-
//
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
805
|
+
// when all datas are null, return empty array
|
|
806
|
+
// https://github.com/naver/billboard.js/issues/3124
|
|
807
|
+
if (converted.length) {
|
|
808
|
+
// insert & append cloning first/last value to be fully rendered covering on each gap sides
|
|
809
|
+
const head = converted[0];
|
|
810
|
+
const tail = converted[converted.length - 1];
|
|
811
|
+
const {id} = head;
|
|
812
|
+
let {x} = head;
|
|
813
813
|
|
|
814
|
-
|
|
814
|
+
// insert head
|
|
815
815
|
converted.unshift({x: --x, value: head.value, id});
|
|
816
816
|
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
converted.push({x: ++x, value: tail.value, id});
|
|
817
|
+
isCategorized && stepType === "step-after" &&
|
|
818
|
+
converted.unshift({x: --x, value: head.value, id});
|
|
820
819
|
|
|
821
|
-
|
|
820
|
+
// append tail
|
|
821
|
+
x = tail.x;
|
|
822
822
|
converted.push({x: ++x, value: tail.value, id});
|
|
823
823
|
|
|
824
|
+
isCategorized && stepType === "step-before" &&
|
|
825
|
+
converted.push({x: ++x, value: tail.value, id});
|
|
826
|
+
}
|
|
827
|
+
|
|
824
828
|
return converted;
|
|
825
829
|
},
|
|
826
830
|
|
|
@@ -5,9 +5,24 @@
|
|
|
5
5
|
import {$LEGEND} from "../../config/classes";
|
|
6
6
|
import {endall} from "../../module/util";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Call done callback with resize after transition
|
|
10
|
+
* @param {Function} fn Callback function
|
|
11
|
+
* @param {boolean} resizeAfter Weather to resize chart after the load
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
export function callDone(fn, resizeAfter = false) {
|
|
15
|
+
const $$ = this;
|
|
16
|
+
const {api} = $$;
|
|
17
|
+
|
|
18
|
+
resizeAfter && $$.api.flush(true);
|
|
19
|
+
fn?.call(api);
|
|
20
|
+
}
|
|
21
|
+
|
|
8
22
|
export default {
|
|
9
23
|
load(rawTargets, args): void {
|
|
10
24
|
const $$ = this;
|
|
25
|
+
const {data} = $$;
|
|
11
26
|
const {append} = args;
|
|
12
27
|
let targets = rawTargets;
|
|
13
28
|
|
|
@@ -27,7 +42,7 @@ export default {
|
|
|
27
42
|
}
|
|
28
43
|
|
|
29
44
|
// Update/Add data
|
|
30
|
-
|
|
45
|
+
data.targets.forEach(d => {
|
|
31
46
|
for (let i = 0; i < targets.length; i++) {
|
|
32
47
|
if (d.id === targets[i].id) {
|
|
33
48
|
d.values = append ?
|
|
@@ -39,11 +54,11 @@ export default {
|
|
|
39
54
|
}
|
|
40
55
|
});
|
|
41
56
|
|
|
42
|
-
|
|
57
|
+
data.targets = data.targets.concat(targets); // add remained
|
|
43
58
|
}
|
|
44
59
|
|
|
45
60
|
// Set targets
|
|
46
|
-
$$.updateTargets(
|
|
61
|
+
$$.updateTargets(data.targets);
|
|
47
62
|
|
|
48
63
|
// Redraw with new targets
|
|
49
64
|
$$.redraw({
|
|
@@ -55,7 +70,7 @@ export default {
|
|
|
55
70
|
// Update current state chart type and elements list after redraw
|
|
56
71
|
$$.updateTypesElements();
|
|
57
72
|
|
|
58
|
-
args.done
|
|
73
|
+
callDone.call($$, args.done, args.resizeAfter);
|
|
59
74
|
},
|
|
60
75
|
|
|
61
76
|
loadFromArgs(args): void {
|
|
@@ -28,6 +28,7 @@ export default {
|
|
|
28
28
|
const $$ = this;
|
|
29
29
|
const {config, state, $el} = $$;
|
|
30
30
|
const isMultipleX = $$.isMultipleX();
|
|
31
|
+
const isInverted = config.axis_x_inverted;
|
|
31
32
|
|
|
32
33
|
if ($el.eventRect) {
|
|
33
34
|
$$.updateEventRect($el.eventRect, true);
|
|
@@ -66,8 +67,8 @@ export default {
|
|
|
66
67
|
// Set data and update eventReceiver.data
|
|
67
68
|
const xAxisTickValues = $$.getMaxDataCountTarget();
|
|
68
69
|
|
|
69
|
-
if (!config.data_xSort) {
|
|
70
|
-
xAxisTickValues.sort((a, b) => a.x - b.x);
|
|
70
|
+
if (!config.data_xSort || isInverted) {
|
|
71
|
+
xAxisTickValues.sort((a, b) => (isInverted ? b.x - a.x : a.x - b.x));
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
// update data's index value to be alinged with the x Axis
|
|
@@ -206,7 +206,6 @@ export default {
|
|
|
206
206
|
"M 0 18 A 6 6 0 0 1 6.5 23.5 V 29 A 6 6 0 0 1 0 35 Z M 2 23 V 30 M 4 23 V 30Z"
|
|
207
207
|
];
|
|
208
208
|
|
|
209
|
-
|
|
210
209
|
$$.brush.handle = brush.selectAll(`.${customHandleClass}`)
|
|
211
210
|
.data(isRotated ?
|
|
212
211
|
[{type: "n"}, {type: "s"}] :
|
|
@@ -335,7 +334,9 @@ export default {
|
|
|
335
334
|
*/
|
|
336
335
|
redrawForBrush() {
|
|
337
336
|
const $$ = this;
|
|
338
|
-
const {config: {
|
|
337
|
+
const {config: {
|
|
338
|
+
subchart_onbrush: onBrush, zoom_rescale: withY
|
|
339
|
+
}, scale} = $$;
|
|
339
340
|
|
|
340
341
|
$$.redraw({
|
|
341
342
|
withTransition: false,
|
|
@@ -109,7 +109,7 @@ export default {
|
|
|
109
109
|
$$.state.xTickOffset = $$.axis.x.tickOffset();
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
scale.zoom = $$.
|
|
112
|
+
scale.zoom = $$.getCustomizedXScale(newScale);
|
|
113
113
|
$$.axis.x.scale(scale.zoom);
|
|
114
114
|
|
|
115
115
|
if (rescale) {
|
|
@@ -256,8 +256,15 @@ export default {
|
|
|
256
256
|
const xDomain = subX.domain();
|
|
257
257
|
const delta = 0.015; // arbitrary value
|
|
258
258
|
|
|
259
|
-
const isfullyShown =
|
|
260
|
-
|
|
259
|
+
const isfullyShown = $$.config.axis_x_inverted ? (
|
|
260
|
+
zoomDomain[0] >= xDomain[0] || (zoomDomain[0] + delta) >= xDomain[0]
|
|
261
|
+
) && (
|
|
262
|
+
xDomain[1] >= zoomDomain[1] || xDomain[1] >= (zoomDomain[1] + delta)
|
|
263
|
+
) : (
|
|
264
|
+
zoomDomain[0] <= xDomain[0] || (zoomDomain[0] - delta) <= xDomain[0]
|
|
265
|
+
) && (
|
|
266
|
+
xDomain[1] <= zoomDomain[1] || xDomain[1] <= (zoomDomain[1] - delta)
|
|
267
|
+
);
|
|
261
268
|
|
|
262
269
|
// check if the zoomed chart is fully shown, then reset scale when zoom is out as initial
|
|
263
270
|
if (force || isfullyShown) {
|
|
@@ -83,10 +83,11 @@ export default {
|
|
|
83
83
|
const left = Math.max(30, margin.left) - (isRotated ? 20 : 0);
|
|
84
84
|
const isInner = config.axis_y_inner;
|
|
85
85
|
|
|
86
|
-
const x = isInner
|
|
86
|
+
const x = isInner && !isRotated ? (config.axis_y_label.text ? -20 : -1) :
|
|
87
|
+
(isRotated ? -(1 + left) : -(left - 1));
|
|
87
88
|
const y = -(isRotated ? 20 : margin.top);
|
|
88
89
|
const w = (isRotated ? width + 15 + left : margin.left + 20) + (isInner ? 20 : 0);
|
|
89
|
-
const h = (isRotated ? margin.bottom : (margin.top + height)) + 10;
|
|
90
|
+
const h = (isRotated ? margin.bottom + (config.padding?.mode === "fit" ? 10 : 0) : (margin.top + height)) + 10;
|
|
90
91
|
|
|
91
92
|
node
|
|
92
93
|
.attr("x", x)
|
|
@@ -274,9 +274,10 @@ export default {
|
|
|
274
274
|
* @returns {Array} x Axis domain
|
|
275
275
|
* @private
|
|
276
276
|
*/
|
|
277
|
-
getXDomain(targets
|
|
277
|
+
getXDomain(targets: IData[]): (Date|number)[] {
|
|
278
278
|
const $$ = this;
|
|
279
|
-
const {axis, scale: {x}} = $$;
|
|
279
|
+
const {axis, config, scale: {x}} = $$;
|
|
280
|
+
const isInverted = config.axis_x_inverted;
|
|
280
281
|
const domain = [
|
|
281
282
|
$$.getXDomainMinMax(targets, "min"),
|
|
282
283
|
$$.getXDomainMinMax(targets, "max")
|
|
@@ -309,7 +310,7 @@ export default {
|
|
|
309
310
|
}
|
|
310
311
|
}
|
|
311
312
|
|
|
312
|
-
return [min, max];
|
|
313
|
+
return isInverted ? [max, min] : [min, max];
|
|
313
314
|
},
|
|
314
315
|
|
|
315
316
|
updateXDomain(targets, withUpdateXDomain, withUpdateOrgXDomain, withTrim, domain) {
|
|
@@ -318,7 +319,7 @@ export default {
|
|
|
318
319
|
const zoomEnabled = config.zoom_enabled;
|
|
319
320
|
|
|
320
321
|
if (withUpdateOrgXDomain) {
|
|
321
|
-
x.domain(domain || sortValue($$.getXDomain(targets)));
|
|
322
|
+
x.domain(domain || sortValue($$.getXDomain(targets), !config.axis_x_inverted));
|
|
322
323
|
org.xDomain = x.domain();
|
|
323
324
|
|
|
324
325
|
zoomEnabled && $$.zoom.updateScaleExtent();
|
|
@@ -341,16 +342,24 @@ export default {
|
|
|
341
342
|
return x.domain();
|
|
342
343
|
},
|
|
343
344
|
|
|
345
|
+
/**
|
|
346
|
+
* Trim x domain when given domain surpasses the range
|
|
347
|
+
* @param {Array} domain Domain value
|
|
348
|
+
* @returns {Array} Trimed domain if given domain is out of range
|
|
349
|
+
* @private
|
|
350
|
+
*/
|
|
344
351
|
trimXDomain(domain) {
|
|
345
|
-
const
|
|
352
|
+
const $$ = this;
|
|
353
|
+
const isInverted = $$.config.axis_x_inverted;
|
|
354
|
+
const zoomDomain = $$.getZoomDomain();
|
|
346
355
|
const [min, max] = zoomDomain;
|
|
347
356
|
|
|
348
|
-
if (domain[0] <= min) {
|
|
349
|
-
domain[1] = +domain[1] + (min - domain[0]);
|
|
357
|
+
if (isInverted ? domain[0] >= min : domain[0] <= min) {
|
|
350
358
|
domain[0] = min;
|
|
359
|
+
domain[1] = +domain[1] + (min - domain[0]);
|
|
351
360
|
}
|
|
352
361
|
|
|
353
|
-
if (
|
|
362
|
+
if (isInverted ? domain[1] <= max : domain[1] >= max) {
|
|
354
363
|
domain[0] = +domain[0] - (domain[1] - max);
|
|
355
364
|
domain[1] = max;
|
|
356
365
|
}
|
|
@@ -254,10 +254,13 @@ export default {
|
|
|
254
254
|
getLegendHeight(): number {
|
|
255
255
|
const $$ = this;
|
|
256
256
|
const {current, isLegendRight, legendItemHeight, legendStep} = $$.state;
|
|
257
|
+
const isFitPadding = $$.config.padding?.mode === "fit";
|
|
257
258
|
|
|
258
259
|
return $$.config.legend_show ? (
|
|
259
260
|
isLegendRight ?
|
|
260
|
-
current.height :
|
|
261
|
+
current.height : (
|
|
262
|
+
isFitPadding ? 10 : Math.max(20, legendItemHeight)
|
|
263
|
+
) * (legendStep + 1)
|
|
261
264
|
) : 0;
|
|
262
265
|
},
|
|
263
266
|
|
|
@@ -66,7 +66,6 @@ export default {
|
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
|
|
70
69
|
// circles for select
|
|
71
70
|
$el.text && main.selectAll(`.${$SELECT.selectedCircles}`)
|
|
72
71
|
.filter($$.isBarType.bind($$))
|
|
@@ -250,20 +249,5 @@ export default {
|
|
|
250
249
|
|
|
251
250
|
// Draw with new sizes & scales
|
|
252
251
|
$$.redraw(options, transitions);
|
|
253
|
-
},
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Redraw without rescale
|
|
257
|
-
* @private
|
|
258
|
-
*/
|
|
259
|
-
redrawWithoutRescale(): void {
|
|
260
|
-
this.redraw({
|
|
261
|
-
withY: false,
|
|
262
|
-
withDimension: false,
|
|
263
|
-
withLegend: false,
|
|
264
|
-
withSubchart: false,
|
|
265
|
-
withEventRect: false,
|
|
266
|
-
withTransitionForAxis: false,
|
|
267
|
-
});
|
|
268
252
|
}
|
|
269
253
|
};
|
|
@@ -28,26 +28,26 @@ export default {
|
|
|
28
28
|
|
|
29
29
|
// hide if arc type
|
|
30
30
|
region.main.style("visibility", $$.hasArcType() ? "hidden" : null);
|
|
31
|
-
// select <g> element
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
// select <g> element
|
|
33
|
+
const regions = region.main
|
|
34
34
|
.selectAll(`.${$REGION.region}`)
|
|
35
35
|
.data(config.regions);
|
|
36
36
|
|
|
37
|
-
$T(
|
|
37
|
+
$T(regions.exit())
|
|
38
38
|
.style("opacity", "0")
|
|
39
39
|
.remove();
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
.append("g")
|
|
43
|
-
.merge(list)
|
|
44
|
-
.attr("class", $$.classRegion.bind($$));
|
|
41
|
+
const regionsEnter = regions.enter()
|
|
42
|
+
.append("g");
|
|
45
43
|
|
|
46
|
-
|
|
44
|
+
regionsEnter
|
|
47
45
|
.append("rect")
|
|
48
46
|
.style("fill-opacity", "0");
|
|
49
47
|
|
|
50
|
-
region.list =
|
|
48
|
+
region.list = regionsEnter
|
|
49
|
+
.merge(regions)
|
|
50
|
+
.attr("class", $$.classRegion.bind($$));
|
|
51
51
|
},
|
|
52
52
|
|
|
53
53
|
redrawRegion(withTransition) {
|