billboard.js 3.3.3 → 3.4.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 (61) hide show
  1. package/dist/billboard.css +19 -14
  2. package/dist/billboard.js +343 -60
  3. package/dist/billboard.min.css +2 -2
  4. package/dist/billboard.min.js +2 -2
  5. package/dist/billboard.pkgd.js +343 -60
  6. package/dist/billboard.pkgd.min.js +2 -2
  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 +27 -15
  10. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  11. package/dist/plugin/billboardjs-plugin-stanford.js +27 -15
  12. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-tableview.js +22 -12
  14. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  15. package/dist/plugin/billboardjs-plugin-textoverlap.js +22 -12
  16. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  17. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +2 -2
  18. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +27 -15
  19. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +27 -15
  20. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +22 -12
  21. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +22 -12
  22. package/dist/theme/datalab.css +24 -20
  23. package/dist/theme/datalab.min.css +2 -2
  24. package/dist/theme/graph.css +24 -20
  25. package/dist/theme/graph.min.css +2 -2
  26. package/dist/theme/insight.css +24 -20
  27. package/dist/theme/insight.min.css +2 -2
  28. package/dist-esm/billboard.js +310 -52
  29. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  30. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +3 -5
  31. package/dist-esm/plugin/billboardjs-plugin-stanford.js +3 -5
  32. package/dist-esm/plugin/billboardjs-plugin-tableview.js +2 -2
  33. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
  34. package/package.json +19 -19
  35. package/src/Chart/api/focus.ts +3 -2
  36. package/src/ChartInternal/Axis/Axis.ts +8 -6
  37. package/src/ChartInternal/ChartInternal.ts +23 -12
  38. package/src/ChartInternal/data/data.ts +1 -1
  39. package/src/ChartInternal/internals/color.ts +4 -3
  40. package/src/ChartInternal/internals/format.ts +5 -1
  41. package/src/ChartInternal/internals/redraw.ts +3 -0
  42. package/src/ChartInternal/internals/text.ts +1 -1
  43. package/src/ChartInternal/internals/transform.ts +4 -1
  44. package/src/ChartInternal/internals/type.ts +5 -0
  45. package/src/ChartInternal/shape/arc.ts +41 -17
  46. package/src/ChartInternal/shape/polar.ts +132 -0
  47. package/src/ChartInternal/shape/radar.ts +4 -4
  48. package/src/config/Options/data/data.ts +3 -0
  49. package/src/config/Options/shape/polar.ts +81 -0
  50. package/src/config/classes.ts +6 -3
  51. package/src/config/const.ts +3 -0
  52. package/src/config/resolver/shape.ts +4 -0
  53. package/src/core.ts +1 -0
  54. package/src/index.esm.ts +1 -0
  55. package/src/module/util.ts +18 -7
  56. package/src/scss/billboard.scss +13 -0
  57. package/src/scss/theme/datalab.scss +13 -0
  58. package/src/scss/theme/graph.scss +13 -0
  59. package/src/scss/theme/insight.scss +13 -0
  60. package/types/bb.d.ts +1 -0
  61. package/types/options.d.ts +72 -0
@@ -5,7 +5,7 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 3.3.3
8
+ * @version 3.4.0-next.1
9
9
  * @requires billboard.js
10
10
  * @summary billboard.js plugin
11
11
  */
@@ -142,7 +142,7 @@ var Plugin = /*#__PURE__*/function () {
142
142
  return Plugin;
143
143
  }();
144
144
 
145
- Plugin.version = "#3.3.3#";
145
+ Plugin.version = "#3.4.0-next.1#";
146
146
 
147
147
  /**
148
148
  * Bubble compare diagram plugin.<br>
@@ -5,7 +5,7 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 3.3.3
8
+ * @version 3.4.0-next.1
9
9
  * @requires billboard.js
10
10
  * @summary billboard.js plugin
11
11
  */
@@ -190,9 +190,7 @@ var $GRID = {
190
190
  };
