billboard.js 3.4.0 → 3.5.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.
Files changed (70) hide show
  1. package/README.md +11 -4
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +3901 -1451
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +2 -2
  6. package/dist/billboard.pkgd.js +8350 -5297
  7. package/dist/billboard.pkgd.min.js +3 -2
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.js +29 -13
  9. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  10. package/dist/plugin/billboardjs-plugin-sparkline.js +377 -92
  11. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-stanford.js +447 -109
  13. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  14. package/dist/plugin/billboardjs-plugin-tableview.js +341 -74
  15. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  16. package/dist/plugin/billboardjs-plugin-textoverlap.js +337 -75
  17. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  18. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +4233 -3792
  19. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +4635 -3889
  20. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +4823 -3937
  21. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +4594 -3866
  22. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +4606 -3874
  23. package/dist/theme/datalab.css +1 -1
  24. package/dist/theme/datalab.min.css +1 -1
  25. package/dist/theme/graph.css +1 -1
  26. package/dist/theme/graph.min.css +1 -1
  27. package/dist/theme/insight.css +1 -1
  28. package/dist/theme/insight.min.css +1 -1
  29. package/dist-esm/billboard.js +796 -387
  30. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +47 -75
  31. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +68 -86
  32. package/dist-esm/plugin/billboardjs-plugin-stanford.js +52 -77
  33. package/dist-esm/plugin/billboardjs-plugin-tableview.js +49 -76
  34. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +49 -76
  35. package/package.json +40 -40
  36. package/src/Chart/api/chart.ts +4 -1
  37. package/src/Chart/api/data.ts +2 -2
  38. package/src/Chart/api/flow.ts +125 -115
  39. package/src/ChartInternal/Axis/AxisRenderer.ts +29 -3
  40. package/src/ChartInternal/ChartInternal.ts +55 -18
  41. package/src/ChartInternal/data/IData.ts +2 -2
  42. package/src/ChartInternal/data/convert.helper.ts +226 -0
  43. package/src/ChartInternal/data/convert.ts +43 -210
  44. package/src/ChartInternal/data/load.ts +5 -4
  45. package/src/ChartInternal/interactions/zoom.ts +17 -4
  46. package/src/ChartInternal/internals/color.ts +59 -36
  47. package/src/ChartInternal/internals/grid.ts +5 -3
  48. package/src/ChartInternal/internals/redraw.ts +5 -2
  49. package/src/ChartInternal/internals/scale.ts +3 -1
  50. package/src/ChartInternal/internals/size.axis.ts +5 -2
  51. package/src/ChartInternal/internals/text.ts +118 -17
  52. package/src/ChartInternal/shape/area.ts +14 -7
  53. package/src/ChartInternal/shape/bar.ts +19 -10
  54. package/src/ChartInternal/shape/point.ts +15 -9
  55. package/src/ChartInternal/shape/polar.ts +1 -1
  56. package/src/Plugin/sparkline/index.ts +22 -11
  57. package/src/Plugin/stanford/index.ts +10 -7
  58. package/src/Plugin/textoverlap/index.ts +4 -1
  59. package/src/config/Options/Options.ts +2 -0
  60. package/src/config/Options/common/boost.ts +31 -0
  61. package/src/config/Options/common/main.ts +15 -1
  62. package/src/config/Options/common/tooltip.ts +1 -1
  63. package/src/config/Options/data/data.ts +11 -3
  64. package/src/config/Options/shape/area.ts +6 -1
  65. package/src/config/Store/State.ts +3 -0
  66. package/src/module/browser.ts +2 -1
  67. package/src/module/generator.ts +18 -16
  68. package/src/module/util.ts +115 -1
  69. package/types/chart.d.ts +2 -2
  70. package/types/options.d.ts +45 -8
@@ -5,7 +5,7 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 3.4.0
8
+ * @version 3.5.0-next.2
9
9
  */
10
10
  import { timeParse, utcParse, timeFormat, utcFormat } from 'd3-time-format';
11
11
  import { pointer, select, namespaces, selectAll } from 'd3-selection';
