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.
Files changed (73) hide show
  1. package/dist/billboard.css +1 -1
  2. package/dist/billboard.js +420 -256
  3. package/dist/billboard.min.css +1 -1
  4. package/dist/billboard.min.js +2 -2
  5. package/dist/billboard.pkgd.js +2115 -1544
  6. package/dist/billboard.pkgd.min.js +3 -3
  7. package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  9. package/dist/plugin/billboardjs-plugin-sparkline.js +22 -19
  10. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  11. package/dist/plugin/billboardjs-plugin-stanford.js +22 -19
  12. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-tableview.js +22 -19
  14. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  15. package/dist/plugin/billboardjs-plugin-textoverlap.js +22 -19
  16. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  17. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +1696 -1289
  18. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +1717 -1307
  19. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +1718 -1308
  20. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +1719 -1309
  21. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +1752 -1325
  22. package/dist/theme/datalab.css +1 -1
  23. package/dist/theme/datalab.min.css +1 -1
  24. package/dist/theme/graph.css +1 -1
  25. package/dist/theme/graph.min.css +1 -1
  26. package/dist/theme/insight.css +1 -1
  27. package/dist/theme/insight.min.css +1 -1
  28. package/dist-esm/billboard.js +359 -211
  29. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  30. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +4 -9
  31. package/dist-esm/plugin/billboardjs-plugin-stanford.js +6 -11
  32. package/dist-esm/plugin/billboardjs-plugin-tableview.js +7 -12
  33. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -7
  34. package/package.json +33 -33
  35. package/src/Chart/api/focus.ts +4 -4
  36. package/src/Chart/api/grid.ts +206 -0
  37. package/src/Chart/api/load.ts +31 -21
  38. package/src/Chart/api/regions.ts +28 -24
  39. package/src/Chart/api/zoom.ts +18 -3
  40. package/src/ChartInternal/Axis/Axis.ts +1 -0
  41. package/src/ChartInternal/Axis/AxisRenderer.ts +7 -2
  42. package/src/ChartInternal/ChartInternal.ts +1 -1
  43. package/src/ChartInternal/data/IData.ts +1 -1
  44. package/src/ChartInternal/data/convert.ts +6 -3
  45. package/src/ChartInternal/data/data.ts +22 -19
  46. package/src/ChartInternal/data/load.ts +19 -4
  47. package/src/ChartInternal/interactions/eventrect.ts +5 -0
  48. package/src/ChartInternal/interactions/subchart.ts +3 -2
  49. package/src/ChartInternal/interactions/zoom.ts +10 -3
  50. package/src/ChartInternal/internals/clip.ts +3 -2
  51. package/src/ChartInternal/internals/domain.ts +17 -8
  52. package/src/ChartInternal/internals/legend.ts +4 -1
  53. package/src/ChartInternal/internals/redraw.ts +0 -16
  54. package/src/ChartInternal/internals/scale.ts +7 -4
  55. package/src/ChartInternal/internals/size.axis.ts +14 -4
  56. package/src/ChartInternal/internals/size.ts +41 -18
  57. package/src/ChartInternal/internals/transform.ts +1 -1
  58. package/src/ChartInternal/internals/type.ts +10 -0
  59. package/src/ChartInternal/shape/bar.ts +2 -3
  60. package/src/config/Options/axis/x.ts +17 -0
  61. package/src/config/Options/axis/y.ts +2 -1
  62. package/src/config/Options/axis/y2.ts +2 -1
  63. package/src/config/Options/common/main.ts +19 -1
  64. package/src/config/Options/data/axis.ts +10 -1
  65. package/src/config/resolver/axis.ts +2 -4
  66. package/src/module/browser.ts +13 -5
  67. package/src/module/generator.ts +3 -3
  68. package/src/module/util.ts +7 -4
  69. package/types/axis.d.ts +8 -7
  70. package/types/chart.d.ts +6 -1
  71. package/types/options.d.ts +6 -0
  72. package/src/Chart/api/grid.x.ts +0 -90
  73. package/src/Chart/api/grid.y.ts +0 -92
@@ -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 {window} from "../../module/browser";
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
- * | - url<br>- json<br>- rows<br>- columns | The 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 |
25
- * | data | Data objects to be loaded. Checkout the example. |
26
- * | append | 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. |
27
- * | names | Same as data.names() |
28
- * | xs | Same as data.xs option |
29
- * | classes | The classes specified by data.classes will be updated. classes must be Object that has target id as keys. |
30
- * | categories | The categories specified by axis.x.categories or data.x will be updated. categories must be Array. |
31
- * | axes | The axes specified by data.axes will be updated. axes must be Object that has target id as keys. |
32
- * | colors | The colors specified by data.colors will be updated. colors must be Object that has target id as keys. |
33
- * | headers | Set request header if loading via `data.url`.<br>@see [data․headers](Options.html#.data%25E2%2580%25A4headers) |
34
- * | keys | 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) |
35
- * | mimeType | Set 'json' if loading JSON via url.<br>@see [data․mimeType](Options.html#.data%25E2%2580%25A4mimeType) |
36
- * | - type<br>- types | The type of targets will be updated. type must be String and types must be Object. |
37
- * | unload | 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. |
38
- * | done | The specified function will be called after data loaded.|
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
+ * | &nbsp; | | |
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
- window.requestIdleCallback(() => $$.loadFromArgs(args));
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 &vert; 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 && args.done.call(this);
235
+ callDone.call($$, args.done, args.resizeAfter);
226
236
  });
227
237
  }
228
238
  };
@@ -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?: string, class?: string, start?: number, end?: number}[];
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
- const $$ = this.internal;
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
- const $$ = this.internal;
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
  /**
@@ -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(domain: (number|Date)[], current, range: number[]): boolean {
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 ? (v >= min) : (v <= max)
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
- if (withinRange(domain as (number|Date)[], $$.getZoomDomain(true), $$.getZoomDomain())) {
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
- (Math.ceil(scale(ticks[1]) - scale(ticks[0])) - 12) : 110
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
@@ -19,7 +19,7 @@ export interface ITreemapData {
19
19
  }
20
20
 
21
21
  export interface IDataRow extends TDataRow {
22
- x: number;
22
+ x: number | string | Date;
23
23
  }
24
24
  export interface IArcDataRow extends TDataRow {
25
25
  ratio: number;
@@ -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 (config.data_type) {
211
- $$.setTargetType($$.mapToIds(targets)
212
- .filter(id => !(id in config.data_types)), config.data_type);
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
@@ -122,7 +122,6 @@ export default {
122
122
 
123
123
  isMultipleX(): boolean {
124
124
  return notEmpty(this.config.data_xs) ||
125
- !this.config.data_xSort ||
126
125
  this.hasType("bubble") ||
127
126
  this.hasType("scatter");
128
127
  },
@@ -398,6 +397,7 @@ export default {
398
397
  getMaxDataCountTarget() {
399
398
  let target = this.filterTargetsToShow() || [];
400
399
  const length = target.length;
400
+ const isInverted = this.config.axis_x_inverted;
401
401
 
402
402
  if (length > 1) {
403
403
  target = target.map(t => t.values)
@@ -405,9 +405,9 @@ export default {
405
405
  .map(v => v.x);
406
406
 
407
407
  target = sortValue(getUnique(target))
408
- .map((x, index) => ({x, index}));
408
+ .map((x, index, array) => ({x, index: isInverted ? array.length - index - 1 : index}));
409
409
  } else if (length) {
410
- target = target[0].values;
410
+ target = target[0].values.concat();
411
411
  }
412
412
 
413
413
  return target;
@@ -796,32 +796,35 @@ export default {
796
796
  const {axis, config} = $$;
797
797
  const stepType = config.line_step_type;
798
798
  const isCategorized = axis ? axis.isCategorized() : false;
799
-
800
799
  const converted = isArray(values) ? values.concat() : [values];
801
800
 
802
801
  if (!(isCategorized || /step\-(after|before)/.test(stepType))) {
803
802
  return values;
804
803
  }
805
804
 
806
- // insert & append cloning first/last value to be fully rendered covering on each gap sides
807
- const head = converted[0];
808
- const tail = converted[converted.length - 1];
809
- const {id} = head;
810
- let {x} = head;
811
-
812
- // insert head
813
- converted.unshift({x: --x, value: head.value, id});
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;
814
813
 
815
- isCategorized && stepType === "step-after" &&
814
+ // insert head
816
815
  converted.unshift({x: --x, value: head.value, id});
817
816
 
818
- // append tail
819
- x = tail.x;
820
- converted.push({x: ++x, value: tail.value, id});
817
+ isCategorized && stepType === "step-after" &&
818
+ converted.unshift({x: --x, value: head.value, id});
821
819
 
822
- isCategorized && stepType === "step-before" &&
820
+ // append tail
821
+ x = tail.x;
823
822
  converted.push({x: ++x, value: tail.value, id});
824
823
 
824
+ isCategorized && stepType === "step-before" &&
825
+ converted.push({x: ++x, value: tail.value, id});
826
+ }
827
+
825
828
  return converted;
826
829
  },
827
830
 
@@ -1007,7 +1010,7 @@ export default {
1007
1010
 
1008
1011
  return $$.isBubbleType(d) && (
1009
1012
  (isObject(d.value) && ("z" in d.value || "y" in d.value)) ||
1010
- (isArray(d.value) && d.value.length === 2)
1013
+ (isArray(d.value) && d.value.length >= 2)
1011
1014
  );
1012
1015
  },
1013
1016
 
@@ -1021,7 +1024,7 @@ export default {
1021
1024
  const $$ = this;
1022
1025
  const {value} = d;
1023
1026
 
1024
- return $$.isBarType(d) && isArray(value) && value.length === 2 && value.every(v => isNumber(v));
1027
+ return $$.isBarType(d) && isArray(value) && value.length >= 2 && value.every(v => isNumber(v));
1025
1028
  },
1026
1029
 
1027
1030
  /**
@@ -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
- $$.data.targets.forEach(d => {
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
- $$.data.targets = $$.data.targets.concat(targets); // add remained
57
+ data.targets = data.targets.concat(targets); // add remained
43
58
  }
44
59
 
45
60
  // Set targets
46
- $$.updateTargets($$.data.targets);
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?.call($$.api);
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,6 +67,10 @@ export default {
66
67
  // Set data and update eventReceiver.data
67
68
  const xAxisTickValues = $$.getMaxDataCountTarget();
68
69
 
70
+ if (!config.data_xSort || isInverted) {
71
+ xAxisTickValues.sort((a, b) => (isInverted ? b.x - a.x : a.x - b.x));
72
+ }
73
+
69
74
  // update data's index value to be alinged with the x Axis
70
75
  $$.updateDataIndexByX(xAxisTickValues);
71
76
  $$.updateXs(xAxisTickValues);
@@ -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: {subchart_onbrush: onBrush, zoom_rescale: withY}, scale} = $$;
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 = $$.getCustomizedScale(newScale);
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 = (zoomDomain[0] <= xDomain[0] || (zoomDomain[0] - delta) <= xDomain[0]) &&
260
- (xDomain[1] <= zoomDomain[1] || xDomain[1] <= (zoomDomain[1] - delta));
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 ? -1 : (isRotated ? -(1 + left) : -(left - 1));
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?: IData[]): (Date|number)[] {
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 zoomDomain = this.getZoomDomain();
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 (max <= domain[1]) {
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 : Math.max(20, legendItemHeight) * (legendStep + 1)
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
  };