191
191
  var $RADAR = {
192
192
  chartRadar: "bb-chart-radar",
193
- chartRadars: "bb-chart-radars",
194
- level: "bb-level",
195
- levels: "bb-levels"
193
+ chartRadars: "bb-chart-radars"
196
194
  };
197
195
  var $REGION = {
198
196
  region: "bb-region",
@@ -319,7 +317,7 @@ var Plugin = /*#__PURE__*/function () {
319
317
  return Plugin;
320
318
  }();
321
319
 
322
- Plugin.version = "#3.3.3#";
320
+ Plugin.version = "#3.4.0-next.1#";
323
321
 
324
322
  /**
325
323
  * Copyright (c) 2021 ~ present NAVER Corp.
@@ -5,7 +5,7 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 3.3.3
8
+ * @version 3.4.0-next.1
9
9
  * @requires billboard.js
10
10
  * @summary billboard.js plugin
11
11
  */
@@ -196,9 +196,7 @@ var $GRID = {
196
196
  };
197
197
  var $RADAR = {
198
198
  chartRadar: "bb-chart-radar",
199
- chartRadars: "bb-chart-radars",
200
- level: "bb-level",
201
- levels: "bb-levels"
199
+ chartRadars: "bb-chart-radars"
202
200
  };
203
201
  var $REGION = {
204
202
  region: "bb-region",
@@ -519,7 +517,7 @@ var Plugin = /*#__PURE__*/function () {
519
517
  return Plugin;
520
518
  }();
521
519
 
522
- Plugin.version = "#3.3.3#";
520
+ Plugin.version = "#3.4.0-next.1#";
523
521
 
524
522
  /**
525
523
  * Copyright (c) 2017 ~ present NAVER Corp.
@@ -5,7 +5,7 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 3.3.3
8
+ * @version 3.4.0-next.1
9
9
  * @requires billboard.js
10
10
  * @summary billboard.js plugin
11
11
  */
@@ -165,7 +165,7 @@ var Plugin = /*#__PURE__*/function () {
165
165
  return Plugin;
166
166
  }();
167
167
 
168
- Plugin.version = "#3.3.3#";
168
+ Plugin.version = "#3.4.0-next.1#";
169
169
 
170
170
  /**
171
171
  * Copyright (c) 2021 ~ present NAVER Corp.
@@ -5,7 +5,7 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 3.3.3
8
+ * @version 3.4.0-next.1
9
9
  * @requires billboard.js
10
10
  * @summary billboard.js plugin
11
11
  */
@@ -296,7 +296,7 @@ var Plugin = /*#__PURE__*/function () {
296
296
  return Plugin;
297
297
  }();
298
298
 
299
- Plugin.version = "#3.3.3#";
299
+ Plugin.version = "#3.4.0-next.1#";
300
300
 
301
301
  /**
302
302
  * Copyright (c) 2017 ~ present NAVER Corp.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "billboard.js",
3
- "version": "3.3.3",
3
+ "version": "3.4.0-next.1",
4
4
  "description": "Re-usable easy interface JavaScript chart library, based on D3 v4+",
5
5
  "homepage": "https://naver.github.io/billboard.js/",
6
6
  "main": "dist/billboard.js",
@@ -95,32 +95,32 @@
95
95
  "d3-zoom": "^3.0.0"
96
96
  },
97
97
  "devDependencies": {
98
- "@babel/core": "^7.17.5",
98
+ "@babel/core": "^7.17.7",
99
99
  "@babel/eslint-parser": "^7.17.0",
100
100
  "@babel/plugin-proposal-class-properties": "^7.16.7",
101
101
  "@babel/plugin-proposal-object-rest-spread": "^7.17.3",
102
102
  "@babel/plugin-transform-runtime": "^7.17.0",
103
103
  "@babel/preset-env": "^7.16.8",
104
104
  "@babel/preset-typescript": "^7.16.7",
105
- "@babel/runtime": "^7.17.2",
105
+ "@babel/runtime": "^7.17.7",
106
106
  "@commitlint/cli": "^15.0.0",
107
107
  "@commitlint/config-conventional": "^16.2.1",
108
- "@rollup/plugin-babel": "^5.3.0",
108
+ "@rollup/plugin-babel": "^5.3.1",
109
109
  "@rollup/plugin-node-resolve": "^13.1.3",
110
- "@rollup/plugin-replace": "^3.1.0",
111
- "@rollup/plugin-typescript": "^8.3.0",
110
+ "@rollup/plugin-replace": "^4.0.0",
111
+ "@rollup/plugin-typescript": "^8.3.1",
112
112
  "@semantic-release/changelog": "^6.0.1",
113
113
  "@semantic-release/commit-analyzer": "^9.0.2",
114
114
  "@semantic-release/exec": "^6.0.3",
115
115
  "@semantic-release/git": "^10.0.1",
116
- "@semantic-release/npm": "^9.0.0",
116
+ "@semantic-release/npm": "^9.0.1",
117
117
  "@semantic-release/release-notes-generator": "^10.0.3",
118
118
  "@types/chai": "^4.3.0",
119
119
  "@types/d3": "^7.1.0",
120
120
  "@types/mocha": "^9.0.0",
121
121
  "@types/sinon": "^10.0.11",
122
- "@typescript-eslint/eslint-plugin": "^5.12.1",
123
- "@typescript-eslint/parser": "^5.12.1",
122
+ "@typescript-eslint/eslint-plugin": "^5.15.0",
123
+ "@typescript-eslint/parser": "^5.15.0",
124
124
  "babel-helper-modules": "^6.0.0",
125
125
  "babel-loader": "^8.2.3",
126
126
  "babel-plugin-add-module-exports": "^1.0.4",
@@ -139,7 +139,7 @@
139
139
  "core-js": "^3.21.1",
140
140
  "coveralls": "^3.1.1",
141
141
  "cross-env": "^7.0.3",
142
- "css-loader": "^6.6.0",
142
+ "css-loader": "^6.7.1",
143
143
  "css-minimizer-webpack-plugin": "^3.3.1",
144
144
  "d3-color": "^3.0.1",
145
145
  "d3-delaunay": "^6.0.2",
@@ -147,10 +147,10 @@
147
147
  "d3-polygon": "^3.0.1",
148
148
  "docdash": "^1.2.0",
149
149
  "dtslint": "^4.2.1",
150
- "eslint": "^8.9.0",
150
+ "eslint": "^8.11.0",
151
151
  "eslint-config-naver": "^2.1.0",
152
152
  "eslint-plugin-import": "^2.25.4",
153
- "eslint-plugin-jsdoc": "^37.9.4",
153
+ "eslint-plugin-jsdoc": "^38.0.4",
154
154
  "eslint-webpack-plugin": "^3.1.1",
155
155
  "exports-loader": "^3.1.0",
156
156
  "hammer-simulator": "0.0.1",
@@ -158,9 +158,9 @@
158
158
  "istanbul-instrumenter-loader": "^3.0.1",
159
159
  "istanbul-lib-instrument": "^5.1.0",
160
160
  "jsdoc": "^3.6.10",
161
- "karma": "^6.3.16",
161
+ "karma": "^6.3.17",
162
162
  "karma-chai": "^0.1.0",
163
- "karma-chrome-launcher": "^3.1.0",
163
+ "karma-chrome-launcher": "^3.1.1",
164
164
  "karma-coverage-istanbul-reporter": "^3.0.3",
165
165
  "karma-mocha": "^2.0.1",
166
166
  "karma-mocha-reporter": "^2.2.3",
@@ -169,11 +169,11 @@
169
169
  "karma-sourcemap-loader": "^0.3.8",
170
170
  "karma-webpack": "^5.0.0",
171
171
  "lite-fixture": "^1.0.2",
172
- "mini-css-extract-plugin": "^2.5.2",
173
- "mocha": "^9.2.1",
172
+ "mini-css-extract-plugin": "^2.6.0",
173
+ "mocha": "^9.2.2",
174
174
  "node-sass": "^7.0.1",
175
175
  "regenerator-runtime": "^0.13.7",
176
- "rollup": "^2.67.3",
176
+ "rollup": "^2.70.1",
177
177
  "rollup-plugin-delete": "^2.0.0",
178
178
  "sass-loader": "^12.6.0",
179
179
  "semantic-release": "^19.0.2",
@@ -183,8 +183,8 @@
183
183
  "style-loader": "^3.3.1",
184
184
  "terser-webpack-plugin": "^5.3.1",
185
185
  "tslib": "^2.3.1",
186
- "typescript": "^4.5.4",
187
- "webpack": "^5.69.1",
186
+ "typescript": "^4.6.2",
187
+ "webpack": "^5.70.0",
188
188
  "webpack-bundle-analyzer": "^4.5.0",
189
189
  "webpack-clean": "^1.2.5",
190
190
  "webpack-cli": "^4.9.1",
@@ -78,7 +78,7 @@ export default {
78
78
 
79
79
  candidates.classed($FOCUS.focused, false).classed($FOCUS.defocused, true);
80
80
 
81
- if ($$.hasArcType()) {
81
+ if ($$.hasArcType(null, ["polar"])) {
82
82
  $$.unexpandArc(targetIds);
83
83
 
84
84
  $$.hasType("gauge") &&
@@ -115,7 +115,8 @@ export default {
115
115
  const candidates = $el.svg.selectAll($$.selectorTargets(targetIds)); // should be for all targets
116
116
 
117
117
  candidates.classed($FOCUS.focused, false).classed($FOCUS.defocused, false);
118
- $$.hasArcType() && $$.unexpandArc(targetIds);
118
+
119
+ $$.hasArcType(null, ["polar"]) && $$.unexpandArc(targetIds);
119
120
 
120
121
  if (config.legend_show) {
121
122
  $$.showLegend(targetIds.filter($$.isLegendToShow.bind($$)));
@@ -894,7 +894,7 @@ class Axis {
894
894
  const prefix = `axis_${key}_`;
895
895
  const axisScale = scale[key];
896
896
 
897
- if (config[`${prefix}show`] && axisScale) {
897
+ if (axisScale) {
898
898
  const tickValues = config[`${prefix}tick_values`];
899
899
  const tickCount = config[`${prefix}tick_count`];
900
900
 
@@ -941,6 +941,7 @@ class Axis {
941
941
  const $$ = this.owner;
942
942
  const {config, state: {clip, current}, $el} = $$;
943
943
 
944
+
944
945
  ["subX", "x", "y", "y2"].forEach(type => {
945
946
  const axis = $el.axis[type];
946
947
 
@@ -966,13 +967,14 @@ class Axis {
966
967
  }
967
968
  }
968
969
 
969
- tickNodes.each(function(d) {
970
- if (tickValues.indexOf(d) % intervalForCulling) {
970
+ tickNodes
971
+ .each(function(d) {
971
972
  const node = (lines ? this.querySelector("text") : this);
972
973
 
973
- node && (node.style.display = "none");
974
- }
975
- });
974
+ if (node) {
975
+ node.style.display = tickValues.indexOf(d) % intervalForCulling ? "none" : null;
976
+ }
977
+ });
976
978
  } else {
977
979
  tickNodes.style("display", null);
978
980
  }
@@ -313,6 +313,7 @@ export default class ChartInternal {
313
313
  const {config, scale, state, $el, org} = $$;
314
314
  const {hasAxis} = state;
315
315
  const hasInteraction = config.interaction_enabled;
316
+ const hasPolar = $$.hasType("polar");
316
317
 
317
318
  // for arc type, set axes to not be shown
318
319
  // $$.hasArcType() && ["x", "y", "y2"].forEach(id => (config[`axis_${id}_show`] = false));
@@ -387,7 +388,7 @@ export default class ChartInternal {
387
388
  // Define defs
388
389
  const hasColorPatterns = (isFunction(config.color_tiles) && $$.patterns);
389
390
 
390
- if (hasAxis || hasColorPatterns || config.data_labels_backgroundColors) {
391
+ if (hasAxis || hasColorPatterns || config.data_labels_backgroundColors || hasPolar) {
391
392
  $el.defs = $el.svg.append("defs");
392
393
 
393
394
  if (hasAxis) {
@@ -396,7 +397,7 @@ export default class ChartInternal {
396
397
  });
397
398
  }
398
399
 
399
- // Append data backgound color filter definition
400
+ // Append data background color filter definition
400
401
  $$.generateDataLabelBackgroundColorFilter();
401
402
 
402
403
  // set color patterns
@@ -512,6 +513,8 @@ export default class ChartInternal {
512
513
  }
513
514
  });
514
515
  } else {
516
+ const hasPolar = $$.hasType("polar");
517
+
515
518
  if (!hasRadar) {
516
519
  types.push("Arc", "Pie");
517
520
  }
@@ -520,6 +523,8 @@ export default class ChartInternal {
520
523
  types.push("Gauge");
521
524
  } else if (hasRadar) {
522
525
  types.push("Radar");
526
+ } else if (hasPolar) {
527
+ types.push("Polar");
523
528
  }
524
529
  }
525
530
 
@@ -600,6 +605,9 @@ export default class ChartInternal {
600
605
  updateTargets(targets): void {
601
606
  const $$ = <any> this;
602
607
  const {hasAxis, hasRadar} = $$.state;
608
+ const helper = type => $$[`updateTargetsFor${type}`](
609
+ targets.filter($$[`is${type}Type`].bind($$))
610
+ );
603
611
 
604
612
  // Text
605
613
  $$.updateTargetsForText(targets);
@@ -609,22 +617,25 @@ export default class ChartInternal {
609
617
  const name = capitalize(v);
610
618
 
611
619
  if ((v === "line" && $$.hasTypeOf(name)) || $$.hasType(v)) {
612
- $$[`updateTargetsFor${name}`](
613
- targets.filter($$[`is${name}Type`].bind($$))
614
- );
620
+ helper(name);
615
621
  }
616
622
  });
617
623
 
618
624
  // Sub Chart
619
625
  $$.updateTargetsForSubchart &&
620
626
  $$.updateTargetsForSubchart(targets);
621
- } else {
622
- // Arc & Radar
623
- $$.hasArcType(targets) && (
624
- hasRadar ?
625
- $$.updateTargetsForRadar(targets.filter($$.isRadarType.bind($$))) :
626
- $$.updateTargetsForArc(targets.filter($$.isArcType.bind($$)))
627
- );
627
+
628
+ // Arc, Polar, Radar
629
+ } else if ($$.hasArcType(targets)) {
630
+ let type = "Arc";
631
+
632
+ if (hasRadar) {
633
+ type = "Radar";
634
+ } else if ($$.hasType("polar")) {
635
+ type = "Polar";
636
+ }
637
+
638
+ helper(type);
628
639
  }
629
640
 
630
641
  // circle
@@ -271,7 +271,7 @@ export default {
271
271
  * @private
272
272
  * @returns {{min: Array, max: Array}}
273
273
  */
274
- getMinMaxData() {
274
+ getMinMaxData(): {min: IDataRow[], max: IDataRow[]} {
275
275
  const $$ = this;
276
276
  const cacheKey = KEY.dataMinMax;
277
277
  let minMaxData = $$.cache.get(cacheKey);
@@ -160,12 +160,13 @@ export default {
160
160
 
161
161
  /**
162
162
  * Append data backgound color filter definition
163
+ * @param {string} color Color string
163
164
  * @private
164
165
  */
165
- generateDataLabelBackgroundColorFilter(): void {
166
+ generateDataLabelBackgroundColorFilter(color?: string): void {
166
167
  const $$ = this;
167
168
  const {$el, config, state} = $$;
168
- const backgroundColors = config.data_labels_backgroundColors;
169
+ const backgroundColors = color || config.data_labels_backgroundColors;
169
170
 
170
171
  if (backgroundColors) {
171
172
  let ids: string[] = [];
@@ -177,7 +178,7 @@ export default {
177
178
  }
178
179
 
179
180
  ids.forEach(v => {
180
- const id = `${state.datetimeId}-labels-bg${$$.getTargetSelectorSuffix(v)}`;
181
+ const id = `${state.datetimeId}-labels-bg${$$.getTargetSelectorSuffix(v)}${color ? $$.getTargetSelectorSuffix(color) : ""}`;
181
182
 
182
183
  $el.defs.append("filter")
183
184
  .attr("x", "0")
@@ -39,7 +39,7 @@ export default {
39
39
  getDefaultValueFormat(): Function {
40
40
  const $$ = this;
41
41
  const {defaultArcValueFormat, yFormat, y2Format} = $$;
42
- const hasArc = $$.hasArcType(null, ["gauge", "radar"]);
42
+ const hasArc = $$.hasArcType(null, ["gauge", "polar", "radar"]);
43
43
 
44
44
  return function(v, ratio, id) {
45
45
  const format = hasArc ? defaultArcValueFormat : (
@@ -58,6 +58,10 @@ export default {
58
58
  return `${(ratio * 100).toFixed(1)}%`;
59
59
  },
60
60
 
61
+ defaultPolarValueFormat(v): string {
62
+ return `${v}`;
63
+ },
64
+
61
65
  dataLabelFormat(targetId: string): Function {
62
66
  const $$ = this;
63
67
  const dataLabels = $$.config.data_labels;
@@ -85,6 +85,9 @@ export default {
85
85
 
86
86
  // radar
87
87
  $el.radar && $$.redrawRadar();
88
+
89
+ // polar
90
+ $el.polar && $$.redrawPolar();
88
91
  }
89
92
 
90
93
  // @TODO: Axis & Radar type
@@ -501,7 +501,7 @@ export default {
501
501
  * @returns {boolean}
502
502
  * @private
503
503
  */
504
- meetsLabelThreshold(ratio: number = 0, type: "bar" | "donut" | "gauge" | "pie"): boolean {
504
+ meetsLabelThreshold(ratio: number = 0, type: "bar" | "donut" | "gauge" | "pie" | "polar"): boolean {
505
505
  const $$ = this;
506
506
  const {config} = $$;
507
507
  const threshold = config[`${type}_label_threshold`] || 0;
@@ -5,7 +5,7 @@
5
5
  import {$ARC, $AXIS} from "../../config/classes";
6
6
  import {asHalfPixel} from "../../module/util";
7
7
 
8
- type TranslateParam = "main" | "context" | "legend" | "x" | "y" | "y2" | "subX" | "arc" | "radar";
8
+ type TranslateParam = "main" | "context" | "legend" | "x" | "y" | "y2" | "subX" | "arc" | "radar" | "polar";
9
9
 
10
10
  export default {
11
11
  getTranslate(target: TranslateParam, index = 0): string {
@@ -44,6 +44,9 @@ export default {
44
44
  } else if (target === "arc") {
45
45
  x = state.arcWidth / 2;
46
46
  y = state.arcHeight / 2;
47
+ } else if (target === "polar") {
48
+ x = state.arcWidth / 2;
49
+ y = state.arcHeight / 2;
47
50
  } else if (target === "radar") {
48
51
  const [width] = $$.getRadarSize();
49
52
 
@@ -187,6 +187,10 @@ export default {
187
187
  return this.isTypeOf(d, "donut");
188
188
  },
189
189
 
190
+ isPolarType(d): boolean {
191
+ return this.isTypeOf(d, "polar");
192
+ },
193
+
190
194
  isRadarType(d): boolean {
191
195
  return this.isTypeOf(d, "radar");
192
196
  },
@@ -195,6 +199,7 @@ export default {
195
199
  return this.isPieType(d) ||
196
200
  this.isDonutType(d) ||
197
201
  this.isGaugeType(d) ||
202
+ this.isPolarType(d) ||
198
203
  this.isRadarType(d);
199
204
  },
200
205
 
@@ -12,17 +12,17 @@ import {document} from "../../module/browser";
12
12
  import {$ARC, $COMMON, $FOCUS, $GAUGE} from "../../config/classes";
13
13
  import {callFn, endall, isFunction, isNumber, isObject, isUndefined, setTextValue} from "../../module/util";
14
14
  import {d3Selection} from "../../../types/types";
15
- import {IData} from "../data/IData";
15
+ import {IArcData, IData} from "../data/IData";
16
16
 
17
17
  export default {
18
18
  initPie(): void {
19
19
  const $$ = this;
20
20
  const {config} = $$;
21
21
  const dataType = config.data_type;
22
- const padding = config.pie_padding;
22
+ const padding = config[`${dataType}_padding`];
23
23
  const startingAngle = config[`${dataType}_startingAngle`] || 0;
24
24
  const padAngle = (
25
- $$.hasType("pie") && padding ? padding * 0.01 :
25
+ padding ? padding * 0.01 :
26
26
  config[`${dataType}_padAngle`]
27
27
  ) || 0;
28
28
 
@@ -37,7 +37,8 @@ export default {
37
37
  updateRadius(): void {
38
38
  const $$ = this;
39
39
  const {config, state} = $$;
40
- const padding = config.pie_padding;
40
+ const dataType = config.data_type;
41
+ const padding = config[`${dataType}_padding`];
41
42
  const w = config.gauge_width || config.donut_width;
42
43
  const gaugeArcWidth = $$.filterTargetsToShow($$.data.targets).length *
43
44
  config.gauge_arcs_minWidth;
@@ -72,7 +73,7 @@ export default {
72
73
  * @returns {object}
73
74
  * @private
74
75
  */
75
- getRadius(d): {innerRadius: number, outerRadius: number} {
76
+ getRadius(d: IArcData): {innerRadius: number, outerRadius: number} {
76
77
  const $$ = this;
77
78
  const data = d?.data;
78
79
  let {innerRadius, outerRadius} = $$.state;
@@ -194,6 +195,7 @@ export default {
194
195
  const {state} = $$;
195
196
  const singleArcWidth = state.gaugeArcWidth / $$.filterTargetsToShow($$.data.targets).length;
196
197
  const hasMultiArcGauge = $$.hasMultiArcGauge();
198
+ const hasPolar = $$.hasType("polar");
197
199
 
198
200
  const arc = d3Arc()
199
201
  .innerRadius((d: any) => {
@@ -205,8 +207,15 @@ export default {
205
207
  })
206
208
  .outerRadius((d: any) => {
207
209
  const {outerRadius} = $$.getRadius(d);
210
+ let radius = outerRadius;
208
211
 
209
- return hasMultiArcGauge ? (state.radius - singleArcWidth * d.index) : outerRadius;
212
+ if (hasMultiArcGauge) {
213
+ radius = state.radius - singleArcWidth * d.index;
214
+ } else if (hasPolar) {
215
+ radius = $$.getPolarOuterRadius(d, outerRadius);
216
+ }
217
+
218
+ return radius;
210
219
  });
211
220
 
212
221
  const newArc = function(d, withoutUpdate) {
@@ -253,6 +262,7 @@ export default {
253
262
  radius = state.radius - singleArcWidth * d.index + expandWidth;
254
263
  } else {
255
264
  const {outerRadius} = $$.getRadius(d);
265
+
256
266
  let {radiusExpanded} = state;
257
267
 
258
268
  if (state.radius !== outerRadius) {
@@ -276,6 +286,12 @@ export default {
276
286
  return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0";
277
287
  },
278
288
 
289
+ /**
290
+ * Set transform attributes to arc label text
291
+ * @param {Object} d Data object
292
+ * @returns {string} Translate attribute string
293
+ * @private
294
+ */
279
295
  transformForArcLabel(d): string {
280
296
  const $$ = this;
281
297
  const {config, state: {radiusExpanded}} = $$;
@@ -292,13 +308,19 @@ export default {
292
308
 
293
309
  translate = `translate(${x},${y})`;
294
310
  } else if (!$$.hasType("gauge") || $$.data.targets.length > 1) {
295
- const {outerRadius} = $$.getRadius(d);
311
+ let {outerRadius} = $$.getRadius(d);
312
+
313
+ if ($$.hasType("polar")) {
314
+ outerRadius = $$.getPolarOuterRadius(d, outerRadius);
315
+ }
316
+
296
317
  const c = this.svgArc.centroid(updated);
297
318
  const [x, y] = c.map(v => (isNaN(v) ? 0 : v));
298
319
  const h = Math.sqrt(x * x + y * y);
299
320
 
300
- let ratio = ($$.hasType("donut") && config.donut_label_ratio) ||
301
- ($$.hasType("pie") && config.pie_label_ratio);
321
+ let ratio = ["donut", "pie", "polar"]
322
+ .filter($$.hasType.bind($$))
323
+ .map(v => config[`${v}_label_ratio`])?.[0];
302
324
 
303
325
  if (ratio) {
304
326
  ratio = isFunction(ratio) ? ratio.bind($$.api)(d, outerRadius, h) : ratio;
@@ -337,7 +359,7 @@ export default {
337
359
  const updated = $$.updateAngle(d);
338
360
  const ratio = $$.getRatio("arc", updated);
339
361
  const isUnderThreshold = $$.meetsLabelThreshold(ratio,
340
- ($$.hasType("donut") && "donut") || ($$.hasType("gauge") && "gauge") || ($$.hasType("pie") && "pie")
362
+ ["donut", "gauge", "pie", "polar"].filter($$.hasType.bind($$))?.[0]
341
363
  );
342
364
 
343
365
  if (isUnderThreshold) {
@@ -453,20 +475,20 @@ export default {
453
475
  const $$ = this;
454
476
  const {config} = $$;
455
477
 
456
- return ["pie", "donut", "gauge"]
478
+ return ["donut", "gauge", "pie", "polar"]
457
479
  .some(v => $$.hasType(v) && config[`${v}_label_show`]);
458
480
  },
459
481
 
460
482
  getArcLabelFormat(): number | string {
461
483
  const $$ = this;
462
484
  const {config} = $$;
463
- let format = config.pie_label_format;
485
+ let format = v => v;
464
486
 
465
- if ($$.hasType("gauge")) {
466
- format = config.gauge_label_format;
467
- } else if ($$.hasType("donut")) {
468
- format = config.donut_label_format;
469
- }
487
+ ["donut", "gauge", "pie", "polar"]
488
+ .filter($$.hasType.bind($$))
489
+ .forEach(v => {
490
+ format = config[`${v}_label_format`];
491
+ });
470
492
 
471
493
  return isFunction(format) ? format.bind($$.api) : format;
472
494
  },
@@ -611,6 +633,7 @@ export default {
611
633
  const interpolated = interpolate(t);
612
634
 
613
635
  interpolated.data = d.data; // data.id will be updated by interporator
636
+
614
637
  return $$.getArc(interpolated, true);
615
638
  };
616
639
  })
@@ -646,6 +669,7 @@ export default {
646
669
  // bind arc events
647
670
  hasInteraction && $$.bindArcEvent(mainArc);
648
671
 
672
+ $$.hasType("polar") && $$.redrawPolar();
649
673
  $$.hasType("gauge") && $$.redrawBackgroundArcs();
650
674
 
651
675
  $$.redrawArcText(duration);