@@ -33,7 +33,8 @@ var win = (function () {
33
33
  /* eslint-enable no-new-func, no-undef */
34
34
  // fallback for non-supported environments
35
35
  win.requestIdleCallback = win.requestIdleCallback || (function (cb) { return setTimeout(cb, 1); });
36
- win.cancelIdleCallback = win.cancelIdleCallback || (function (id) { return clearTimeout(id); });
36
+ // win.cancelIdleCallback = win.cancelIdleCallback || (id => clearTimeout(id));
37
+ win.requestAnimationFrame = win.requestAnimationFrame || (function (cb) { return setTimeout(cb, 1); });
37
38
  var doc = win === null || win === void 0 ? void 0 : win.document;
38
39
 
39
40
  /**
@@ -130,7 +131,7 @@ var TYPE_BY_CATEGORY = {
130
131
  ]
131
132
  };
132
133
 
133
- /*! *****************************************************************************
134
+ /******************************************************************************
134
135
  Copyright (c) Microsoft Corporation.
135
136
 
136
137
  Permission to use, copy, modify, and/or distribute this software for any
@@ -525,6 +526,22 @@ function camelize(str, separator) {
525
526
  * @private
526
527
  */
527
528
  var toArray = function (v) { return [].slice.call(v); };
529
+ /**
530
+ * Add CSS rules
531
+ * @param {object} style Style object
532
+ * @param {string} selector Selector string
533
+ * @param {Array} prop Prps arrary
534
+ * @returns {number} Newely added rule index
535
+ * @private
536
+ */
537
+ function addCssRules(style, selector, prop) {
538
+ var rootSelctor = style.rootSelctor, sheet = style.sheet;
539
+ var getSelector = function (s) { return s
540
+ .replace(/\s?(bb-)/g, ".$1")
541
+ .replace(/\.+/g, "."); };
542
+ var rule = "".concat(rootSelctor, " ").concat(getSelector(selector), " {").concat(prop.join(";"), "}");
543
+ return sheet[sheet.insertRule ? "insertRule" : "addRule"](rule, sheet.cssRules.length);
544
+ }
528
545
  /**
529
546
  * Get css rules for specified stylesheets
530
547
  * @param {Array} styleSheets The stylesheets to get the rules from
@@ -805,7 +822,90 @@ function convertInputType(mouse, touch) {
805
822
  // Demo: https://patrickhlauke.github.io/touch/pointer-hover-any-pointer-any-hover/
806
823
  var hasMouse = mouse && ["any-hover:hover", "any-pointer:fine"]
807
824
  .some(function (v) { return matchMedia === null || matchMedia === void 0 ? void 0 : matchMedia("(".concat(v, ")")).matches; });
808
- return (hasMouse && "mouse") || (hasTouch && "touch") || null;
825
+ // fallback to 'mouse' if no input type is detected.
826
+ return (hasMouse && "mouse") || (hasTouch && "touch") || "mouse";
827
+ }
828
+ /**
829
+ * Create and run on Web Worker
830
+ * @param {boolean} useWorker Use Web Worker
831
+ * @param {Function} fn Function to be executed in worker
832
+ * @param {Function} callback Callback function to receive result from worker
833
+ * @param {Array} depsFn Dependency functions to run given function(fn).
834
+ * @returns {object}
835
+ * @example
836
+ * const worker = runWorker(function(arg) {
837
+ * // do some tasks...
838
+ * console.log("param:", A(arg));
839
+ *
840
+ * return 1234;
841
+ * }, function(data) {
842
+ * // callback after worker is done
843
+ * console.log("result:", data);
844
+ * },
845
+ * [function A(){}]
846
+ * );
847
+ *
848
+ * worker(11111);
849
+ * @private
850
+ */
851
+ function runWorker(useWorker, fn, callback, depsFn) {
852
+ var _a;
853
+ if (useWorker === void 0) { useWorker = true; }
854
+ var runFn;
855
+ if (win.Worker && useWorker) {
856
+ // Web Worker body
857
+ var blob = new Blob([
858
+ "".concat((_a = depsFn === null || depsFn === void 0 ? void 0 : depsFn.map(String).join(";")) !== null && _a !== void 0 ? _a : "", "\n\n\t\t\tself.onmessage=function({data}) {\n\t\t\t\tconst result = (").concat(fn.toString(), ").apply(null, data);\n\t\t\t\tself.postMessage(result);\n\t\t\t};")
859
+ ], {
860
+ type: "text/javascript"
861
+ });
862
+ var worker_1 = new Worker(URL.createObjectURL(blob));
863
+ runFn = function () {
864
+ var args = [];
865
+ for (var _i = 0; _i < arguments.length; _i++) {
866
+ args[_i] = arguments[_i];
867
+ }
868
+ // trigger worker
869
+ worker_1.postMessage(args);
870
+ // listen worker
871
+ worker_1.onmessage = function (e) {
872
+ return callback(e.data);
873
+ };
874
+ // handle error
875
+ worker_1.onerror = function (e) {
876
+ console.error(e);
877
+ };
878
+ // return new Promise((resolve, reject) => {
879
+ // worker.onmessage = ({data}) => resolve(data);
880
+ // worker.onerror = reject;
881
+ // });
882
+ };
883
+ }
884
+ else {
885
+ runFn = function () {
886
+ var args = [];
887
+ for (var _i = 0; _i < arguments.length; _i++) {
888
+ args[_i] = arguments[_i];
889
+ }
890
+ var res = fn.apply(void 0, args);
891
+ callback(res);
892
+ };
893
+ }
894
+ return runFn;
895
+ }
896
+ /**
897
+ * Run function until given condition function return true
898
+ * @param {Function} fn Function to be executed when condition is true
899
+ * @param {Function} conditionFn Condition function to check if condition is true
900
+ * @private
901
+ */
902
+ function runUntil(fn, conditionFn) {
903
+ if (conditionFn() === false) {
904
+ win.requestAnimationFrame(function () { return runUntil(fn, conditionFn); });
905
+ }
906
+ else {
907
+ fn();
908
+ }
809
909
  }
810
910
 
811
911
  /**
@@ -1104,6 +1204,8 @@ var State = /** @class */ (function () {
1104
1204
  xAxisHeight: 0,
1105
1205
  hasAxis: false,
1106
1206
  hasRadar: false,
1207
+ // for data CSS rule index (used when boost.useCssRule is true)
1208
+ colorRule: {},
1107
1209
  current: {
1108
1210
  // chart whole dimension
1109
1211
  width: 0,
@@ -1368,12 +1470,26 @@ var main = {
1368
1470
  * @type {object}
1369
1471
  * @property {object} [resize] resize object
1370
1472
  * @property {boolean} [resize.auto=true] Set chart resize automatically on viewport changes.
1473
+ * @property {boolean|number} [resize.timer=true] Set resize timer option.
1474
+ * - **NOTE:**
1475
+ * - The resize function will be called using: true - `setTimeout()`, false - `requestIdleCallback()`.
1476
+ * - Given number(delay in ms) value, resize function will be triggered using `setTimer()` with given delay.
1371
1477
  * @example
1372
1478
  * resize: {
1373
- * auto: false
1479
+ * auto: false,
1480
+ *
1481
+ * // set resize function will be triggered using `setTimer()`
1482
+ * timer: true,
1483
+ *
1484
+ * // set resize function will be triggered using `requestIdleCallback()`
1485
+ * timer: false,
1486
+ *
1487
+ * // set resize function will be triggered using `setTimer()` with a delay of `100ms`.
1488
+ * timer: 100
1374
1489
  * }
1375
1490
  */
1376
1491
  resize_auto: true,
1492
+ resize_timer: true,
1377
1493
  /**
1378
1494
  * Set a callback to execute when the chart is clicked.
1379
1495
  * @name onclick
@@ -1587,6 +1703,38 @@ var main = {
1587
1703
  regions: []
1588
1704
  };
1589
1705
 
1706
+ /**
1707
+ * Copyright (c) 2017 ~ present NAVER Corp.
1708
+ * billboard.js project is licensed under the MIT license
1709
+ */
1710
+ /**
1711
+ * boost config options
1712
+ */
1713
+ var boost = {
1714
+ /**
1715
+ * Set boost options
1716
+ * @name boost
1717
+ * @memberof Options
1718
+ * @type {object}
1719
+ * @property {object} boost boost object
1720
+ * @property {boolean} [boost.useCssRule=false] Avoid setting inline styles for each shape elements.
1721
+ * - **NOTE:**
1722
+ * - Will append &lt;style> to the head tag and will add shpes' CSS rules dynamically.
1723
+ * - For now, covers colors related properties (fill, stroke, etc.) only.
1724
+ * @property {boolean} [boost.useWorker=false] Use Web Worker as possible for processing.
1725
+ * - **NOTE:**
1726
+ * - For now, only applies for data conversion at the initial time.
1727
+ * - As of Web Worker's async nature, handling chart instance synchrously is not recommended.
1728
+ * @example
1729
+ * boost: {
1730
+ * useCssRule: true,
1731
+ * useWorker: false
1732
+ * }
1733
+ */
1734
+ boost_useCssRule: false,
1735
+ boost_useWorker: false
1736
+ };
1737
+
1590
1738
  /**
1591
1739
  * data config options
1592
1740
  */
@@ -1626,6 +1774,7 @@ var data$2 = {
1626
1774
  data_idConverter: function (id) { return id; },
1627
1775
  /**
1628
1776
  * Set custom data name.
1777
+ * If a name is set to `null`, the series is omitted from the legend.
1629
1778
  * @name data․names
1630
1779
  * @memberof Options
1631
1780
  * @type {object}
@@ -1884,6 +2033,8 @@ var data$2 = {
1884
2033
  * @property {object} [data.labels.position] Set each dataset position, relative the original.
1885
2034
  * @property {number} [data.labels.position.x=0] x coordinate position, relative the original.
1886
2035
  * @property {number} [data.labels.position.y=0] y coordinate position, relative the original.
2036
+ * @property {object} [data.labels.rotate] Rotate label text. Specify degree value in a range of `0 ~ 360`.
2037
+ * - **NOTE:** Depend on rotate value, text position need to be adjusted manually(using `data.labels.position` option) to be shown nicely.
1887
2038
  * @memberof Options
1888
2039
  * @type {object}
1889
2040
  * @default {}
@@ -1893,6 +2044,7 @@ var data$2 = {
1893
2044
  * @see [Demo: label multiline](https://naver.github.io/billboard.js/demo/#Data.DataLabelMultiline)
1894
2045
  * @see [Demo: label overlap](https://naver.github.io/billboard.js/demo/#Data.DataLabelOverlap)
1895
2046
  * @see [Demo: label position](https://naver.github.io/billboard.js/demo/#Data.DataLabelPosition)
2047
+ * @see [Demo: label rotate](https://naver.github.io/billboard.js/demo/#Data.DataLabelRotate)
1896
2048
  * @example
1897
2049
  * data: {
1898
2050
  * labels: true,
@@ -1951,7 +2103,10 @@ var data$2 = {
1951
2103
  * position: {
1952
2104
  * data1: {x: 5, y: 5},
1953
2105
  * data2: {x: 10, y: -20}
1954
- * }
2106
+ * },
2107
+ *
2108
+ * // rotate degree for label text
2109
+ * rotate: 90
1955
2110
  * }
1956
2111
  * }
1957
2112
  */
@@ -2722,7 +2877,7 @@ var tooltip$2 = {
2722
2877
  * - **Note:**
2723
2878
  * - defaultTitleFormat:
2724
2879
  * - if `axis.x.tick.format` option will be used if set.
2725
- * - otherwise, will return funciton based on tick format type(category, timeseries).
2880
+ * - otherwise, will return function based on tick format type(category, timeseries).
2726
2881
  * - defaultValueFormat:
2727
2882
  * - for Arc type (except gauge, radar), the function will return value from `(ratio * 100).toFixed(1)`.
2728
2883
  * - for Axis based types, will be used `axis.[y|y2].tick.format` option value if is set.
@@ -2911,7 +3066,7 @@ var tooltip$2 = {
2911
3066
  */
2912
3067
  var Options = /** @class */ (function () {
2913
3068
  function Options() {
2914
- return deepClone(main, data$2, color$1, interaction$1, legend$2, title$1, tooltip$2, Options.data);
3069
+ return deepClone(main, boost, data$2, color$1, interaction$1, legend$2, title$1, tooltip$2, Options.data);
2915
3070
  }
2916
3071
  Options.setOptions = function (options) {
2917
3072
  this.data = options
@@ -3025,18 +3180,26 @@ var Cache = /** @class */ (function () {
3025
3180
  var setTimeout$1 = win.setTimeout, clearTimeout$1 = win.clearTimeout;
3026
3181
  /**
3027
3182
  * Generate resize queue function
3183
+ * @param {boolean|number} option Resize option
3028
3184
  * @returns {Fucntion}
3029
3185
  * @private
3030
3186
  */
3031
- function generateResize() {
3187
+ function generateResize(option) {
3032
3188
  var fn = [];
3033
3189
  var timeout;
3034
3190
  var callResizeFn = function () {
3035
3191
  // Delay all resize functions call, to prevent unintended excessive call from resize event
3036
3192
  callResizeFn.clear();
3037
- timeout = setTimeout$1(function () {
3038
- fn.forEach(function (f) { return f(); });
3039
- }, 200);
3193
+ if (option === false && win.requestIdleCallback) {
3194
+ requestIdleCallback(function () {
3195
+ fn.forEach(function (f) { return f(); });
3196
+ }, { timeout: 200 });
3197
+ }
3198
+ else {
3199
+ timeout = setTimeout$1(function () {
3200
+ fn.forEach(function (f) { return f(); });
3201
+ }, isNumber(option) ? option : 200);
3202
+ }
3040
3203
  };
3041
3204
  callResizeFn.clear = function () {
3042
3205
  if (timeout) {
@@ -3057,9 +3220,9 @@ function generateWait() {
3057
3220
  var transitionsToWait = [];
3058
3221
  // 'f' is called as selection.call(f, ...);
3059
3222
  var f = function (selection, callback) {
3060
- var timer;
3061
3223
  /**
3062
3224
  * Check if transition is complete
3225
+ * @returns {boolean} Whether transition is complete
3063
3226
  * @private
3064
3227
  */
3065
3228
  function loop() {
@@ -3082,15 +3245,11 @@ function generateWait() {
3082
3245
  done++;
3083
3246
  }
3084
3247
  }
3085
- timer && clearTimeout$1(timer);
3086
- if (done === transitionsToWait.length) {
3087
- callback === null || callback === void 0 ? void 0 : callback();
3088
- }
3089
- else {
3090
- timer = setTimeout$1(loop, 50);
3091
- }
3248
+ return done === transitionsToWait.length;
3092
3249
  }
3093
- loop();
3250
+ runUntil(function () {
3251
+ callback === null || callback === void 0 ? void 0 : callback();
3252
+ }, loop);
3094
3253
  };
3095
3254
  f.add = function (t) {
3096
3255
  isArray(t) ?
@@ -3104,6 +3263,197 @@ function generateWait() {
3104
3263
  * Copyright (c) 2017 ~ present NAVER Corp.
3105
3264
  * billboard.js project is licensed under the MIT license
3106
3265
  */
3266
+ /***** Functions to be executed on Web Worker *****
3267
+ * NOTE: Don't allowed to use
3268
+ * - arrow function syntax
3269
+ * - Utils functions
3270
+ */
3271
+ /**
3272
+ * Convert Columns data
3273
+ * @param {object} columns
3274
+ * @returns {Array}
3275
+ * @private
3276
+ */
3277
+ function columns(columns) {
3278
+ var newRows = [];
3279
+ columns.forEach(function (col, i) {
3280
+ var key = col[0];
3281
+ col.forEach(function (v, j) {
3282
+ if (j > 0) {
3283
+ if (typeof newRows[j - 1] === "undefined") {
3284
+ newRows[j - 1] = {};
3285
+ }
3286
+ if (typeof v === "undefined") {
3287
+ throw new Error("Source data is missing a component at (".concat(i, ", ").concat(j, ")!"));
3288
+ }
3289
+ newRows[j - 1][key] = v;
3290
+ }
3291
+ });
3292
+ });
3293
+ return newRows;
3294
+ }
3295
+ /**
3296
+ * Convert Rows data
3297
+ * @param {object} columns
3298
+ * @returns {Array}
3299
+ * @private
3300
+ */
3301
+ function rows(rows) {
3302
+ var keys = rows[0];
3303
+ var newRows = [];
3304
+ rows.forEach(function (row, i) {
3305
+ if (i > 0) {
3306
+ var newRow_1 = {};
3307
+ row.forEach(function (v, j) {
3308
+ if (typeof v === "undefined") {
3309
+ throw new Error("Source data is missing a component at (".concat(i, ", ").concat(j, ")!"));
3310
+ }
3311
+ newRow_1[keys[j]] = v;
3312
+ });
3313
+ newRows.push(newRow_1);
3314
+ }
3315
+ });
3316
+ return newRows;
3317
+ }
3318
+ /**
3319
+ * Convert JSON data
3320
+ * @param {object} columns
3321
+ * @returns {Array}
3322
+ * @private
3323
+ */
3324
+ function json(json, keysParam) {
3325
+ var newRows = [];
3326
+ var findValueInJson = function (object, path) {
3327
+ if (object[path] !== undefined) {
3328
+ return object[path];
3329
+ }
3330
+ var convertedPath = path.replace(/\[(\w+)\]/g, ".$1"); // convert indexes to properties (replace [] with .)
3331
+ var pathArray = convertedPath.replace(/^\./, "").split("."); // strip a leading dot
3332
+ var target = object;
3333
+ pathArray.some(function (k) {
3334
+ return !(target = target && k in target ?
3335
+ target[k] : undefined);
3336
+ });
3337
+ return target;
3338
+ };
3339
+ var targetKeys;
3340
+ var data;
3341
+ if (Array.isArray(json)) {
3342
+ if (keysParam.x) {
3343
+ targetKeys = keysParam.value.concat(keysParam.x);
3344
+ }
3345
+ else {
3346
+ targetKeys = keysParam.value;
3347
+ }
3348
+ newRows.push(targetKeys);
3349
+ json.forEach(function (o) {
3350
+ var newRow = targetKeys.map(function (key) {
3351
+ // convert undefined to null because undefined data will be removed in convertDataToTargets()
3352
+ var v = findValueInJson(o, key);
3353
+ if (typeof v === "undefined") {
3354
+ v = null;
3355
+ }
3356
+ return v;
3357
+ });
3358
+ newRows.push(newRow);
3359
+ });
3360
+ data = rows(newRows);
3361
+ }
3362
+ else {
3363
+ Object.keys(json).forEach(function (key) {
3364
+ var tmp = json[key].concat();
3365
+ tmp.unshift(key);
3366
+ newRows.push(tmp);
3367
+ });
3368
+ data = columns(newRows);
3369
+ }
3370
+ return data;
3371
+ }
3372
+ /***** Functions can't be executed on Web Worker *****/
3373
+ /**
3374
+ * Convert URL data
3375
+ * @param {string} url Remote URL
3376
+ * @param {string} mimeType MIME type string: json | csv | tsv
3377
+ * @param {object} headers Header object
3378
+ * @param {object} keys Key object
3379
+ * @param {Function} done Callback function
3380
+ * @private
3381
+ */
3382
+ function url(url, mimeType, headers, keys, done) {
3383
+ if (mimeType === void 0) { mimeType = "csv"; }
3384
+ var req = new XMLHttpRequest();
3385
+ var converter = { csv: csv, tsv: tsv, json: json };
3386
+ req.open("GET", url);
3387
+ if (headers) {
3388
+ Object.keys(headers).forEach(function (key) {
3389
+ req.setRequestHeader(key, headers[key]);
3390
+ });
3391
+ }
3392
+ req.onreadystatechange = function () {
3393
+ if (req.readyState === 4) {
3394
+ if (req.status === 200) {
3395
+ var response = req.responseText;
3396
+ response && done.call(this, converter[mimeType](mimeType === "json" ? JSON.parse(response) : response, keys));
3397
+ }
3398
+ else {
3399
+ throw new Error("".concat(url, ": Something went wrong loading!"));
3400
+ }
3401
+ }
3402
+ };
3403
+ req.send();
3404
+ }
3405
+ /**
3406
+ * Convert CSV/TSV data
3407
+ * @param {object} parser Parser object
3408
+ * @param {object} xsv Data
3409
+ * @returns {object}
3410
+ * @private
3411
+ */
3412
+ function convertCsvTsvToData(parser, xsv) {
3413
+ var rows = parser.rows(xsv);
3414
+ var d;
3415
+ if (rows.length === 1) {
3416
+ d = [{}];
3417
+ rows[0].forEach(function (id) {
3418
+ d[0][id] = null;
3419
+ });
3420
+ }
3421
+ else {
3422
+ d = parser.parse(xsv);
3423
+ }
3424
+ return d;
3425
+ }
3426
+ function csv(xsv) {
3427
+ return convertCsvTsvToData({
3428
+ rows: csvParseRows,
3429
+ parse: csvParse
3430
+ }, xsv);
3431
+ }
3432
+ function tsv(tsv) {
3433
+ return convertCsvTsvToData({
3434
+ rows: tsvParseRows,
3435
+ parse: tsvParse
3436
+ }, tsv);
3437
+ }
3438
+
3439
+ /**
3440
+ * Copyright (c) 2017 ~ present NAVER Corp.
3441
+ * billboard.js project is licensed under the MIT license
3442
+ */
3443
+ /**
3444
+ * Get data key for JSON
3445
+ * @param {string|object} keysParam Key params
3446
+ * @param {object} config Config object
3447
+ * @returns {string} Data key
3448
+ * @private
3449
+ */
3450
+ function getDataKeyForJson(keysParam, config) {
3451
+ var keys = keysParam || (config === null || config === void 0 ? void 0 : config.data_keys);
3452
+ if (keys === null || keys === void 0 ? void 0 : keys.x) {
3453
+ config.data_x = keys.x;
3454
+ }
3455
+ return keys;
3456
+ }
3107
3457
  /**
3108
3458
  * Data convert
3109
3459
  * @memberof ChartInternal
@@ -3114,11 +3464,12 @@ var dataConvert = {
3114
3464
  * Convert data according its type
3115
3465
  * @param {object} args data object
3116
3466
  * @param {Function} [callback] callback for url(XHR) type loading
3117
- * @returns {object}
3118
3467
  * @private
3119
3468
  */
3120
3469
  convertData: function (args, callback) {
3121
- var data;
3470
+ var config = this.config;
3471
+ var useWorker = config.boost_useWorker;
3472
+ var data = args;
3122
3473
  if (args.bindto) {
3123
3474
  data = {};
3124
3475
  ["url", "mimeType", "headers", "keys", "json", "keys", "rows", "columns"]
@@ -3129,175 +3480,21 @@ var dataConvert = {
3129
3480
  }
3130
3481
  });
3131
3482
  }
3132
- else {
3133
- data = args;
3134
- }
3135
3483
  if (data.url && callback) {
3136
- this.convertUrlToData(data.url, data.mimeType, data.headers, data.keys, callback);
3484
+ url(data.url, data.mimeType, data.headers, getDataKeyForJson(data.keys, config), callback);
3137
3485
  }
3138
3486
  else if (data.json) {
3139
- data = this.convertJsonToData(data.json, data.keys);
3487
+ runWorker(useWorker, json, callback, [columns, rows])(data.json, getDataKeyForJson(data.keys, config));
3140
3488
  }
3141
3489
  else if (data.rows) {
3142
- data = this.convertRowsToData(data.rows);
3490
+ runWorker(useWorker, rows, callback)(data.rows);
3143
3491
  }
3144
3492
  else if (data.columns) {
3145
- data = this.convertColumnsToData(data.columns);
3493
+ runWorker(useWorker, columns, callback)(data.columns);
3146
3494
  }
3147
3495
  else if (args.bindto) {
3148
3496
  throw Error("url or json or rows or columns is required.");
3149
3497
  }
3150
- return isArray(data) && data;
3151
- },
3152
- /**
3153
- * Convert URL data
3154
- * @param {string} url Remote URL
3155
- * @param {string} mimeType MIME type string: json | csv | tsv
3156
- * @param {object} headers Header object
3157
- * @param {object} keys Key object
3158
- * @param {Function} done Callback function
3159
- * @private
3160
- */
3161
- convertUrlToData: function (url, mimeType, headers, keys, done) {
3162
- var _this = this;
3163
- if (mimeType === void 0) { mimeType = "csv"; }
3164
- var req = new XMLHttpRequest();
3165
- req.open("GET", url);
3166
- if (headers) {
3167
- Object.keys(headers).forEach(function (key) {
3168
- req.setRequestHeader(key, headers[key]);
3169
- });
3170
- }
3171
- req.onreadystatechange = function () {
3172
- if (req.readyState === 4) {
3173
- if (req.status === 200) {
3174
- var response = req.responseText;
3175
- response && done.call(_this, _this["convert".concat(capitalize(mimeType), "ToData")](mimeType === "json" ? JSON.parse(response) : response, keys));
3176
- }
3177
- else {
3178
- throw new Error("".concat(url, ": Something went wrong loading!"));
3179
- }
3180
- }
3181
- };
3182
- req.send();
3183
- },
3184
- /**
3185
- * Convert CSV/TSV data
3186
- * @param {object} parser Parser object
3187
- * @param {object} xsv Data
3188
- * @private
3189
- * @returns {object}
3190
- */
3191
- convertCsvTsvToData: function (parser, xsv) {
3192
- var rows = parser.rows(xsv);
3193
- var d;
3194
- if (rows.length === 1) {
3195
- d = [{}];
3196
- rows[0].forEach(function (id) {
3197
- d[0][id] = null;
3198
- });
3199
- }
3200
- else {
3201
- d = parser.parse(xsv);
3202
- }
3203
- return d;
3204
- },
3205
- convertCsvToData: function (xsv) {
3206
- return this.convertCsvTsvToData({
3207
- rows: csvParseRows,
3208
- parse: csvParse
3209
- }, xsv);
3210
- },
3211
- convertTsvToData: function (tsv) {
3212
- return this.convertCsvTsvToData({
3213
- rows: tsvParseRows,
3214
- parse: tsvParse
3215
- }, tsv);
3216
- },
3217
- convertJsonToData: function (json, keysParam) {
3218
- var _this = this;
3219
- var config = this.config;
3220
- var newRows = [];
3221
- var targetKeys;
3222
- var data;
3223
- if (isArray(json)) {
3224
- var keys = keysParam || config.data_keys;
3225
- if (keys.x) {
3226
- targetKeys = keys.value.concat(keys.x);
3227
- config.data_x = keys.x;
3228
- }
3229
- else {
3230
- targetKeys = keys.value;
3231
- }
3232
- newRows.push(targetKeys);
3233
- json.forEach(function (o) {
3234
- var newRow = targetKeys.map(function (key) {
3235
- // convert undefined to null because undefined data will be removed in convertDataToTargets()
3236
- var v = _this.findValueInJson(o, key);
3237
- if (isUndefined(v)) {
3238
- v = null;
3239
- }
3240
- return v;
3241
- });
3242
- newRows.push(newRow);
3243
- });
3244
- data = this.convertRowsToData(newRows);
3245
- }
3246
- else {
3247
- Object.keys(json).forEach(function (key) {
3248
- var tmp = json[key].concat();
3249
- tmp.unshift(key);
3250
- newRows.push(tmp);
3251
- });
3252
- data = this.convertColumnsToData(newRows);
3253
- }
3254
- return data;
3255
- },
3256
- findValueInJson: function (object, path) {
3257
- if (object[path] !== undefined) {
3258
- return object[path];
3259
- }
3260
- var convertedPath = path.replace(/\[(\w+)\]/g, ".$1"); // convert indexes to properties (replace [] with .)
3261
- var pathArray = convertedPath.replace(/^\./, "").split("."); // strip a leading dot
3262
- var target = object;
3263
- pathArray.some(function (k) { return !(target = target && k in target ?
3264
- target[k] : undefined); });
3265
- return target;
3266
- },
3267
- convertRowsToData: function (rows) {
3268
- var keys = rows[0];
3269
- var newRows = [];
3270
- rows.forEach(function (row, i) {
3271
- if (i > 0) {
3272
- var newRow_1 = {};
3273
- row.forEach(function (v, j) {
3274
- if (isUndefined(v)) {
3275
- throw new Error("Source data is missing a component at (".concat(i, ", ").concat(j, ")!"));
3276
- }
3277
- newRow_1[keys[j]] = v;
3278
- });
3279
- newRows.push(newRow_1);
3280
- }
3281
- });
3282
- return newRows;
3283
- },
3284
- convertColumnsToData: function (columns) {
3285
- var newRows = [];
3286
- columns.forEach(function (col, i) {
3287
- var key = col[0];
3288
- col.forEach(function (v, j) {
3289
- if (j > 0) {
3290
- if (isUndefined(newRows[j - 1])) {
3291
- newRows[j - 1] = {};
3292
- }
3293
- if (isUndefined(v)) {
3294
- throw new Error("Source data is missing a component at (".concat(i, ", ").concat(j, ")!"));
3295
- }
3296
- newRows[j - 1][key] = v;
3297
- }
3298
- });
3299
- });
3300
- return newRows;
3301
3498
  },
3302
3499
  convertDataToTargets: function (data, appendXs) {
3303
3500
  var _this = this;
@@ -3355,6 +3552,7 @@ var dataConvert = {
3355
3552
  var hasCategory = isCategory && data.map(function (v) { return v.x; })
3356
3553
  .every(function (v) { return config.axis_x_categories.indexOf(v) > -1; });
3357
3554
  // when .load() with 'append' option is used for indexed axis
3555
+ // @ts-ignore
3358
3556
  var isDataAppend = data.__append__;
3359
3557
  var xIndex = xKey === null && isDataAppend ?
3360
3558
  $$.api.data.values(id).length : 0;
@@ -3385,7 +3583,12 @@ var dataConvert = {
3385
3583
  if (isUndefined(value) || $$.data.xs[id].length <= i) {
3386
3584
  x = undefined;
3387
3585
  }
3388
- return { x: x, value: value, id: convertedId };
3586
+ return {
3587
+ x: x,
3588
+ value: value,
3589
+ id: convertedId,
3590
+ index: -1
3591
+ };
3389
3592
  }).filter(function (v) { return isDefined(v.x); })
3390
3593
  };
3391
3594
  });
@@ -4276,9 +4479,11 @@ var dataLoad = {
4276
4479
  }
4277
4480
  // reset internally cached data
4278
4481
  $$.cache.reset();
4279
- var data = args.data || $$.convertData(args, function (d) { return $$.load($$.convertDataToTargets(d), args); });
4280
- args.append && (data.__append__ = true);
4281
- data && $$.load($$.convertDataToTargets(data), args);
4482
+ $$.convertData(args, function (d) {
4483
+ var data = args.data || d;
4484
+ args.append && (data.__append__ = true);
4485
+ data && $$.load($$.convertDataToTargets(data), args);
4486
+ });
4282
4487
  },
4283
4488
  unload: function (rawTargetIds, customDoneCb) {
4284
4489
  var $$ = this;
@@ -4703,47 +4908,67 @@ var colorizePattern = function (pattern, color, id) {
4703
4908
  node: node.node()
4704
4909
  };
4705
4910
  };
4911
+ /**
4912
+ * Get color pattern from CSS file
4913
+ * CSS should be defined as: background-image: url("#00c73c;#fa7171; ...");
4914
+ * @param {d3Selection} element Chart element
4915
+ * @returns {Array}
4916
+ * @private
4917
+ */
4918
+ function getColorFromCss(element) {
4919
+ var cacheKey = KEY.colorPattern;
4920
+ var body = doc.body;
4921
+ var pattern = body[cacheKey];
4922
+ if (!pattern) {
4923
+ var delimiter = ";";
4924
+ var content = element
4925
+ .classed($COLOR.colorPattern, true)
4926
+ .style("background-image");
4927
+ element.classed($COLOR.colorPattern, false);
4928
+ if (content.indexOf(delimiter) > -1) {
4929
+ pattern = content
4930
+ .replace(/url[^#]*|["'()]|(\s|%20)/g, "")
4931
+ .split(delimiter)
4932
+ .map(function (v) { return v.trim().replace(/[\"'\s]/g, ""); })
4933
+ .filter(Boolean);
4934
+ body[cacheKey] = pattern;
4935
+ }
4936
+ }
4937
+ return pattern;
4938
+ }
4706
4939
  // Replacement of d3.schemeCategory10.
4707
4940
  // Contained differently depend on d3 version: v4(d3-scale), v5(d3-scale-chromatic)
4708
4941
  var schemeCategory10 = ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"];
4709
4942
  var color = {
4710
4943
  /**
4711
- * Get color pattern from CSS file
4712
- * CSS should be defined as: background-image: url("#00c73c;#fa7171; ...");
4713
- * @returns {Array}
4944
+ * Add props color css rule to given selector
4945
+ * @param {Function} fn Color function
4946
+ * @param {string} selector CSS selector
4947
+ * @param {Array} props CSS props list
4948
+ * @returns {Function}
4714
4949
  * @private
4715
4950
  */
4716
- getColorFromCss: function () {
4717
- var cacheKey = KEY.colorPattern;
4718
- var body = doc.body;
4719
- var pattern = body[cacheKey];
4720
- if (!pattern) {
4721
- var delimiter = ";";
4722
- var span = doc.createElement("span");
4723
- span.className = $COLOR.colorPattern;
4724
- span.style.display = "none";
4725
- body.appendChild(span);
4726
- var content = win.getComputedStyle(span).backgroundImage;
4727
- span.parentNode.removeChild(span);
4728
- if (content.indexOf(delimiter) > -1) {
4729
- pattern = content
4730
- .replace(/url[^#]*|["'()]|(\s|%20)/g, "")
4731
- .split(delimiter)
4732
- .map(function (v) { return v.trim().replace(/[\"'\s]/g, ""); })
4733
- .filter(Boolean);
4734
- body[cacheKey] = pattern;
4735
- }
4736
- }
4737
- return pattern;
4951
+ setColorByRule: function (fn, selector, props) {
4952
+ var $$ = this;
4953
+ var config = $$.config, _a = $$.state, colorRule = _a.colorRule, style = _a.style;
4954
+ var colorFn = fn || $$.color;
4955
+ return config.boost_useCssRule ? function (selection) {
4956
+ selection.each(function (d) {
4957
+ var color = colorFn.call($$, d);
4958
+ var shapeSelector = "".concat($SHAPE.shapes).concat($$.getTargetSelectorSuffix(d.id), " .").concat(selector);
4959
+ (shapeSelector in colorRule) && style.sheet.deleteRule(colorRule[shapeSelector]);
4960
+ $$.state.colorRule[shapeSelector] = addCssRules(style, shapeSelector, props.map(function (v) { return "".concat(v, ": ").concat(color); }));
4961
+ });
4962
+ } : function () { };
4738
4963
  },
4739
4964
  generateColor: function () {
4740
4965
  var $$ = this;
4741
- var config = $$.config;
4966
+ var $el = $$.$el, config = $$.config;
4742
4967
  var colors = config.data_colors;
4743
4968
  var callback = config.data_color;
4744
4969
  var ids = [];
4745
4970
  var pattern = notEmpty(config.color_pattern) ? config.color_pattern :
4746
- scaleOrdinal($$.getColorFromCss() || schemeCategory10).range();
4971
+ scaleOrdinal(getColorFromCss($el.chart) || schemeCategory10).range();
4747
4972
  var originalColorPattern = pattern;
4748
4973
  if (isFunction(config.color_tiles)) {
4749
4974
  var tiles_1 = config.color_tiles.bind($$.api)();
@@ -6060,6 +6285,10 @@ var redraw = {
6060
6285
  // Draw with new sizes & scales
6061
6286
  $$.redraw(options, transitions);
6062
6287
  },
6288
+ /**
6289
+ * Redraw without rescale
6290
+ * @private
6291
+ */
6063
6292
  redrawWithoutRescale: function () {
6064
6293
  this.redraw({
6065
6294
  withY: false,
@@ -6208,7 +6437,10 @@ var scale = {
6208
6437
  var xDomain = updateXDomain && ((_a = scale.x) === null || _a === void 0 ? void 0 : _a.orgDomain());
6209
6438
  var xSubDomain = updateXDomain && org.xDomain;
6210
6439
  scale.x = $$.getXScale(min.x, max.x, xDomain, function () { return axis.x.tickOffset(); });
6211
- scale.subX = $$.getXScale(min.x, max.x, xSubDomain, function (d) { return (d % 1 ? 0 : axis.subX.tickOffset()); });
6440
+ scale.subX = $$.getXScale(min.x, max.x, xSubDomain, function (d) {
6441
+ var _a;
6442
+ return (d % 1 ? 0 : ((_a = axis.subX) !== null && _a !== void 0 ? _a : axis.x).tickOffset());
6443
+ });
6212
6444
  format.xAxisTick = axis.getXAxisTickFormat();
6213
6445
  format.subXAxisTick = axis.getXAxisTickFormat(true);
6214
6446
  axis.setAxis("x", scale.x, config.axis_x_tick_outer, isInit);
@@ -6971,6 +7203,75 @@ var size = {
6971
7203
  * Copyright (c) 2017 ~ present NAVER Corp.
6972
7204
  * billboard.js project is licensed under the MIT license
6973
7205
  */
7206
+ /**
7207
+ * Get text-anchor according text.labels.rotate angle
7208
+ * @param {number} angle Angle value
7209
+ * @returns {string} Anchor string value
7210
+ * @private
7211
+ */
7212
+ function getRotateAnchor(angle) {
7213
+ var anchor = "middle";
7214
+ if (angle > 0 && angle <= 170) {
7215
+ anchor = "end";
7216
+ }
7217
+ else if (angle > 190 && angle <= 360) {
7218
+ anchor = "start";
7219
+ }
7220
+ return anchor;
7221
+ }
7222
+ /**
7223
+ * Set rotated position coordinate according text.labels.rotate angle
7224
+ * @param {object} d Data object
7225
+ * @param {object} pos Position object
7226
+ * @param {object} pos.x x coordinate
7227
+ * @param {object} pos.y y coordinate
7228
+ * @param {string} anchor string value
7229
+ * @param {boolean} isRotated If axis is rotated
7230
+ * @param {boolean} isInverted If axis is inverted
7231
+ * @returns {object} x, y coordinate
7232
+ * @private
7233
+ */
7234
+ function setRotatePos(d, pos, anchor, isRotated, isInverted) {
7235
+ var _a;
7236
+ var $$ = this;
7237
+ var value = d.value;
7238
+ var isCandlestickType = $$.isCandlestickType(d);
7239
+ var isNegative = (isNumber(value) && value < 0) || (isCandlestickType && !((_a = $$.getCandlestickData(d)) === null || _a === void 0 ? void 0 : _a._isUp));
7240
+ var x = pos.x, y = pos.y;
7241
+ var gap = 4;
7242
+ var doubleGap = gap * 2;
7243
+ if (isRotated) {
7244
+ if (anchor === "start") {
7245
+ x += isNegative ? 0 : doubleGap;
7246
+ y += gap;
7247
+ }
7248
+ else if (anchor === "middle") {
7249
+ x += doubleGap;
7250
+ y -= doubleGap;
7251
+ }
7252
+ else if (anchor === "end") {
7253
+ isNegative && (x -= doubleGap);
7254
+ y += gap;
7255
+ }
7256
+ }
7257
+ else {
7258
+ if (anchor === "start") {
7259
+ x += gap;
7260
+ isNegative && (y += doubleGap * 2);
7261
+ }
7262
+ else if (anchor === "middle") {
7263
+ y -= doubleGap;
7264
+ }
7265
+ else if (anchor === "end") {
7266
+ x -= gap;
7267
+ isNegative && (y += doubleGap * 2);
7268
+ }
7269
+ if (isInverted) {
7270
+ y += isNegative ? -17 : (isCandlestickType ? 13 : 7);
7271
+ }
7272
+ }
7273
+ return { x: x, y: y };
7274
+ }
6974
7275
  var text = {
6975
7276
  opacityForText: function (d) {
6976
7277
  var $$ = this;
@@ -7001,6 +7302,7 @@ var text = {
7001
7302
  var mainTextEnter = mainTextUpdate.enter().append("g")
7002
7303
  .style("opacity", "0")
7003
7304
  .attr("class", classChartText)
7305
+ .call($$.setColorByRule($$.updateTextColor, $TEXT.text, ["fill"]))
7004
7306
  .style("pointer-events", "none");
7005
7307
  mainTextEnter.append("g")
7006
7308
  .attr("class", classTexts);
@@ -7032,7 +7334,7 @@ var text = {
7032
7334
  }
7033
7335
  return (config.axis_rotated ? (isEndAnchor ? "end" : "start") : "middle");
7034
7336
  })
7035
- .style("fill", $$.updateTextColor.bind($$))
7337
+ .style("fill", $$.colorTextByRule)
7036
7338
  .style("fill-opacity", "0")
7037
7339
  .each(function (d, i, texts) {
7038
7340
  var node = select(this);
@@ -7102,32 +7404,43 @@ var text = {
7102
7404
  },
7103
7405
  /**
7104
7406
  * Redraw chartText
7105
- * @param {Function} x Positioning function for x
7106
- * @param {Function} y Positioning function for y
7407
+ * @param {Function} getX Positioning function for x
7408
+ * @param {Function} getY Positioning function for y
7107
7409
  * @param {boolean} forFlow Weather is flow
7108
7410
  * @param {boolean} withTransition transition is enabled
7109
7411
  * @returns {Array}
7110
7412
  * @private
7111
7413
  */
7112
- redrawText: function (x, y, forFlow, withTransition) {
7414
+ redrawText: function (getX, getY, forFlow, withTransition) {
7113
7415
  var $$ = this;
7114
- var $T = $$.$T;
7416
+ var $T = $$.$T, axis = $$.axis, config = $$.config;
7115
7417
  var t = getRandom(true);
7418
+ var isRotated = config.axis_rotated;
7419
+ var angle = config.data_labels.rotate;
7420
+ var anchorString = getRotateAnchor(angle);
7421
+ var rotateString = angle ? "rotate(".concat(angle, ")") : "";
7116
7422
  $$.$el.text
7117
- .style("fill", $$.updateTextColor.bind($$))
7423
+ .style("fill", $$.colorTextByRule)
7118
7424
  .attr("filter", $$.updateTextBacgroundColor.bind($$))
7119
7425
  .style("fill-opacity", forFlow ? 0 : $$.opacityForText.bind($$))
7120
7426
  .each(function (d, i) {
7121
7427
  // do not apply transition for newly added text elements
7122
7428
  var node = $T(this, !!(withTransition && this.getAttribute("x")), t);
7123
- var posX = x.bind(this)(d, i);
7124
- var posY = y.bind(this)(d, i);
7429
+ var isInverted = config["axis_".concat(axis === null || axis === void 0 ? void 0 : axis.getId(d.id), "_inverted")];
7430
+ var pos = {
7431
+ x: getX.bind(this)(d, i),
7432
+ y: getY.bind(this)(d, i)
7433
+ };
7434
+ if (angle) {
7435
+ pos = setRotatePos.bind($$)(d, pos, anchorString, isRotated, isInverted);
7436
+ node.attr("text-anchor", anchorString);
7437
+ }
7125
7438
  // when is multiline
7126
- if (this.childElementCount) {
7127
- node.attr("transform", "translate(".concat(posX, " ").concat(posY, ")"));
7439
+ if (this.childElementCount || angle) {
7440
+ node.attr("transform", "translate(".concat(pos.x, " ").concat(pos.y, ") ").concat(rotateString));
7128
7441
  }
7129
7442
  else {
7130
- node.attr("x", posX).attr("y", posY);
7443
+ node.attr("x", pos.x).attr("y", pos.y);
7131
7444
  }
7132
7445
  });
7133
7446
  // need to return 'true' as of being pushed to the redraw list
@@ -7286,8 +7599,10 @@ var text = {
7286
7599
  */
7287
7600
  getYForText: function (points, d, textElement) {
7288
7601
  var $$ = this;
7289
- var config = $$.config, state = $$.state;
7602
+ var axis = $$.axis, config = $$.config, state = $$.state;
7290
7603
  var isRotated = config.axis_rotated;
7604
+ var isInverted = config["axis_".concat(axis === null || axis === void 0 ? void 0 : axis.getId(d.id), "_inverted")];
7605
+ var isBarType = $$.isBarType(d);
7291
7606
  var r = config.point_r;
7292
7607
  var rect = getBoundingRect(textElement);
7293
7608
  var value = d.value;
@@ -7303,6 +7618,9 @@ var text = {
7303
7618
  yPos = value && value._isUp ?
7304
7619
  points[2][2] - baseY :
7305
7620
  points[2][1] + (baseY * 4);
7621
+ if (isInverted) {
7622
+ yPos += 15 * (value._isUp ? 1 : -1);
7623
+ }
7306
7624
  }
7307
7625
  }
7308
7626
  else {
@@ -7315,16 +7633,19 @@ var text = {
7315
7633
  baseY += config.point_r / 2.3;
7316
7634
  }
7317
7635
  if (value < 0 || (value === 0 && !state.hasPositiveValue && state.hasNegativeValue)) {
7318
- yPos += rect.height + ($$.isBarType(d) ? -baseY : baseY);
7636
+ yPos += isInverted ? (isBarType ? -3 : -5) : (rect.height + (isBarType ? -baseY : baseY));
7319
7637
  }
7320
7638
  else {
7321
7639
  var diff = -baseY * 2;
7322
- if ($$.isBarType(d)) {
7640
+ if (isBarType) {
7323
7641
  diff = -baseY;
7324
7642
  }
7325
7643
  else if ($$.isBubbleType(d)) {
7326
7644
  diff = baseY;
7327
7645
  }
7646
+ if (isInverted) {
7647
+ diff = isBarType ? 10 : 15;
7648
+ }
7328
7649
  yPos += diff;
7329
7650
  }
7330
7651
  }
@@ -8310,17 +8631,25 @@ var ChartInternal = /** @class */ (function () {
8310
8631
  ChartInternal.prototype.init = function () {
8311
8632
  var $$ = this;
8312
8633
  var config = $$.config, state = $$.state, $el = $$.$el;
8634
+ var useCssRule = config.boost_useCssRule;
8313
8635
  checkModuleImport($$);
8314
8636
  state.hasAxis = !$$.hasArcType();
8315
8637
  state.hasRadar = !state.hasAxis && $$.hasType("radar");
8316
- // when 'padding=false' is set, disable axes and subchart. Because they are useless.
8317
- if (config.padding === false) {
8318
- config.axis_x_show = false;
8319
- config.axis_y_show = false;
8320
- config.axis_y2_show = false;
8321
- config.subchart_show = false;
8638
+ // datetime to be used for uniqueness
8639
+ state.datetimeId = "bb-".concat(+new Date() * getRandom());
8640
+ if (useCssRule) {
8641
+ // append style element
8642
+ var styleEl = doc.createElement("style");
8643
+ // styleEl.id = styleId;
8644
+ styleEl.type = "text/css";
8645
+ doc.head.appendChild(styleEl);
8646
+ state.style = {
8647
+ rootSelctor: ".".concat(state.datetimeId),
8648
+ sheet: styleEl.sheet
8649
+ };
8650
+ // used on .destroy()
8651
+ $el.style = styleEl;
8322
8652
  }
8323
- $$.initParams();
8324
8653
  var bindto = {
8325
8654
  element: config.bindto,
8326
8655
  classname: "bb"
@@ -8337,7 +8666,9 @@ var ChartInternal = /** @class */ (function () {
8337
8666
  }
8338
8667
  $el.chart.html("")
8339
8668
  .classed(bindto.classname, true)
8669
+ .classed(state.datetimeId, useCssRule)
8340
8670
  .style("position", "relative");
8671
+ $$.initParams();
8341
8672
  $$.initToRender();
8342
8673
  };
8343
8674
  /**
@@ -8363,19 +8694,35 @@ var ChartInternal = /** @class */ (function () {
8363
8694
  });
8364
8695
  }
8365
8696
  if (!isLazy || forced) {
8366
- var convertedData = $$.convertData(config, $$.initWithData);
8367
- convertedData && $$.initWithData(convertedData);
8368
- $$.afterInit();
8697
+ $$.convertData(config, function (res) {
8698
+ $$.initWithData(res);
8699
+ $$.afterInit();
8700
+ });
8369
8701
  }
8370
8702
  };
8371
8703
  ChartInternal.prototype.initParams = function () {
8372
8704
  var $$ = this;
8373
8705
  var config = $$.config, format = $$.format, state = $$.state;
8374
8706
  var isRotated = config.axis_rotated;
8375
- // datetime to be used for uniqueness
8376
- state.datetimeId = "bb-".concat(+new Date() * getRandom());
8707
+ var useCssRule = config.boost_useCssRule;
8708
+ // color settings
8377
8709
  $$.color = $$.generateColor();
8710
+ $$.colorByRule = $$.color;
8711
+ $$.colorTextByRule = $$.updateTextColor.bind($$);
8378
8712
  $$.levelColor = $$.generateLevelColor();
8713
+ if (useCssRule) {
8714
+ state.colorRule = {};
8715
+ // to not apply inline color setting
8716
+ $$.colorByRule = null;
8717
+ $$.colorTextByRule = null;
8718
+ }
8719
+ // when 'padding=false' is set, disable axes and subchart. Because they are useless.
8720
+ if (config.padding === false) {
8721
+ config.axis_x_show = false;
8722
+ config.axis_y_show = false;
8723
+ config.axis_y2_show = false;
8724
+ config.subchart_show = false;
8725
+ }
8379
8726
  if ($$.hasPointType()) {
8380
8727
  $$.point = $$.generatePoint();
8381
8728
  }
@@ -8728,17 +9075,22 @@ var ChartInternal = /** @class */ (function () {
8728
9075
  ChartInternal.prototype.bindResize = function () {
8729
9076
  var $$ = this;
8730
9077
  var config = $$.config, state = $$.state;
8731
- var resizeFunction = generateResize();
9078
+ var resizeFunction = generateResize(config.resize_timer);
8732
9079
  var list = [];
8733
- list.push(function () { return callFn(config.onresize, $$, $$.api); });
9080
+ list.push(function () { return callFn(config.onresize, $$.api); });
8734
9081
  if (config.resize_auto) {
8735
9082
  list.push(function () {
8736
9083
  state.resizing = true;
9084
+ // https://github.com/naver/billboard.js/issues/2650
9085
+ if (config.legend_show) {
9086
+ $$.updateSizes();
9087
+ $$.updateLegend();
9088
+ }
8737
9089
  $$.api.flush(false);
8738
9090
  });
8739
9091
  }
8740
9092
  list.push(function () {
8741
- callFn(config.onresized, $$, $$.api);
9093
+ callFn(config.onresized, $$.api);
8742
9094
  state.resizing = false;
8743
9095
  });
8744
9096
  // add resize functions
@@ -8921,7 +9273,7 @@ var apiChart = {
8921
9273
  destroy: function () {
8922
9274
  var _this = this;
8923
9275
  var $$ = this.internal;
8924
- var _a = $$.$el, chart = _a.chart, svg = _a.svg;
9276
+ var _a = $$.$el, chart = _a.chart, style = _a.style, svg = _a.svg;
8925
9277
  if (notEmpty($$)) {
8926
9278
  $$.callPluginHook("$willDestroy");
8927
9279
  $$.charts.splice($$.charts.indexOf(this), 1);
@@ -8935,6 +9287,8 @@ var apiChart = {
8935
9287
  .style("position", null)
8936
9288
  .selectChildren()
8937
9289
  .remove();
9290
+ // remove <style> element added by boost.useCssRule option
9291
+ style && style.parentNode.removeChild(style);
8938
9292
  // releasing own references
8939
9293
  Object.keys(this).forEach(function (key) {
8940
9294
  key === "internal" && Object.keys($$).forEach(function (k) {
@@ -9090,7 +9444,7 @@ extend(data, {
9090
9444
  * @function data․names
9091
9445
  * @instance
9092
9446
  * @memberof Chart
9093
- * @param {object} names If this argument is given, the names of data will be updated. If not given, the current names will be returned. The format of this argument is the same as
9447
+ * @param {object} names If this argument is given, the names of data will be updated. If not given, the current names will be returned. The format of this argument is the same as [data.names](./Options.html#.data%25E2%2580%25A4names).
9094
9448
  * @returns {object} Corresponding names according its key value, if specified names values.
9095
9449
  * @example
9096
9450
  * // Get current names
@@ -10735,130 +11089,139 @@ var apiFlow = {
10735
11089
  flow: function (args) {
10736
11090
  var $$ = this.internal;
10737
11091
  var data;
10738
- var domain;
10739
- var length = 0;
10740
- var tail = 0;
10741
- var diff;
10742
- var to;
10743
11092
  if (args.json || args.rows || args.columns) {
10744
- data = $$.convertData(args);
10745
- }
10746
- if ($$.state.redrawing || !data || !isTabVisible()) {
10747
- return;
11093
+ $$.convertData(args, function (res) {
11094
+ data = res;
11095
+ _();
11096
+ });
10748
11097
  }
10749
- var notfoundIds = [];
10750
- var orgDataCount = $$.getMaxDataCount();
10751
- var targets = $$.convertDataToTargets(data, true);
10752
- var isTimeSeries = $$.axis.isTimeSeries();
10753
- // Update/Add data
10754
- $$.data.targets.forEach(function (t) {
10755
- var found = false;
10756
- for (var i = 0; i < targets.length; i++) {
10757
- if (t.id === targets[i].id) {
10758
- found = true;
10759
- if (t.values[t.values.length - 1]) {
10760
- tail = t.values[t.values.length - 1].index + 1;
11098
+ /**
11099
+ * Process flows
11100
+ * @private
11101
+ */
11102
+ function _() {
11103
+ var domain;
11104
+ var length = 0;
11105
+ var tail = 0;
11106
+ var diff;
11107
+ var to;
11108
+ if ($$.state.redrawing || !data || !isTabVisible()) {
11109
+ return;
11110
+ }
11111
+ var notfoundIds = [];
11112
+ var orgDataCount = $$.getMaxDataCount();
11113
+ var targets = $$.convertDataToTargets(data, true);
11114
+ var isTimeSeries = $$.axis.isTimeSeries();
11115
+ // Update/Add data
11116
+ $$.data.targets.forEach(function (t) {
11117
+ var found = false;
11118
+ for (var i = 0; i < targets.length; i++) {
11119
+ if (t.id === targets[i].id) {
11120
+ found = true;
11121
+ if (t.values[t.values.length - 1]) {
11122
+ tail = t.values[t.values.length - 1].index + 1;
11123
+ }
11124
+ length = targets[i].values.length;
11125
+ for (var j = 0; j < length; j++) {
11126
+ targets[i].values[j].index = tail + j;
11127
+ if (!isTimeSeries) {
11128
+ targets[i].values[j].x = tail + j;
11129
+ }
11130
+ }
11131
+ t.values = t.values.concat(targets[i].values);
11132
+ targets.splice(i, 1);
11133
+ break;
10761
11134
  }
10762
- length = targets[i].values.length;
10763
- for (var j = 0; j < length; j++) {
10764
- targets[i].values[j].index = tail + j;
10765
- if (!isTimeSeries) {
10766
- targets[i].values[j].x = tail + j;
11135
+ }
11136
+ !found && notfoundIds.push(t.id);
11137
+ });
11138
+ // Append null for not found targets
11139
+ $$.data.targets.forEach(function (t) {
11140
+ for (var i = 0; i < notfoundIds.length; i++) {
11141
+ if (t.id === notfoundIds[i]) {
11142
+ tail = t.values[t.values.length - 1].index + 1;
11143
+ for (var j = 0; j < length; j++) {
11144
+ t.values.push({
11145
+ id: t.id,
11146
+ index: tail + j,
11147
+ x: isTimeSeries ? $$.getOtherTargetX(tail + j) : tail + j,
11148
+ value: null
11149
+ });
10767
11150
  }
10768
11151
  }
10769
- t.values = t.values.concat(targets[i].values);
10770
- targets.splice(i, 1);
10771
- break;
10772
11152
  }
10773
- }
10774
- !found && notfoundIds.push(t.id);
10775
- });
10776
- // Append null for not found targets
10777
- $$.data.targets.forEach(function (t) {
10778
- for (var i = 0; i < notfoundIds.length; i++) {
10779
- if (t.id === notfoundIds[i]) {
10780
- tail = t.values[t.values.length - 1].index + 1;
10781
- for (var j = 0; j < length; j++) {
10782
- t.values.push({
11153
+ });
11154
+ // Generate null values for new target
11155
+ if ($$.data.targets.length) {
11156
+ targets.forEach(function (t) {
11157
+ var missing = [];
11158
+ for (var i = $$.data.targets[0].values[0].index; i < tail; i++) {
11159
+ missing.push({
10783
11160
  id: t.id,
10784
- index: tail + j,
10785
- x: isTimeSeries ? $$.getOtherTargetX(tail + j) : tail + j,
11161
+ index: i,
11162
+ x: isTimeSeries ? $$.getOtherTargetX(i) : i,
10786
11163
  value: null
10787
11164
  });
10788
11165
  }
10789
- }
10790
- }
10791
- });
10792
- // Generate null values for new target
10793
- if ($$.data.targets.length) {
10794
- targets.forEach(function (t) {
10795
- var missing = [];
10796
- for (var i = $$.data.targets[0].values[0].index; i < tail; i++) {
10797
- missing.push({
10798
- id: t.id,
10799
- index: i,
10800
- x: isTimeSeries ? $$.getOtherTargetX(i) : i,
10801
- value: null
11166
+ t.values.forEach(function (v) {
11167
+ v.index += tail;
11168
+ if (!isTimeSeries) {
11169
+ v.x += tail;
11170
+ }
10802
11171
  });
10803
- }
10804
- t.values.forEach(function (v) {
10805
- v.index += tail;
10806
- if (!isTimeSeries) {
10807
- v.x += tail;
10808
- }
11172
+ t.values = missing.concat(t.values);
10809
11173
  });
10810
- t.values = missing.concat(t.values);
10811
- });
10812
- }
10813
- $$.data.targets = $$.data.targets.concat(targets); // add remained
10814
- // check data count because behavior needs to change when it"s only one
10815
- // const dataCount = $$.getMaxDataCount();
10816
- var baseTarget = $$.data.targets[0];
10817
- var baseValue = baseTarget.values[0];
10818
- // Update length to flow if needed
10819
- if (isDefined(args.to)) {
10820
- length = 0;
10821
- to = isTimeSeries ? parseDate.call($$, args.to) : args.to;
10822
- baseTarget.values.forEach(function (v) {
10823
- v.x < to && length++;
10824
- });
10825
- }
10826
- else if (isDefined(args.length)) {
10827
- length = args.length;
10828
- }
10829
- // If only one data, update the domain to flow from left edge of the chart
10830
- if (!orgDataCount) {
10831
- if (isTimeSeries) {
10832
- diff = baseTarget.values.length > 1 ?
10833
- baseTarget.values[baseTarget.values.length - 1].x - baseValue.x :
10834
- baseValue.x - $$.getXDomain($$.data.targets)[0];
10835
11174
  }
10836
- else {
10837
- diff = 1;
11175
+ $$.data.targets = $$.data.targets.concat(targets); // add remained
11176
+ // check data count because behavior needs to change when it"s only one
11177
+ // const dataCount = $$.getMaxDataCount();
11178
+ var baseTarget = $$.data.targets[0];
11179
+ var baseValue = baseTarget.values[0];
11180
+ // Update length to flow if needed
11181
+ if (isDefined(args.to)) {
11182
+ length = 0;
11183
+ to = isTimeSeries ? parseDate.call($$, args.to) : args.to;
11184
+ baseTarget.values.forEach(function (v) {
11185
+ v.x < to && length++;
11186
+ });
10838
11187
  }
10839
- domain = [baseValue.x - diff, baseValue.x];
10840
- }
10841
- else if (orgDataCount === 1 && isTimeSeries) {
10842
- diff = (baseTarget.values[baseTarget.values.length - 1].x - baseValue.x) / 2;
10843
- domain = [new Date(+baseValue.x - diff), new Date(+baseValue.x + diff)];
11188
+ else if (isDefined(args.length)) {
11189
+ length = args.length;
11190
+ }
11191
+ // If only one data, update the domain to flow from left edge of the chart
11192
+ if (!orgDataCount) {
11193
+ if (isTimeSeries) {
11194
+ diff = baseTarget.values.length > 1 ?
11195
+ baseTarget.values[baseTarget.values.length - 1].x - baseValue.x :
11196
+ baseValue.x - $$.getXDomain($$.data.targets)[0];
11197
+ }
11198
+ else {
11199
+ diff = 1;
11200
+ }
11201
+ domain = [baseValue.x - diff, baseValue.x];
11202
+ }
11203
+ else if (orgDataCount === 1 && isTimeSeries) {
11204
+ diff = (baseTarget.values[baseTarget.values.length - 1].x - baseValue.x) / 2;
11205
+ domain = [new Date(+baseValue.x - diff), new Date(+baseValue.x + diff)];
11206
+ }
11207
+ domain && $$.updateXDomain(null, true, true, false, domain);
11208
+ // Set targets
11209
+ $$.updateTargets($$.data.targets);
11210
+ // Redraw with new targets
11211
+ $$.redraw({
11212
+ flow: {
11213
+ index: baseValue.index,
11214
+ length: length,
11215
+ duration: isValue(args.duration) ? args.duration : $$.config.transition_duration,
11216
+ done: args.done,
11217
+ orgDataCount: orgDataCount
11218
+ },
11219
+ withLegend: true,
11220
+ withTransition: orgDataCount > 1,
11221
+ withTrimXDomain: false,
11222
+ withUpdateXAxis: true
11223
+ });
10844
11224
  }
10845
- domain && $$.updateXDomain(null, true, true, false, domain);
10846
- // Set targets
10847
- $$.updateTargets($$.data.targets);
10848
- // Redraw with new targets
10849
- $$.redraw({
10850
- flow: {
10851
- index: baseValue.index,
10852
- length: length,
10853
- duration: isValue(args.duration) ? args.duration : $$.config.transition_duration,
10854
- done: args.done,
10855
- orgDataCount: orgDataCount
10856
- },
10857
- withLegend: true,
10858
- withTransition: orgDataCount > 1,
10859
- withTrimXDomain: false,
10860
- withUpdateXAxis: true
10861
- });
10862
11225
  }
10863
11226
  };
10864
11227
 
@@ -11048,10 +11411,10 @@ var AxisRenderer = /** @class */ (function () {
11048
11411
  */
11049
11412
  AxisRenderer.prototype.create = function (g) {
11050
11413
  var ctx = this;
11051
- var _a = this, config = _a.config, helper = _a.helper, params = _a.params;
11414
+ var config = ctx.config, helper = ctx.helper, params = ctx.params;
11052
11415
  var scale = helper.scale;
11053
11416
  var orient = config.orient;
11054
- var splitTickText = this.splitTickText.bind(this);
11417
+ var splitTickText = this.splitTickText.bind(ctx);
11055
11418
  var isLeftRight = /^(left|right)$/.test(orient);
11056
11419
  var isTopBottom = /^(top|bottom)$/.test(orient);
11057
11420
  // line/text enter and path update
@@ -11100,6 +11463,8 @@ var AxisRenderer = /** @class */ (function () {
11100
11463
  if (tickShow.tick || tickShow.text) {
11101
11464
  // count of tick data in array
11102
11465
  var ticks_1 = config.tickValues || helper.generateTicks(scale1, isLeftRight);
11466
+ // set generated ticks
11467
+ ctx.generatedTicks = ticks_1;
11103
11468
  // update selection
11104
11469
  var tick = g.selectAll(".tick")
11105
11470
  .data(ticks_1, scale1);
@@ -11188,6 +11553,24 @@ var AxisRenderer = /** @class */ (function () {
11188
11553
  });
11189
11554
  this.g = $g;
11190
11555
  };
11556
+ /**
11557
+ * Get generated ticks
11558
+ * @param {number} count Count of ticks
11559
+ * @returns {Array} Generated ticks
11560
+ * @private
11561
+ */
11562
+ AxisRenderer.prototype.getGeneratedTicks = function (count) {
11563
+ var len = this.generatedTicks.length - 1;
11564
+ var res = this.generatedTicks;
11565
+ if (len > count) {
11566
+ var interval_1 = Math.round((len / count) - 0.1);
11567
+ res = this.generatedTicks
11568
+ .map(function (v, i) { return (i % interval_1 === 0 ? v : null); })
11569
+ .filter(function (v) { return v !== null; })
11570
+ .splice(0, count);
11571
+ }
11572
+ return res;
11573
+ };
11191
11574
  /**
11192
11575
  * Get tick x/y coordinate
11193
11576
  * @returns {{x: number, y: number}}
@@ -13090,10 +13473,10 @@ var grid = {
13090
13473
  },
13091
13474
  updateYGrid: function () {
13092
13475
  var $$ = this;
13093
- var config = $$.config, state = $$.state, _a = $$.$el, grid = _a.grid, main = _a.main;
13476
+ var axis = $$.axis, config = $$.config, scale = $$.scale, state = $$.state, _a = $$.$el, grid = _a.grid, main = _a.main;
13094
13477
  var isRotated = config.axis_rotated;
13095
- var gridValues = $$.axis.y.tickValues() || $$.scale.y.ticks(config.grid_y_ticks);
13096
- var pos = function (d) { return Math.ceil($$.scale.y(d)); };
13478
+ var pos = function (d) { return Math.ceil(scale.y(d)); };
13479
+ var gridValues = axis.y.getGeneratedTicks(config.grid_y_ticks) || $$.scale.y.ticks(config.grid_y_ticks);
13097
13480
  grid.y = main.select(".".concat($GRID.ygrids))
13098
13481
  .selectAll(".".concat($GRID.ygrid))
13099
13482
  .data(gridValues);
@@ -13532,8 +13915,9 @@ var sizeAxis = {
13532
13915
  var $$ = this;
13533
13916
  if ($$.axis) {
13534
13917
  var position = (_a = $$.axis) === null || _a === void 0 ? void 0 : _a.getLabelPositionById(id);
13535
- return $$.axis.getMaxTickWidth(id, withoutRecompute) +
13536
- (position.isInner ? 20 : 40);
13918
+ var width = $$.axis.getMaxTickWidth(id, withoutRecompute);
13919
+ var gap = width === 0 ? 0.5 : 0;
13920
+ return width + (position.isInner ? (20 + gap) : 40);
13537
13921
  }
13538
13922
  else {
13539
13923
  return 40;
@@ -16318,8 +16702,7 @@ var shapeArea = {
16318
16702
  .x0(value0)
16319
16703
  .x1(value1) :
16320
16704
  area.x(xValue)
16321
- // @ts-ignore
16322
- .y0(config.area_above ? 0 : value0)
16705
+ .y0(config.area_above ? 0 : (config.area_below ? $$.state.height : value0))
16323
16706
  .y1(value1);
16324
16707
  if (!lineConnectNull) {
16325
16708
  area = area.defined(function (d) { return $$.getBaseValue(d) !== null; });
@@ -16403,7 +16786,8 @@ var shapeBar = {
16403
16786
  // Bars for each data
16404
16787
  mainBarEnter.append("g")
16405
16788
  .attr("class", classBars)
16406
- .style("cursor", function (d) { var _a; return (((_a = isSelectable === null || isSelectable === void 0 ? void 0 : isSelectable.bind) === null || _a === void 0 ? void 0 : _a.call(isSelectable, $$.api)(d)) ? "pointer" : null); });
16789
+ .style("cursor", function (d) { var _a; return (((_a = isSelectable === null || isSelectable === void 0 ? void 0 : isSelectable.bind) === null || _a === void 0 ? void 0 : _a.call(isSelectable, $$.api)(d)) ? "pointer" : null); })
16790
+ .call($$.setColorByRule(null, $BAR.bar, ["fill"]));
16407
16791
  },
16408
16792
  /**
16409
16793
  * Generate/Update elements
@@ -16426,7 +16810,7 @@ var shapeBar = {
16426
16810
  .remove();
16427
16811
  $root.bar = bar.enter().append("path")
16428
16812
  .attr("class", classBar)
16429
- .style("fill", $$.color)
16813
+ .style("fill", $$.colorByRule)
16430
16814
  .merge(bar)
16431
16815
  .style("opacity", initialOpacity);
16432
16816
  },
@@ -16444,7 +16828,7 @@ var shapeBar = {
16444
16828
  return [
16445
16829
  $$.$T(bar, withTransition, getRandom())
16446
16830
  .attr("d", function (d) { return (isNumber(d.value) || $$.isBarRangeType(d)) && drawFn(d); })
16447
- .style("fill", this.color)
16831
+ .style("fill", $$.colorByRule)
16448
16832
  .style("opacity", null)
16449
16833
  ];
16450
16834
  },
@@ -16488,9 +16872,9 @@ var shapeBar = {
16488
16872
  var pathRadius = ["", ""];
16489
16873
  var radius = 0;
16490
16874
  var isGrouped = $$.isGrouped(d.id);
16491
- var hasRadius = d.value !== 0 && getRadius;
16492
- var isRadiusData = hasRadius && isGrouped ? $$.isStackingRadiusData(d) : false;
16493
- if (hasRadius && (!isGrouped || isRadiusData)) {
16875
+ // const hasRadius = d.value !== 0 && getRadius;
16876
+ var isRadiusData = getRadius && isGrouped ? $$.isStackingRadiusData(d) : false;
16877
+ if (getRadius && (!isGrouped || isRadiusData)) {
16494
16878
  var index = isRotated ? indexY : indexX;
16495
16879
  var barW = points[2][index] - points[0][index];
16496
16880
  radius = getRadius(barW);
@@ -16514,15 +16898,20 @@ var shapeBar = {
16514
16898
  */
16515
16899
  isStackingRadiusData: function (d) {
16516
16900
  var $$ = this;
16517
- var config = $$.config, data = $$.data;
16901
+ var $el = $$.$el, config = $$.config, data = $$.data, state = $$.state;
16518
16902
  var id = d.id, index = d.index, value = d.value;
16903
+ // when the data is hidden, check if has rounded edges
16904
+ if (state.hiddenTargetIds.indexOf(id) > -1) {
16905
+ var target = $el.bar.filter(function (d) { return d.id === id && d.value === value; });
16906
+ return !target.empty() && /a\d+/i.test(target.attr("d"));
16907
+ }
16519
16908
  // Find same grouped ids
16520
16909
  var keys = config.data_groups.find(function (v) { return v.indexOf(id) > -1; });
16521
16910
  // Get sorted list
16522
16911
  var sortedList = $$.orderTargets($$.filterTargetsToShow(data.targets.filter($$.isBarType, $$))).filter(function (v) { return keys.indexOf(v.id) > -1; });
16523
16912
  // Get sorted Ids. Filter positive or negative values Ids from given value
16524
16913
  var sortedIds = sortedList
16525
- .map(function (v) { return v.values.filter(function (v2) { return v2.index === index && (value > 0 ? v2.value > 0 : v2.value < 0); })[0]; })
16914
+ .map(function (v) { return v.values.filter(function (v2) { return v2.index === index && (isNumber(value) && value > 0 ? v2.value > 0 : v2.value < 0); })[0]; })
16526
16915
  .filter(Boolean)
16527
16916
  .map(function (v) { return v.id; });
16528
16917
  // If the given id stays in the last position, then radius should be applied.
@@ -16549,10 +16938,11 @@ var shapeBar = {
16549
16938
  var y0 = yScale.call($$, d.id, isSub)($$.getShapeYMin(d.id));
16550
16939
  var offset = barOffset(d, i) || y0; // offset is for stacked bar chart
16551
16940
  var width = isNumber(barW) ? barW : barW[d.id] || barW._$width;
16941
+ var value = d.value;
16552
16942
  var posX = barX(d);
16553
16943
  var posY = barY(d);
16554
16944
  // fix posY not to overflow opposite quadrant
16555
- if (config.axis_rotated && ((d.value > 0 && posY < y0) || (d.value < 0 && y0 < posY))) {
16945
+ if (config.axis_rotated && ((value > 0 && posY < y0) || (value < 0 && y0 < posY))) {
16556
16946
  posY = y0;
16557
16947
  }
16558
16948
  if (!$$.isBarRangeType(d)) {
@@ -17277,10 +17667,11 @@ var shapePoint = {
17277
17667
  enterNode.append("g")
17278
17668
  .attr("class", classCircles)
17279
17669
  .style("cursor", function (d) { return (isFunction(isSelectable) && isSelectable(d) ? "pointer" : null); })
17670
+ .call($$.setColorByRule(null, $CIRCLE.circle, ["fill", "stroke"]))
17280
17671
  .style("opacity", function () {
17281
- var _a;
17672
+ var parent = select(this.parentNode);
17282
17673
  // if the parent node is .bb-chart-circles (bubble, scatter), initialize <g bb-circles> with opacity "0"
17283
- return ((_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.classList.contains("bb-chart-circles")) ? "0" : null;
17674
+ return parent.attr("class").indexOf($CIRCLE.chartCircles) > -1 ? "0" : null;
17284
17675
  });
17285
17676
  // Update date for selected circles
17286
17677
  selectionEnabled && targets.forEach(function (t) {
@@ -17306,9 +17697,9 @@ var shapePoint = {
17306
17697
  circles.exit().remove();
17307
17698
  circles.enter()
17308
17699
  .filter(Boolean)
17309
- .append($$.point("create", this, $$.pointR.bind($$), $$.color));
17700
+ .append($$.point("create", this, $$.pointR.bind($$), $$.colorByRule));
17310
17701
  $root.circle = $root.main.selectAll(".".concat($CIRCLE.circles, " .").concat($CIRCLE.circle))
17311
- .style("stroke", $$.color)
17702
+ .style("stroke", $$.colorByRule)
17312
17703
  .style("opacity", $$.initialOpacityForCircle.bind($$));
17313
17704
  }
17314
17705
  },
@@ -17321,7 +17712,7 @@ var shapePoint = {
17321
17712
  if (!$$.config.point_show) {
17322
17713
  return [];
17323
17714
  }
17324
- var fn = $$.point("update", $$, cx, cy, $$.color, withTransition, flow, selectedCircles);
17715
+ var fn = $$.point("update", $$, cx, cy, $$.colorByRule, withTransition, flow, selectedCircles);
17325
17716
  var posAttr = $$.isCirclePoint() ? "c" : "";
17326
17717
  var t = getRandom();
17327
17718
  var opacityStyleFn = $$.opacityForCircle.bind($$);
@@ -17352,7 +17743,7 @@ var shapePoint = {
17352
17743
  var cx = (hasRadar ? $$.radarCircleX : $$.circleX).bind($$);
17353
17744
  var cy = (hasRadar ? $$.radarCircleY : $$.circleY).bind($$);
17354
17745
  var withTransition = toggling || isUndefined(d);
17355
- var fn_1 = $$.point("update", $$, cx, cy, $$.color, resizing ? false : withTransition);
17746
+ var fn_1 = $$.point("update", $$, cx, cy, $$.colorByRule, resizing ? false : withTransition);
17356
17747
  if (d) {
17357
17748
  circle = circle
17358
17749
  .filter(function (t) {
@@ -17437,8 +17828,10 @@ var shapePoint = {
17437
17828
  })
17438
17829
  .classed($COMMON.EXPANDED, false);
17439
17830
  circles.attr("r", r);
17440
- !$$.isCirclePoint() &&
17441
- circles.attr("transform", "scale(".concat(r(circles) / $$.config.point_r, ")"));
17831
+ if (!$$.isCirclePoint()) {
17832
+ var scale = r(circles) / $$.config.point_r;
17833
+ circles.attr("transform", scale !== 1 ? "scale(".concat(scale, ")") : null);
17834
+ }
17442
17835
  },
17443
17836
  pointR: function (d) {
17444
17837
  var $$ = this;
@@ -17592,7 +17985,7 @@ var shapePoint = {
17592
17985
  };
17593
17986
  },
17594
17987
  custom: {
17595
- create: function (element, id, sizeFn, fillStyleFn) {
17988
+ create: function (element, id, fillStyleFn) {
17596
17989
  return element.append("use")
17597
17990
  .attr("xlink:href", "#".concat(id))
17598
17991
  .attr("class", this.updatePointClass.bind(this))
@@ -17720,8 +18113,9 @@ var shapePolar = {
17720
18113
  * @private
17721
18114
  */
17722
18115
  getPolarOuterRadius: function (d, outerRadius) {
18116
+ var _a;
17723
18117
  var dataMax = getDataMax(this);
17724
- return ((d === null || d === void 0 ? void 0 : d.data.values[0].value) / dataMax) * outerRadius;
18118
+ return (((_a = d === null || d === void 0 ? void 0 : d.data.values[0].value) !== null && _a !== void 0 ? _a : 0) / dataMax) * outerRadius;
17725
18119
  },
17726
18120
  /**
17727
18121
  * Update polar based on given data array
@@ -18211,7 +18605,9 @@ var optArea = {
18211
18605
  * @memberof Options
18212
18606
  * @type {object}
18213
18607
  * @property {object} area Area object
18214
- * @property {boolean} [area.above=false] Set background area above the data chart line.
18608
+ * @property {boolean} [area.above=false] Set background area `above` the data chart line.
18609
+ * @property {boolean} [area.below=false] Set background area `below` the data chart line.
18610
+ * - **NOTE**: Can't be used along with `above` option. When above & below options are set to true, `above` will be prioritized.
18215
18611
  * @property {boolean} [area.front=true] Set area node to be positioned over line node.
18216
18612
  * @property {boolean|object} [area.linearGradient=false] Set the linear gradient on area.<br><br>
18217
18613
  * Or customize by giving below object value:
@@ -18222,10 +18618,12 @@ var optArea = {
18222
18618
  * @see [MDN's &lt;linearGradient>](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient), [&lt;stop>](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/stop)
18223
18619
  * @see [Demo](https://naver.github.io/billboard.js/demo/#Chart.AreaChart)
18224
18620
  * @see [Demo: above](https://naver.github.io/billboard.js/demo/#AreaChartOptions.Above)
18621
+ * @see [Demo: below](https://naver.github.io/billboard.js/demo/#AreaChartOptions.Below)
18225
18622
  * @see [Demo: linearGradient](https://naver.github.io/billboard.js/demo/#AreaChartOptions.LinearGradient)
18226
18623
  * @example
18227
18624
  * area: {
18228
18625
  * above: true,
18626
+ * below: false,
18229
18627
  * zerobased: false,
18230
18628
  *
18231
18629
  * // <g class='bb-areas'> will be positioned behind the line <g class='bb-lines'> in stacking order
@@ -18257,6 +18655,7 @@ var optArea = {
18257
18655
  * }
18258
18656
  */
18259
18657
  area_above: false,
18658
+ area_below: false,
18260
18659
  area_front: true,
18261
18660
  area_linearGradient: false,
18262
18661
  area_zerobased: true
@@ -20174,18 +20573,28 @@ var zoom = {
20174
20573
  /**
20175
20574
  * Update scale according zoom transform value
20176
20575
  * @param {object} transform transform object
20576
+ * @param {boolean} correctTransform if the d3 transform should be updated after rescaling
20177
20577
  * @private
20178
20578
  */
20179
20579
  // @ts-ignore
20180
- zoom.updateTransformScale = function (transform) {
20580
+ zoom.updateTransformScale = function (transform, correctTransform) {
20181
20581
  var _a;
20582
+ var isRotated = config.axis_rotated;
20182
20583
  // in case of resize, update range of orgXScale
20183
20584
  (_a = org.xScale) === null || _a === void 0 ? void 0 : _a.range(scale.x.range());
20184
20585
  // rescale from the original scale
20185
- var newScale = transform[config.axis_rotated ? "rescaleY" : "rescaleX"](org.xScale || scale.x);
20586
+ var newScale = transform[isRotated ? "rescaleY" : "rescaleX"](org.xScale || scale.x);
20186
20587
  var domain = $$.trimXDomain(newScale.domain());
20187
20588
  var rescale = config.zoom_rescale;
20188
20589
  newScale.domain(domain, org.xDomain);
20590
+ // prevent chart from panning off the edge and feeling "stuck"
20591
+ // https://github.com/naver/billboard.js/issues/2588
20592
+ if (correctTransform) {
20593
+ var t = newScale(scale.x.domain()[0]);
20594
+ var tX = isRotated ? transform.x : t;
20595
+ var tY = isRotated ? t : transform.y;
20596
+ $$.$el.eventRect.property("__zoom", zoomIdentity.translate(tX, tY).scale(transform.k));
20597
+ }
20189
20598
  if (!$$.state.xTickOffset) {
20190
20599
  $$.state.xTickOffset = $$.axis.x.tickOffset();
20191
20600
  }
@@ -20251,7 +20660,7 @@ var zoom = {
20251
20660
  if (!isMousemove && isZoomOut && scale.x.domain().every(function (v, i) { return v !== org.xDomain[i]; })) {
20252
20661
  scale.x.domain(org.xDomain);
20253
20662
  }
20254
- $$.zoom.updateTransformScale(transform);
20663
+ $$.zoom.updateTransformScale(transform, config.zoom_type === "wheel" && sourceEvent);
20255
20664
  // do zoom transiton when:
20256
20665
  // - zoom type 'drag'
20257
20666
  // - when .unzoom() is called (event.transform === d3ZoomIdentity)
@@ -20737,7 +21146,7 @@ var zoomModule = function () {
20737
21146
  var defaults = {};
20738
21147
  /**
20739
21148
  * @namespace bb
20740
- * @version 3.4.0
21149
+ * @version 3.5.0-next.2
20741
21150
  */
20742
21151
  var bb = {
20743
21152
  /**
@@ -20747,7 +21156,7 @@ var bb = {
20747
21156
  * bb.version; // "1.0.0"
20748
21157
  * @memberof bb
20749
21158
  */
20750
- version: "3.4.0",
21159
+ version: "3.5.0-next.2",
20751
21160
  /**
20752
21161
  * Generate chart
20753
21162
  * - **NOTE:** Bear in mind for the possiblity of ***throwing an error***, during the generation when: