@carbon/charts 0.30.7 → 0.30.8

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 (138) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/build/demo/data/bar.d.ts +56 -94
  3. package/build/demo/data/bubble.d.ts +58 -13
  4. package/build/demo/data/donut.d.ts +3 -6
  5. package/build/demo/data/line.d.ts +35 -35
  6. package/build/demo/data/pie.d.ts +3 -6
  7. package/build/demo/data/scatter.d.ts +33 -20
  8. package/build/demo/data/step.d.ts +15 -16
  9. package/build/demo/data/time-series-axis.d.ts +12 -48
  10. package/build/src/charts/bar-grouped.d.ts +2 -2
  11. package/build/src/charts/bar-simple.d.ts +2 -4
  12. package/build/src/components/essentials/legend.d.ts +0 -4
  13. package/build/src/components/essentials/tooltip-bar.d.ts +1 -1
  14. package/build/src/components/essentials/tooltip-pie.d.ts +5 -0
  15. package/build/src/components/essentials/tooltip-scatter.d.ts +1 -1
  16. package/build/src/components/graphs/bar-grouped.d.ts +6 -4
  17. package/build/src/components/graphs/bar-simple.d.ts +0 -1
  18. package/build/src/components/graphs/bar-stacked.d.ts +0 -1
  19. package/build/src/components/graphs/bubble.d.ts +0 -1
  20. package/build/src/components/graphs/line.d.ts +3 -1
  21. package/build/src/components/graphs/pie.d.ts +0 -1
  22. package/build/src/components/graphs/scatter.d.ts +0 -1
  23. package/build/src/components/index.d.ts +1 -0
  24. package/build/src/interfaces/axis-scales.d.ts +4 -16
  25. package/build/src/interfaces/charts.d.ts +23 -1
  26. package/build/src/interfaces/enums.d.ts +0 -4
  27. package/build/src/model-pie.d.ts +1 -7
  28. package/build/src/model.d.ts +31 -13
  29. package/build/src/services/scales-cartesian.d.ts +11 -3
  30. package/build/src/tools.d.ts +2 -2
  31. package/build/stories/tutorials.stories.d.ts +1 -0
  32. package/bundle.js +1 -1
  33. package/charts/bar-grouped.d.ts +2 -2
  34. package/charts/bar-grouped.js.map +1 -1
  35. package/charts/bar-simple.d.ts +2 -4
  36. package/charts/bar-simple.js +0 -2
  37. package/charts/bar-simple.js.map +1 -1
  38. package/charts/donut.js +2 -2
  39. package/charts/donut.js.map +1 -1
  40. package/charts/pie.js +2 -2
  41. package/charts/pie.js.map +1 -1
  42. package/components/axes/grid.js +10 -17
  43. package/components/axes/grid.js.map +1 -1
  44. package/components/essentials/legend.d.ts +0 -4
  45. package/components/essentials/legend.js +8 -22
  46. package/components/essentials/legend.js.map +1 -1
  47. package/components/essentials/tooltip-bar.d.ts +1 -1
  48. package/components/essentials/tooltip-bar.js +12 -4
  49. package/components/essentials/tooltip-bar.js.map +1 -1
  50. package/components/essentials/tooltip-pie.d.ts +5 -0
  51. package/components/essentials/tooltip-pie.js +40 -0
  52. package/components/essentials/tooltip-pie.js.map +1 -0
  53. package/components/essentials/tooltip-scatter.d.ts +1 -1
  54. package/components/essentials/tooltip-scatter.js +8 -6
  55. package/components/essentials/tooltip-scatter.js.map +1 -1
  56. package/components/essentials/tooltip.js +13 -16
  57. package/components/essentials/tooltip.js.map +1 -1
  58. package/components/graphs/bar-grouped.d.ts +6 -4
  59. package/components/graphs/bar-grouped.js +58 -30
  60. package/components/graphs/bar-grouped.js.map +1 -1
  61. package/components/graphs/bar-simple.d.ts +0 -1
  62. package/components/graphs/bar-simple.js +10 -28
  63. package/components/graphs/bar-simple.js.map +1 -1
  64. package/components/graphs/bar-stacked.d.ts +0 -1
  65. package/components/graphs/bar-stacked.js +27 -108
  66. package/components/graphs/bar-stacked.js.map +1 -1
  67. package/components/graphs/bubble.d.ts +0 -1
  68. package/components/graphs/bubble.js +16 -20
  69. package/components/graphs/bubble.js.map +1 -1
  70. package/components/graphs/donut.js +1 -1
  71. package/components/graphs/donut.js.map +1 -1
  72. package/components/graphs/line.d.ts +3 -1
  73. package/components/graphs/line.js +41 -30
  74. package/components/graphs/line.js.map +1 -1
  75. package/components/graphs/pie.d.ts +0 -1
  76. package/components/graphs/pie.js +11 -18
  77. package/components/graphs/pie.js.map +1 -1
  78. package/components/graphs/scatter.d.ts +0 -1
  79. package/components/graphs/scatter.js +24 -39
  80. package/components/graphs/scatter.js.map +1 -1
  81. package/components/index.d.ts +1 -0
  82. package/components/index.js +1 -0
  83. package/components/index.js.map +1 -1
  84. package/configuration.js +7 -0
  85. package/configuration.js.map +1 -1
  86. package/demo/data/bar.d.ts +56 -94
  87. package/demo/data/bar.js +106 -271
  88. package/demo/data/bar.js.map +1 -1
  89. package/demo/data/bubble.d.ts +58 -13
  90. package/demo/data/bubble.js +74 -174
  91. package/demo/data/bubble.js.map +1 -1
  92. package/demo/data/bundle.js +1 -1
  93. package/demo/data/donut.d.ts +3 -6
  94. package/demo/data/index.js +22 -4
  95. package/demo/data/index.js.map +1 -1
  96. package/demo/data/line.d.ts +35 -35
  97. package/demo/data/line.js +70 -196
  98. package/demo/data/line.js.map +1 -1
  99. package/demo/data/pie.d.ts +3 -6
  100. package/demo/data/pie.js +8 -10
  101. package/demo/data/pie.js.map +1 -1
  102. package/demo/data/scatter.d.ts +33 -20
  103. package/demo/data/scatter.js +50 -68
  104. package/demo/data/scatter.js.map +1 -1
  105. package/demo/data/step.d.ts +15 -16
  106. package/demo/data/time-series-axis.d.ts +12 -48
  107. package/demo/data/time-series-axis.js +34 -46
  108. package/demo/data/time-series-axis.js.map +1 -1
  109. package/demo/styles.css +28 -0
  110. package/demo/styles.css.map +1 -1
  111. package/demo/styles.min.css +1 -1
  112. package/demo/styles.min.css.map +1 -1
  113. package/demo/tsconfig.tsbuildinfo +36 -35
  114. package/interfaces/axis-scales.d.ts +4 -16
  115. package/interfaces/axis-scales.js.map +1 -1
  116. package/interfaces/charts.d.ts +23 -1
  117. package/interfaces/charts.js.map +1 -1
  118. package/interfaces/enums.d.ts +0 -4
  119. package/interfaces/enums.js +0 -5
  120. package/interfaces/enums.js.map +1 -1
  121. package/model-pie.d.ts +1 -7
  122. package/model-pie.js +2 -107
  123. package/model-pie.js.map +1 -1
  124. package/model.d.ts +31 -13
  125. package/model.js +199 -75
  126. package/model.js.map +1 -1
  127. package/package.json +3 -1
  128. package/services/scales-cartesian.d.ts +11 -3
  129. package/services/scales-cartesian.js +104 -122
  130. package/services/scales-cartesian.js.map +1 -1
  131. package/tools.d.ts +2 -2
  132. package/tools.js +23 -2
  133. package/tools.js.map +1 -1
  134. package/tsconfig.tsbuildinfo +72 -73
  135. package/build/src/model-simple-bar.d.ts +0 -11
  136. package/model-simple-bar.d.ts +0 -11
  137. package/model-simple-bar.js +0 -88
  138. package/model-simple-bar.js.map +0 -1
package/model.d.ts CHANGED
@@ -9,22 +9,41 @@ export declare class ChartModel {
9
9
  protected services: any;
10
10
  protected state: any;
11
11
  /**
12
- * A list of all the labels that have existed within the lifetime of the chart
12
+ * A list of all the data groups that have existed within the lifetime of the chart
13
13
  * @type string[]
14
14
  */
15
- protected allDataLabels: string[];
16
- protected patternScale: {};
15
+ protected allDataGroups: string[];
17
16
  protected colorScale: any;
18
17
  constructor(services: any);
19
- sanitize(data: any): any;
18
+ /**
19
+ * Converts data provided in the older format to tabular
20
+ *
21
+ */
22
+ protected transformToTabularData(data: any): any[];
23
+ protected getTabularData(data: any): any[];
24
+ protected sanitize(data: any): any[];
20
25
  getDisplayData(): any;
21
26
  getData(): any;
22
27
  /**
23
28
  *
24
29
  * @param newData The new raw data to be set
25
30
  */
26
- setData(newData: any): any;
27
- generateDataLabels(newData: any): {};
31
+ setData(newData: any): any[];
32
+ protected updateAllDataGroups(): void;
33
+ protected generateDataGroups(data: any): {
34
+ name: string;
35
+ status: Number;
36
+ }[];
37
+ getDataGroups(): any;
38
+ getActiveDataGroups(): any;
39
+ getDataGroupNames(): any;
40
+ getActiveDataGroupNames(): any;
41
+ getGroupedData(): {
42
+ name: string;
43
+ data: any;
44
+ }[];
45
+ getDataValuesGroupedByKeys(): any;
46
+ getStackedData(): any[][];
28
47
  /**
29
48
  * @return {Object} The chart's options
30
49
  */
@@ -44,17 +63,16 @@ export declare class ChartModel {
44
63
  update(): void;
45
64
  setUpdateCallback(cb: Function): void;
46
65
  toggleDataLabel(changedLabel: string): void;
47
- setColorScale(): void;
66
+ protected setColorScale(): void;
48
67
  /**
49
68
  * Should the data point be filled?
50
- * @param datasetLabel
51
- * @param label
69
+ * @param group
70
+ * @param key
52
71
  * @param value
53
72
  * @param defaultFilled the default for this chart
54
73
  */
55
- getIsFilled(datasetLabel: any, label?: any, data?: any, defaultFilled?: boolean): any;
56
- getFillColor(datasetLabel: any, label?: any, data?: any): any;
57
- getStrokeColor(datasetLabel: any, label?: any, data?: any): any;
74
+ getIsFilled(group: any, key?: any, data?: any, defaultFilled?: boolean): any;
75
+ getFillColor(group: any, key?: any, data?: any): any;
76
+ getStrokeColor(group: any, key?: any, data?: any): any;
58
77
  getFillScale(): any;
59
- protected updateAllDataLabels(): void;
60
78
  }
package/model.js CHANGED
@@ -5,6 +5,8 @@ import * as colorPalettes from "./services/colorPalettes";
5
5
  import { Events } from "./interfaces";
6
6
  // D3
7
7
  import { scaleOrdinal } from "d3-scale";
8
+ import { map } from "d3-collection";
9
+ import { stack } from "d3-shape";
8
10
  /** The charting model layer which includes mainly the chart data and options,
9
11
  * as well as some misc. information to be shared among components */
10
12
  var ChartModel = /** @class */ (function () {
@@ -14,34 +16,61 @@ var ChartModel = /** @class */ (function () {
14
16
  options: {}
15
17
  };
16
18
  // Fill scales & fill related objects
17
- this.patternScale = {};
18
19
  this.colorScale = {};
19
20
  this.services = services;
20
21
  }
21
- ChartModel.prototype.sanitize = function (data) {
22
- // Sanitize all dates
23
- data.datasets.forEach(function (dataset) {
24
- dataset.data = dataset.data.map(function (d) {
25
- if (d.date && !d.date.getTime) {
26
- d.date = new Date(d.date);
22
+ /**
23
+ * Converts data provided in the older format to tabular
24
+ *
25
+ */
26
+ ChartModel.prototype.transformToTabularData = function (data) {
27
+ console.warn("We've updated the charting data format to be tabular by default. The current format you're using is deprecated and will be removed in v1.0, read more here https://carbon-design-system.github.io/carbon-charts/?path=/story/tutorials--tabular-data-format");
28
+ var tabularData = [];
29
+ var datasets = data.datasets, labels = data.labels;
30
+ // Loop through all datasets
31
+ datasets.forEach(function (dataset) {
32
+ var group = dataset.label;
33
+ // Update each data point to the new format
34
+ dataset.data.forEach(function (datum, i) {
35
+ var updatedDatum = {
36
+ group: group,
37
+ key: labels[i]
38
+ };
39
+ if (isNaN(datum)) {
40
+ updatedDatum["value"] = datum.value;
41
+ updatedDatum["date"] = datum.date;
27
42
  }
28
- return d;
43
+ else {
44
+ updatedDatum["value"] = datum;
45
+ }
46
+ tabularData.push(updatedDatum);
29
47
  });
30
48
  });
49
+ return tabularData;
50
+ };
51
+ ChartModel.prototype.getTabularData = function (data) {
52
+ // if data is not an array
53
+ if (!Array.isArray(data)) {
54
+ return this.transformToTabularData(data);
55
+ }
31
56
  return data;
32
57
  };
58
+ ChartModel.prototype.sanitize = function (data) {
59
+ return this.getTabularData(data);
60
+ };
33
61
  ChartModel.prototype.getDisplayData = function () {
34
- var ACTIVE = Configuration.legend.items.status.ACTIVE;
35
- var dataLabels = this.get("dataLabels");
36
62
  if (!this.get("data")) {
37
63
  return null;
38
64
  }
65
+ var ACTIVE = Configuration.legend.items.status.ACTIVE;
66
+ var dataGroups = this.getDataGroups();
39
67
  // Remove datasets that have been disabled
40
68
  var displayData = Tools.clone(this.get("data"));
41
- displayData.datasets = displayData.datasets.filter(function (dataset) {
42
- return dataLabels[dataset.label] === ACTIVE;
69
+ var groupMapsTo = this.getOptions().data.groupMapsTo;
70
+ return displayData.filter(function (datum) {
71
+ var group = dataGroups.find(function (group) { return group.name === datum[groupMapsTo]; });
72
+ return group.status === ACTIVE;
43
73
  });
44
- return displayData;
45
74
  };
46
75
  ChartModel.prototype.getData = function () {
47
76
  return this.get("data");
@@ -52,19 +81,115 @@ var ChartModel = /** @class */ (function () {
52
81
  */
53
82
  ChartModel.prototype.setData = function (newData) {
54
83
  var sanitizedData = this.sanitize(Tools.clone(newData));
55
- var dataLabels = this.generateDataLabels(sanitizedData);
84
+ var dataGroups = this.generateDataGroups(sanitizedData);
56
85
  this.set({
57
86
  data: sanitizedData,
58
- dataLabels: dataLabels
87
+ dataGroups: dataGroups
59
88
  });
60
89
  return sanitizedData;
61
90
  };
62
- ChartModel.prototype.generateDataLabels = function (newData) {
63
- var dataLabels = {};
64
- newData.datasets.forEach(function (dataset) {
65
- dataLabels[dataset.label] = Configuration.legend.items.status.ACTIVE;
91
+ /*
92
+ * Data groups
93
+ */
94
+ ChartModel.prototype.updateAllDataGroups = function () {
95
+ // allDataGroups is used to generate a color scale that applies
96
+ // to all the groups. Now when the data updates, you might remove a group,
97
+ // and then bring it back in a newer data update, therefore
98
+ // the order of the groups in allDataGroups matters so that you'd never
99
+ // have an incorrect color assigned to a group.
100
+ var _this = this;
101
+ // Also, a new group should only be added to allDataGroups if
102
+ // it doesn't currently exist
103
+ if (!this.allDataGroups) {
104
+ this.allDataGroups = this.getDataGroupNames();
105
+ }
106
+ else {
107
+ // Loop through current data groups
108
+ this.getDataGroupNames().forEach(function (dataGroupName) {
109
+ // If group name hasn't been stored yet, store it
110
+ if (_this.allDataGroups.indexOf(dataGroupName) === -1) {
111
+ _this.allDataGroups.push(dataGroupName);
112
+ }
113
+ });
114
+ }
115
+ };
116
+ ChartModel.prototype.generateDataGroups = function (data) {
117
+ var groupMapsTo = this.getOptions().data.groupMapsTo;
118
+ var ACTIVE = Configuration.legend.items.status.ACTIVE;
119
+ var uniqueDataGroups = map(data, function (datum) { return datum[groupMapsTo]; }).keys();
120
+ return uniqueDataGroups.map(function (groupName) { return ({
121
+ name: groupName,
122
+ status: ACTIVE
123
+ }); });
124
+ };
125
+ ChartModel.prototype.getDataGroups = function () {
126
+ return this.get("dataGroups");
127
+ };
128
+ ChartModel.prototype.getActiveDataGroups = function () {
129
+ var ACTIVE = Configuration.legend.items.status.ACTIVE;
130
+ return this.getDataGroups().filter(function (dataGroup) { return dataGroup.status === ACTIVE; });
131
+ };
132
+ ChartModel.prototype.getDataGroupNames = function () {
133
+ return this.getDataGroups().map(function (dataGroup) { return dataGroup.name; });
134
+ };
135
+ ChartModel.prototype.getActiveDataGroupNames = function () {
136
+ return this.getActiveDataGroups().map(function (dataGroup) { return dataGroup.name; });
137
+ };
138
+ ChartModel.prototype.getGroupedData = function () {
139
+ var displayData = this.getDisplayData();
140
+ var groupedData = {};
141
+ var groupMapsTo = this.getOptions().data.groupMapsTo;
142
+ displayData.map(function (datum) {
143
+ var group = datum[groupMapsTo];
144
+ if (groupedData[group] !== null && groupedData[group] !== undefined) {
145
+ groupedData[group].push(datum);
146
+ }
147
+ else {
148
+ groupedData[group] = [datum];
149
+ }
150
+ });
151
+ return Object.keys(groupedData)
152
+ .map(function (groupName) { return ({
153
+ name: groupName,
154
+ data: groupedData[groupName]
155
+ }); });
156
+ };
157
+ ChartModel.prototype.getDataValuesGroupedByKeys = function () {
158
+ var options = this.getOptions();
159
+ var groupMapsTo = options.data.groupMapsTo;
160
+ var displayData = this.getDisplayData();
161
+ var domainIdentifier = this.services.cartesianScales.getDomainIdentifier();
162
+ var rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();
163
+ var stackKeys = map(displayData, function (datum) { return datum[domainIdentifier]; }).keys();
164
+ var dataGroupNames = this.getDataGroupNames();
165
+ return stackKeys.map(function (key) {
166
+ var correspondingValues = { sharedStackKey: key };
167
+ dataGroupNames.forEach(function (dataGroupName) {
168
+ var correspondingDatum = displayData.find(function (datum) {
169
+ return datum[groupMapsTo] === dataGroupName &&
170
+ datum[domainIdentifier].toString() === key;
171
+ });
172
+ correspondingValues[dataGroupName] = correspondingDatum ? correspondingDatum[rangeIdentifier] : null;
173
+ });
174
+ return correspondingValues;
175
+ });
176
+ };
177
+ ChartModel.prototype.getStackedData = function () {
178
+ var options = this.getOptions();
179
+ var groupMapsTo = options.data.groupMapsTo;
180
+ var dataGroupNames = this.getDataGroupNames();
181
+ var dataValuesGroupedByKeys = this.getDataValuesGroupedByKeys();
182
+ return stack().keys(dataGroupNames)(dataValuesGroupedByKeys)
183
+ .map(function (series, i) {
184
+ // Add data group names to each series
185
+ return Object.keys(series)
186
+ .filter(function (key) { return !isNaN(key); })
187
+ .map(function (key) {
188
+ var element = series[key];
189
+ element[groupMapsTo] = dataGroupNames[i];
190
+ return element;
191
+ });
66
192
  });
67
- return dataLabels;
68
193
  };
69
194
  /**
70
195
  * @return {Object} The chart's options
@@ -105,7 +230,7 @@ var ChartModel = /** @class */ (function () {
105
230
  if (!this.getDisplayData()) {
106
231
  return;
107
232
  }
108
- this.updateAllDataLabels();
233
+ this.updateAllDataGroups();
109
234
  this.setColorScale();
110
235
  this.services.events.dispatchEvent(Events.Model.UPDATE);
111
236
  };
@@ -117,116 +242,115 @@ var ChartModel = /** @class */ (function () {
117
242
  */
118
243
  ChartModel.prototype.toggleDataLabel = function (changedLabel) {
119
244
  var _a = Configuration.legend.items.status, ACTIVE = _a.ACTIVE, DISABLED = _a.DISABLED;
120
- var dataLabels = this.get("dataLabels");
121
- var hasDeactivatedItems = Object.keys(dataLabels).some(function (label) { return dataLabels[label] === DISABLED; });
122
- var activeItems = Object.keys(dataLabels).filter(function (label) { return dataLabels[label] === ACTIVE; });
245
+ var dataGroups = this.getDataGroups();
246
+ var hasDeactivatedItems = dataGroups.some(function (group) { return group.status === DISABLED; });
247
+ var activeItems = dataGroups.filter(function (group) { return group.status === ACTIVE; });
123
248
  // If there are deactivated items, toggle "changedLabel"
124
249
  if (hasDeactivatedItems) {
125
250
  // If the only active item is being toggled
126
251
  // Activate all items
127
- if (activeItems.length === 1 && activeItems[0] === changedLabel) {
252
+ if (activeItems.length === 1 && activeItems[0].name === changedLabel) {
128
253
  // If every item is active, then enable "changedLabel" and disable all other items
129
- Object.keys(dataLabels).forEach(function (label) {
130
- dataLabels[label] = ACTIVE;
254
+ dataGroups.forEach(function (group, i) {
255
+ dataGroups[i].status = ACTIVE;
131
256
  });
132
257
  }
133
258
  else {
134
- dataLabels[changedLabel] = dataLabels[changedLabel] === DISABLED ? ACTIVE : DISABLED;
259
+ var indexToChange = dataGroups.findIndex(function (group) { return group.name === changedLabel; });
260
+ dataGroups[indexToChange].status = dataGroups[indexToChange].status === DISABLED ? ACTIVE : DISABLED;
135
261
  }
136
262
  }
137
263
  else {
138
264
  // If every item is active, then enable "changedLabel" and disable all other items
139
- Object.keys(dataLabels).forEach(function (label) {
140
- dataLabels[label] = (label === changedLabel ? ACTIVE : DISABLED);
265
+ dataGroups.forEach(function (group, i) {
266
+ dataGroups[i].status = (group.name === changedLabel ? ACTIVE : DISABLED);
141
267
  });
142
268
  }
143
269
  // dispatch legend filtering event with the status of all the dataLabels
144
270
  this.services.events.dispatchEvent(Events.Legend.ITEMS_UPDATE, {
145
- dataLabels: dataLabels
271
+ dataGroups: dataGroups
146
272
  });
147
273
  // Update model
148
274
  this.set({
149
- dataLabels: dataLabels
275
+ dataGroups: dataGroups
150
276
  });
151
277
  };
152
278
  /*
153
279
  * Fill scales
154
280
  */
155
281
  ChartModel.prototype.setColorScale = function () {
156
- var _this = this;
157
- if (this.getDisplayData().datasets[0].fillColors) {
158
- this.getDisplayData().datasets.forEach(function (dataset) {
159
- _this.colorScale[dataset.label] = scaleOrdinal().range(dataset.fillColors).domain(_this.allDataLabels);
160
- });
161
- }
162
- else {
163
- var colors_1 = colorPalettes.DEFAULT;
164
- this.getData().datasets.forEach(function (dataset, i) {
165
- _this.colorScale[dataset.label] = scaleOrdinal().range([colors_1[i]]).domain(_this.allDataLabels);
166
- });
282
+ var defaultColors = colorPalettes.DEFAULT;
283
+ var options = this.getOptions();
284
+ var userProvidedScale = Tools.getProperty(options, "color", "scale");
285
+ // If there is no valid user provided scale, use the default set of colors
286
+ if (userProvidedScale === null || Object.keys(userProvidedScale).length === 0) {
287
+ this.colorScale = scaleOrdinal().range(defaultColors)
288
+ .domain(this.allDataGroups);
289
+ return;
167
290
  }
291
+ /**
292
+ * Go through allDataGroups. If a data group has a color value provided
293
+ * by the user, add that to the color range
294
+ * If not, add a default color
295
+ */
296
+ var colorRange = [];
297
+ var colorIndex = 0;
298
+ this.allDataGroups.forEach(function (dataGroup) {
299
+ if (userProvidedScale[dataGroup]) {
300
+ colorRange.push(userProvidedScale[dataGroup]);
301
+ }
302
+ else {
303
+ colorRange.push(defaultColors[colorIndex]);
304
+ }
305
+ if (colorIndex === defaultColors.length - 1) {
306
+ colorIndex = 0;
307
+ }
308
+ else {
309
+ colorIndex++;
310
+ }
311
+ });
312
+ this.colorScale = scaleOrdinal().range(colorRange)
313
+ .domain(this.allDataGroups);
168
314
  };
169
315
  /**
170
316
  * Should the data point be filled?
171
- * @param datasetLabel
172
- * @param label
317
+ * @param group
318
+ * @param key
173
319
  * @param value
174
320
  * @param defaultFilled the default for this chart
175
321
  */
176
- ChartModel.prototype.getIsFilled = function (datasetLabel, label, data, defaultFilled) {
322
+ ChartModel.prototype.getIsFilled = function (group, key, data, defaultFilled) {
177
323
  var options = this.getOptions();
178
324
  if (options.getIsFilled) {
179
- return options.getIsFilled(datasetLabel, label, data, defaultFilled);
325
+ return options.getIsFilled(group, key, data, defaultFilled);
180
326
  }
181
327
  else {
182
328
  return defaultFilled;
183
329
  }
184
330
  };
185
- ChartModel.prototype.getFillColor = function (datasetLabel, label, data) {
331
+ ChartModel.prototype.getFillColor = function (group, key, data) {
186
332
  var options = this.getOptions();
187
- var defaultFillColor = this.getFillScale()[datasetLabel](label);
333
+ var defaultFillColor = this.getFillScale()(group);
188
334
  if (options.getFillColor) {
189
- return options.getFillColor(datasetLabel, label, data, defaultFillColor);
335
+ return options.getFillColor(group, key, data, defaultFillColor);
190
336
  }
191
337
  else {
192
338
  return defaultFillColor;
193
339
  }
194
340
  };
195
- ChartModel.prototype.getStrokeColor = function (datasetLabel, label, data) {
341
+ ChartModel.prototype.getStrokeColor = function (group, key, data) {
196
342
  var options = this.getOptions();
197
- var defaultStrokeColor = this.colorScale[datasetLabel](label);
343
+ var defaultStrokeColor = this.colorScale(group);
198
344
  if (options.getStrokeColor) {
199
- return options.getStrokeColor(datasetLabel, label, data, defaultStrokeColor);
345
+ return options.getStrokeColor(group, key, data, defaultStrokeColor);
200
346
  }
201
347
  else {
202
348
  return defaultStrokeColor;
203
349
  }
204
350
  };
205
351
  ChartModel.prototype.getFillScale = function () {
206
- // Choose patternScale or colorScale based on the "accessibility" flag
207
- // return this.get("options").accessibility ? this.patternScale : this.colorScale;
208
352
  return this.colorScale;
209
353
  };
210
- /*
211
- * Data labels
212
- */
213
- ChartModel.prototype.updateAllDataLabels = function () {
214
- var _this = this;
215
- // If allDataLabels hasn't been initialized yet
216
- // Set it to the current set of chart labels
217
- if (!this.allDataLabels) {
218
- this.allDataLabels = this.getDisplayData().labels;
219
- }
220
- else {
221
- // Loop through current chart labels
222
- this.getDisplayData().labels.forEach(function (label) {
223
- // If label hasn't been stored yet, store it
224
- if (_this.allDataLabels.indexOf(label) === -1) {
225
- _this.allDataLabels.push(label);
226
- }
227
- });
228
- }
229
- };
230
354
  return ChartModel;
231
355
  }());
232
356
  export { ChartModel };
package/model.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","sourceRoot":"","sources":["model.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,KAAK,aAAa,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,KAAK;AACL,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC;qEACqE;AACrE;IA0BC,oBAAY,QAAa;QAjBzB,uBAAuB;QACb,UAAK,GAAQ;YACtB,OAAO,EAAE,EAAE;SACX,CAAC;QASF,qCAAqC;QAC3B,iBAAY,GAAG,EAAE,CAAC;QAClB,eAAU,GAAQ,EAAE,CAAC;QAI9B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED,6BAAQ,GAAR,UAAS,IAAI;QACZ,qBAAqB;QACrB,IAAI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QAbA,+CAA+C;QAC/C,4CAA4C;QAC5C,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACxB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC;SAClD;aAAM;YACN,oCAAoC;YACpC,IAAI,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK;gBACzC,4CAA4C;gBAC5C,IAAI,KAAI,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE;oBAC7C,KAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBAC/B;YACF,CAAC,CAAC,CAAC;SACH;IACF,CAAC;IACF,iBAAC;AAAD,CAAC,AApQD,IAoQC","sourcesContent":["// Internal Imports\nimport * as Configuration from \"./configuration\";\nimport { Tools } from \"./tools\";\nimport * as colorPalettes from \"./services/colorPalettes\";\nimport { Events } from \"./interfaces\";\n\n// D3\nimport { scaleOrdinal } from \"d3-scale\";\n\n/** The charting model layer which includes mainly the chart data and options,\n * as well as some misc. information to be shared among components */\nexport class ChartModel {\n\t// Callbacks\n\t/**\n\t * Function to be called when data or options update within the model\n\t * @type Function\n\t */\n\tprotected updateCallback: Function;\n\tprotected services: any;\n\n\t// Internal Model state\n\tprotected state: any = {\n\t\toptions: {}\n\t};\n\n\t// Data labels\n\t/**\n\t * A list of all the labels that have existed within the lifetime of the chart\n\t * @type string[]\n\t */\n\tprotected allDataLabels: string[];\n\n\t// Fill scales & fill related objects\n\tprotected patternScale = {};\n\tprotected colorScale: any = {};\n\n\n\tconstructor(services: any) {\n\t\tthis.services = services;\n\t}\n\n\tsanitize(data) {\n\t\t// Sanitize all dates\n\t\tdata.datasets.forEach(dataset => {\n\t\t\tdataset.data = dataset.data.map(d => {\n\t\t\t\tif (d.date && !d.date.getTime) {\n\t\t\t\t\td.date = new Date(d.date);\n\t\t\t\t}\n\n\t\t\t\treturn d;\n\t\t\t});\n\t\t});\n\n\t\treturn data;\n\t}\n\n\tgetDisplayData() {\n\t\tconst { ACTIVE } = Configuration.legend.items.status;\n\t\tconst dataLabels = this.get(\"dataLabels\");\n\n\t\tif (!this.get(\"data\")) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// Remove datasets that have been disabled\n\t\tconst displayData = Tools.clone(this.get(\"data\"));\n\t\tdisplayData.datasets = displayData.datasets.filter(dataset => {\n\t\t\treturn dataLabels[dataset.label] === ACTIVE;\n\t\t});\n\n\t\treturn displayData;\n\t}\n\n\tgetData() {\n\t\treturn this.get(\"data\");\n\t}\n\n\t/**\n\t *\n\t * @param newData The new raw data to be set\n\t */\n\tsetData(newData) {\n\t\tconst sanitizedData = this.sanitize(Tools.clone(newData));\n\t\tconst dataLabels = this.generateDataLabels(sanitizedData);\n\n\t\tthis.set({\n\t\t\tdata: sanitizedData,\n\t\t\tdataLabels\n\t\t});\n\n\t\treturn sanitizedData;\n\t}\n\n\tgenerateDataLabels(newData) {\n\t\tconst dataLabels = {};\n\t\tnewData.datasets.forEach(dataset => {\n\t\t\tdataLabels[dataset.label] = Configuration.legend.items.status.ACTIVE;\n\t\t});\n\n\t\treturn dataLabels;\n\t}\n\n\t/**\n\t * @return {Object} The chart's options\n\t */\n\tgetOptions() {\n\t\treturn this.state.options;\n\t}\n\n\tset(newState: any, skipUpdate = false) {\n\t\tthis.state = Object.assign({}, this.state, newState);\n\n\t\tif (!skipUpdate) {\n\t\t\tthis.update();\n\t\t}\n\t}\n\n\tget(property?: string) {\n\t\tif (property) {\n\t\t\treturn this.state[property];\n\t\t} else {\n\t\t\treturn this.state;\n\t\t}\n\t}\n\n\t/**\n\t *\n\t * @param newOptions New options to be set\n\t */\n\tsetOptions(newOptions) {\n\t\tthis.set({\n\t\t\toptions: Tools.merge(this.getOptions(), newOptions)\n\t\t});\n\t}\n\n\t/**\n\t *\n\t * Updates miscellanous information within the model\n\t * such as the color scales, or the legend data labels\n\t */\n\tupdate() {\n\t\tif (!this.getDisplayData()) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.updateAllDataLabels();\n\t\tthis.setColorScale();\n\n\t\tthis.services.events.dispatchEvent(Events.Model.UPDATE);\n\t}\n\n\tsetUpdateCallback(cb: Function) {\n\t\tthis.updateCallback = cb;\n\t}\n\n\t/*\n\t * Data labels\n\t*/\n\ttoggleDataLabel(changedLabel: string) {\n\t\tconst { ACTIVE, DISABLED } = Configuration.legend.items.status;\n\t\tconst dataLabels = this.get(\"dataLabels\");\n\n\t\tconst hasDeactivatedItems = Object.keys(dataLabels).some(label => dataLabels[label] === DISABLED);\n\t\tconst activeItems = Object.keys(dataLabels).filter(label => dataLabels[label] === ACTIVE);\n\t\t// If there are deactivated items, toggle \"changedLabel\"\n\t\tif (hasDeactivatedItems) {\n\t\t\t// If the only active item is being toggled\n\t\t\t// Activate all items\n\t\t\tif (activeItems.length === 1 && activeItems[0] === changedLabel) {\n\t\t\t\t// If every item is active, then enable \"changedLabel\" and disable all other items\n\t\t\t\tObject.keys(dataLabels).forEach(label => {\n\t\t\t\t\tdataLabels[label] = ACTIVE;\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tdataLabels[changedLabel] = dataLabels[changedLabel] === DISABLED ? ACTIVE : DISABLED;\n\t\t\t}\n\t\t} else {\n\t\t\t// If every item is active, then enable \"changedLabel\" and disable all other items\n\t\t\tObject.keys(dataLabels).forEach(label => {\n\t\t\t\tdataLabels[label] = (label === changedLabel ? ACTIVE : DISABLED);\n\t\t\t});\n\t\t}\n\n\t\t// dispatch legend filtering event with the status of all the dataLabels\n\t\tthis.services.events.dispatchEvent(Events.Legend.ITEMS_UPDATE, {\n\t\t\tdataLabels\n\t\t});\n\n\t\t// Update model\n\t\tthis.set({\n\t\t\tdataLabels\n\t\t});\n\t}\n\n\t/*\n\t * Fill scales\n\t*/\n\tsetColorScale() {\n\t\tif (this.getDisplayData().datasets[0].fillColors) {\n\t\t\tthis.getDisplayData().datasets.forEach(dataset => {\n\t\t\t\tthis.colorScale[dataset.label] = scaleOrdinal().range(dataset.fillColors).domain(this.allDataLabels);\n\t\t\t});\n\t\t} else {\n\t\t\tconst colors = colorPalettes.DEFAULT;\n\t\t\tthis.getData().datasets.forEach((dataset, i) => {\n\t\t\t\tthis.colorScale[dataset.label] = scaleOrdinal().range([colors[i]]).domain(this.allDataLabels);\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Should the data point be filled?\n\t * @param datasetLabel\n\t * @param label\n\t * @param value\n\t * @param defaultFilled the default for this chart\n\t */\n\tgetIsFilled(datasetLabel: any, label?: any, data?: any, defaultFilled?: boolean) {\n\t\tconst options = this.getOptions();\n\t\tif (options.getIsFilled) {\n\t\t\treturn options.getIsFilled(datasetLabel, label, data, defaultFilled);\n\t\t} else {\n\t\t\treturn defaultFilled;\n\t\t}\n\t}\n\n\tgetFillColor(datasetLabel: any, label?: any, data?: any) {\n\t\tconst options = this.getOptions();\n\t\tconst defaultFillColor = this.getFillScale()[datasetLabel](label);\n\t\tif (options.getFillColor) {\n\t\t\treturn options.getFillColor(datasetLabel, label, data, defaultFillColor);\n\t\t} else {\n\t\t\treturn defaultFillColor;\n\t\t}\n\t}\n\n\tgetStrokeColor(datasetLabel: any, label?: any, data?: any) {\n\t\tconst options = this.getOptions();\n\t\tconst defaultStrokeColor = this.colorScale[datasetLabel](label);\n\t\tif (options.getStrokeColor) {\n\t\t\treturn options.getStrokeColor(datasetLabel, label, data, defaultStrokeColor);\n\t\t} else {\n\t\t\treturn defaultStrokeColor;\n\t\t}\n\t}\n\n\tgetFillScale() {\n\t\t// Choose patternScale or colorScale based on the \"accessibility\" flag\n\t\t// return this.get(\"options\").accessibility ? this.patternScale : this.colorScale;\n\t\treturn this.colorScale;\n\t}\n\n\n\t/*\n\t * Data labels\n\t*/\n\tprotected updateAllDataLabels() {\n\t\t// If allDataLabels hasn't been initialized yet\n\t\t// Set it to the current set of chart labels\n\t\tif (!this.allDataLabels) {\n\t\t\tthis.allDataLabels = this.getDisplayData().labels;\n\t\t} else {\n\t\t\t// Loop through current chart labels\n\t\t\tthis.getDisplayData().labels.forEach(label => {\n\t\t\t\t// If label hasn't been stored yet, store it\n\t\t\t\tif (this.allDataLabels.indexOf(label) === -1) {\n\t\t\t\t\tthis.allDataLabels.push(label);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["model.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,KAAK,aAAa,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,KAAK;AACL,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC;qEACqE;AACrE;IAwBC,oBAAY,QAAa;QAfzB,uBAAuB;QACb,UAAK,GAAQ;YACtB,OAAO,EAAE,EAAE;SACX,CAAC;QASF,qCAAqC;QAC3B,eAAU,GAAQ,EAAE,CAAC;QAG9B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACO,2CAAsB,GAAhC,UAAiC,IAAI;QACpC,OAAO,CAAC,IAAI,CAAC,6PAA6P,CAAC,CAAA;QAC3Q,IAAM,WAAW,GAAG,EAAE,CAAC;QACf,IAAA,wBAAQ,EAAE,oBAAM,CAAU;QAElC,4BAA4B;QAC5B,QAAQ,CAAC,OAAO,CAAC,UAAA,OAAO;YACvB,IAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;YAE5B,2CAA2C;YAC3C,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAC,KAAK,EAAE,CAAC;gBAC7B,IAAM,YA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a,CAAC,CAAC;SAC5D;aAAM;YACN,OAAO,aAAa,CAAC;SACrB;IACF,CAAC;IAED,iCAAY,GAAZ,UAAa,KAAU,EAAE,GAAS,EAAE,IAAU;QAC7C,IAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAClC,IAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC;QACpD,IAAI,OAAO,CAAC,YAAY,EAAE;YACzB,OAAO,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC;SAChE;aAAM;YACN,OAAO,gBAAgB,CAAC;SACxB;IACF,CAAC;IAED,mCAAc,GAAd,UAAe,KAAU,EAAE,GAAS,EAAE,IAAU;QAC/C,IAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAClC,IAAM,kBAAkB,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAClD,IAAI,OAAO,CAAC,cAAc,EAAE;YAC3B,OAAO,OAAO,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,kBAAkB,CAAC,CAAC;SACpE;aAAM;YACN,OAAO,kBAAkB,CAAC;SAC1B;IACF,CAAC;IAED,iCAAY,GAAZ;QACC,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IACF,iBAAC;AAAD,CAAC,AA3ZD,IA2ZC","sourcesContent":["// Internal Imports\nimport * as Configuration from \"./configuration\";\nimport { Tools } from \"./tools\";\nimport * as colorPalettes from \"./services/colorPalettes\";\nimport { Events } from \"./interfaces\";\n\n// D3\nimport { scaleOrdinal } from \"d3-scale\";\nimport { map } from \"d3-collection\";\nimport { stack } from \"d3-shape\";\n\n/** The charting model layer which includes mainly the chart data and options,\n * as well as some misc. information to be shared among components */\nexport class ChartModel {\n\t// Callbacks\n\t/**\n\t * Function to be called when data or options update within the model\n\t * @type Function\n\t */\n\tprotected updateCallback: Function;\n\tprotected services: any;\n\n\t// Internal Model state\n\tprotected state: any = {\n\t\toptions: {}\n\t};\n\n\t// Data labels\n\t/**\n\t * A list of all the data groups that have existed within the lifetime of the chart\n\t * @type string[]\n\t */\n\tprotected allDataGroups: string[];\n\n\t// Fill scales & fill related objects\n\tprotected colorScale: any = {};\n\n\tconstructor(services: any) {\n\t\tthis.services = services;\n\t}\n\n\t/**\n\t * Converts data provided in the older format to tabular\n\t * \n\t */\n\tprotected transformToTabularData(data) {\n\t\tconsole.warn(\"We've updated the charting data format to be tabular by default. The current format you're using is deprecated and will be removed in v1.0, read more here https://carbon-design-system.github.io/carbon-charts/?path=/story/tutorials--tabular-data-format\")\n\t\tconst tabularData = [];\n\t\tconst { datasets, labels } = data;\n\n\t\t// Loop through all datasets\n\t\tdatasets.forEach(dataset => {\n\t\t\tconst group = dataset.label;\n\n\t\t\t// Update each data point to the new format\n\t\t\tdataset.data.forEach((datum, i) => {\n\t\t\t\tconst updatedDatum = {\n\t\t\t\t\tgroup,\n\t\t\t\t\tkey: labels[i]\n\t\t\t\t};\n\n\t\t\t\tif (isNaN(datum)) {\n\t\t\t\t\tupdatedDatum[\"value\"] = datum.value;\n\t\t\t\t\tupdatedDatum[\"date\"] = datum.date;\n\t\t\t\t} else {\n\t\t\t\t\tupdatedDatum[\"value\"] = datum;\n\t\t\t\t}\n\n\t\t\t\ttabularData.push(updatedDatum);\n\t\t\t});\n\t\t});\n\n\t\treturn tabularData;\n\t}\n\n\tprotected getTabularData(data) {\n\t\t// if data is not an array\n\t\tif (!Array.isArray(data)) {\n\t\t\treturn this.transformToTabularData(data);\n\t\t}\n\n\t\treturn data;\n\t}\n\n\tprotected sanitize(data) {\n\t\treturn this.getTabularData(data);\n\t}\n\n\tgetDisplayData() {\n\t\tif (!this.get(\"data\")) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst { ACTIVE } = Configuration.legend.items.status;\n\t\tconst dataGroups = this.getDataGroups();\n\n\t\t// Remove datasets that have been disabled\n\t\tconst displayData = Tools.clone(this.get(\"data\"));\n\t\tconst { groupMapsTo } = this.getOptions().data;\n\n\t\treturn displayData.filter(datum => {\n\t\t\tconst group = dataGroups.find(group => group.name === datum[groupMapsTo]);\n\n\t\t\treturn group.status === ACTIVE;\n\t\t});\n\t}\n\n\tgetData() {\n\t\treturn this.get(\"data\");\n\t}\n\n\t/**\n\t *\n\t * @param newData The new raw data to be set\n\t */\n\tsetData(newData) {\n\t\tconst sanitizedData = this.sanitize(Tools.clone(newData));\n\t\tconst dataGroups = this.generateDataGroups(sanitizedData);\n\n\t\tthis.set({\n\t\t\tdata: sanitizedData,\n\t\t\tdataGroups\n\t\t});\n\n\t\treturn sanitizedData;\n\t}\n\n\t/*\n\t * Data groups\n\t*/\n\tprotected updateAllDataGroups() {\n\t\t// allDataGroups is used to generate a color scale that applies\n\t\t// to all the groups. Now when the data updates, you might remove a group,\n\t\t// and then bring it back in a newer data update, therefore\n\t\t// the order of the groups in allDataGroups matters so that you'd never\n\t\t// have an incorrect color assigned to a group.\n\n\t\t// Also, a new group should only be added to allDataGroups if\n\t\t// it doesn't currently exist\n\n\t\tif (!this.allDataGroups) {\n\t\t\tthis.allDataGroups = this.getDataGroupNames();\n\t\t} else {\n\t\t\t// Loop through current data groups\n\t\t\tthis.getDataGroupNames().forEach(dataGroupName => {\n\t\t\t\t// If group name hasn't been stored yet, store it\n\t\t\t\tif (this.allDataGroups.indexOf(dataGroupName) === -1) {\n\t\t\t\t\tthis.allDataGroups.push(dataGroupName);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tprotected generateDataGroups(data) {\n\t\tconst { groupMapsTo } = this.getOptions().data;\n\t\tconst { ACTIVE } = Configuration.legend.items.status;\n\n\t\tconst uniqueDataGroups = map(data, datum => datum[groupMapsTo]).keys();\n\t\treturn uniqueDataGroups.map(groupName => ({\n\t\t\tname: groupName,\n\t\t\tstatus: ACTIVE\n\t\t}));\n\t}\n\n\tgetDataGroups() {\n\t\treturn this.get(\"dataGroups\");\n\t}\n\n\tgetActiveDataGroups() {\n\t\tconst { ACTIVE } = Configuration.legend.items.status;\n\n\t\treturn this.getDataGroups().filter(dataGroup => dataGroup.status === ACTIVE);\n\t}\n\n\tgetDataGroupNames() {\n\t\treturn this.getDataGroups().map(dataGroup => dataGroup.name);\n\t}\n\n\tgetActiveDataGroupNames() {\n\t\treturn this.getActiveDataGroups().map(dataGroup => dataGroup.name);\n\t}\n\n\tgetGroupedData() {\n\t\tconst displayData = this.getDisplayData();\n\t\tconst groupedData = {};\n\t\tconst { groupMapsTo } = this.getOptions().data;\n\n\t\tdisplayData.map(datum => {\n\t\t\tconst group = datum[groupMapsTo];\n\t\t\tif (groupedData[group] !== null && groupedData[group] !== undefined) {\n\t\t\t\tgroupedData[group].push(datum);\n\t\t\t} else {\n\t\t\t\tgroupedData[group] = [datum];\n\t\t\t}\n\t\t});\n\n\t\treturn Object.keys(groupedData)\n\t\t\t.map(groupName => ({\n\t\t\t\tname: groupName,\n\t\t\t\tdata: groupedData[groupName]\n\t\t\t}));\n\t}\n\n\tgetDataValuesGroupedByKeys() {\n\t\tconst options = this.getOptions();\n\t\tconst { groupMapsTo } = options.data;\n\n\t\tconst displayData = this.getDisplayData();\n\t\tconst domainIdentifier = this.services.cartesianScales.getDomainIdentifier();\n\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\tconst stackKeys = map(displayData, datum => datum[domainIdentifier]).keys();\n\t\tconst dataGroupNames = this.getDataGroupNames();\n\n\t\treturn stackKeys.map(key => {\n\t\t\tconst correspondingValues = { sharedStackKey: key };\n\t\t\tdataGroupNames.forEach(dataGroupName => {\n\t\t\t\tconst correspondingDatum = displayData.find(datum => {\n\t\t\t\t\treturn datum[groupMapsTo] === dataGroupName &&\n\t\t\t\t\t\tdatum[domainIdentifier].toString() === key;\n\t\t\t\t});\n\n\t\t\t\tcorrespondingValues[dataGroupName] = correspondingDatum ? correspondingDatum[rangeIdentifier] : null;\n\t\t\t});\n\t\t\treturn correspondingValues;\n\t\t}) as any;\n\t}\n\n\tgetStackedData() {\n\t\tconst options = this.getOptions();\n\t\tconst { groupMapsTo } = options.data;\n\n\t\tconst dataGroupNames = this.getDataGroupNames();\n\t\tconst dataValuesGroupedByKeys = this.getDataValuesGroupedByKeys();\n\n\t\treturn stack().keys(dataGroupNames)(dataValuesGroupedByKeys)\n\t\t\t.map((series, i) => {\n\t\t\t\t// Add data group names to each series\n\t\t\t\treturn Object.keys(series)\n\t\t\t\t\t.filter((key: any) => !isNaN(key))\n\t\t\t\t\t.map(key => {\n\t\t\t\t\t\tconst element = series[key];\n\t\t\t\t\t\telement[groupMapsTo] = dataGroupNames[i];\n\n\t\t\t\t\t\treturn element;\n\t\t\t\t\t});\n\t\t\t});\n\t}\n\n\t/**\n\t * @return {Object} The chart's options\n\t */\n\tgetOptions() {\n\t\treturn this.state.options;\n\t}\n\n\tset(newState: any, skipUpdate = false) {\n\t\tthis.state = Object.assign({}, this.state, newState);\n\n\t\tif (!skipUpdate) {\n\t\t\tthis.update();\n\t\t}\n\t}\n\n\tget(property?: string) {\n\t\tif (property) {\n\t\t\treturn this.state[property];\n\t\t} else {\n\t\t\treturn this.state;\n\t\t}\n\t}\n\n\t/**\n\t *\n\t * @param newOptions New options to be set\n\t */\n\tsetOptions(newOptions) {\n\t\tthis.set({\n\t\t\toptions: Tools.merge(this.getOptions(), newOptions)\n\t\t});\n\t}\n\n\t/**\n\t *\n\t * Updates miscellanous information within the model\n\t * such as the color scales, or the legend data labels\n\t */\n\tupdate() {\n\t\tif (!this.getDisplayData()) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.updateAllDataGroups();\n\n\t\tthis.setColorScale();\n\t\tthis.services.events.dispatchEvent(Events.Model.UPDATE);\n\t}\n\n\tsetUpdateCallback(cb: Function) {\n\t\tthis.updateCallback = cb;\n\t}\n\n\t/*\n\t * Data labels\n\t*/\n\ttoggleDataLabel(changedLabel: string) {\n\t\tconst { ACTIVE, DISABLED } = Configuration.legend.items.status;\n\t\tconst dataGroups = this.getDataGroups();\n\n\t\tconst hasDeactivatedItems = dataGroups.some(group => group.status === DISABLED);\n\t\tconst activeItems = dataGroups.filter(group => group.status === ACTIVE);\n\n\t\t// If there are deactivated items, toggle \"changedLabel\"\n\t\tif (hasDeactivatedItems) {\n\t\t\t// If the only active item is being toggled\n\t\t\t// Activate all items\n\t\t\tif (activeItems.length === 1 && activeItems[0].name === changedLabel) {\n\t\t\t\t// If every item is active, then enable \"changedLabel\" and disable all other items\n\t\t\t\tdataGroups.forEach((group, i) => {\n\t\t\t\t\tdataGroups[i].status = ACTIVE;\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst indexToChange = dataGroups.findIndex(group => group.name === changedLabel);\n\t\t\t\tdataGroups[indexToChange].status = dataGroups[indexToChange].status === DISABLED ? ACTIVE : DISABLED;\n\t\t\t}\n\t\t} else {\n\t\t\t// If every item is active, then enable \"changedLabel\" and disable all other items\n\t\t\tdataGroups.forEach((group, i) => {\n\t\t\t\tdataGroups[i].status = (group.name === changedLabel ? ACTIVE : DISABLED);\n\t\t\t});\n\t\t}\n\n\t\t// dispatch legend filtering event with the status of all the dataLabels\n\t\tthis.services.events.dispatchEvent(Events.Legend.ITEMS_UPDATE, {\n\t\t\tdataGroups\n\t\t});\n\n\t\t// Update model\n\t\tthis.set({\n\t\t\tdataGroups\n\t\t});\n\t}\n\n\t/*\n\t * Fill scales\n\t*/\n\tprotected setColorScale() {\n\t\tlet defaultColors = colorPalettes.DEFAULT;\n\n\t\tconst options = this.getOptions();\n\t\tconst userProvidedScale = Tools.getProperty(options, \"color\", \"scale\");\n\n\t\t// If there is no valid user provided scale, use the default set of colors\n\t\tif (userProvidedScale === null || Object.keys(userProvidedScale).length === 0) {\n\t\t\tthis.colorScale = scaleOrdinal().range(defaultColors)\n\t\t\t\t.domain(this.allDataGroups);\n\n\t\t\treturn;\n\t\t}\n\n\t\t/**\n\t\t * Go through allDataGroups. If a data group has a color value provided\n\t\t * by the user, add that to the color range\n\t\t * If not, add a default color\n\t\t */\n\t\tconst colorRange = [];\n\t\tlet colorIndex = 0;\n\t\tthis.allDataGroups.forEach(dataGroup => {\n\t\t\tif (userProvidedScale[dataGroup]) {\n\t\t\t\tcolorRange.push(userProvidedScale[dataGroup]);\n\t\t\t} else {\n\t\t\t\tcolorRange.push(defaultColors[colorIndex]);\n\t\t\t}\n\n\t\t\tif (colorIndex === defaultColors.length - 1) {\n\t\t\t\tcolorIndex = 0;\n\t\t\t} else {\n\t\t\t\tcolorIndex++;\n\t\t\t}\n\t\t});\n\n\t\tthis.colorScale = scaleOrdinal().range(colorRange)\n\t\t\t\t.domain(this.allDataGroups);\n\t}\n\n\t/**\n\t * Should the data point be filled?\n\t * @param group\n\t * @param key\n\t * @param value\n\t * @param defaultFilled the default for this chart\n\t */\n\tgetIsFilled(group: any, key?: any, data?: any, defaultFilled?: boolean) {\n\t\tconst options = this.getOptions();\n\t\tif (options.getIsFilled) {\n\t\t\treturn options.getIsFilled(group, key, data, defaultFilled);\n\t\t} else {\n\t\t\treturn defaultFilled;\n\t\t}\n\t}\n\n\tgetFillColor(group: any, key?: any, data?: any) {\n\t\tconst options = this.getOptions();\n\t\tconst defaultFillColor = this.getFillScale()(group);\n\t\tif (options.getFillColor) {\n\t\t\treturn options.getFillColor(group, key, data, defaultFillColor);\n\t\t} else {\n\t\t\treturn defaultFillColor;\n\t\t}\n\t}\n\n\tgetStrokeColor(group: any, key?: any, data?: any) {\n\t\tconst options = this.getOptions();\n\t\tconst defaultStrokeColor = this.colorScale(group);\n\t\tif (options.getStrokeColor) {\n\t\t\treturn options.getStrokeColor(group, key, data, defaultStrokeColor);\n\t\t} else {\n\t\t\treturn defaultStrokeColor;\n\t\t}\n\t}\n\n\tgetFillScale() {\n\t\treturn this.colorScale;\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carbon/charts",
3
- "version": "0.30.7",
3
+ "version": "0.30.8",
4
4
  "description": "Carbon charting components",
5
5
  "main": "./bundle.js",
6
6
  "module": "./index.js",
@@ -82,6 +82,7 @@
82
82
  "extract-text-webpack-plugin": "3.0.2",
83
83
  "file-loader": "1.1.5",
84
84
  "fork-ts-checker-webpack-plugin": "^4.0.5",
85
+ "highlight.js": "9.18.1",
85
86
  "html-loader": "0.5.1",
86
87
  "html-webpack-exclude-assets-plugin": "0.0.7",
87
88
  "html-webpack-plugin": "3.2.0",
@@ -93,6 +94,7 @@
93
94
  "karma-safari-launcher": "1.0.0",
94
95
  "karma-webpack": "4.0.2",
95
96
  "lerna": "3.13.4",
97
+ "marked": "0.8.2",
96
98
  "mini-css-extract-plugin": "0.9.0",
97
99
  "raw-loader": "0.5.1",
98
100
  "react-docgen-typescript-loader": "^3.6.0",
@@ -18,8 +18,14 @@ export declare class CartesianScales extends Service {
18
18
  protected orientation: CartesianOrientations;
19
19
  getDomainAxisPosition(): AxisPositions;
20
20
  getRangeAxisPosition(): AxisPositions;
21
- setDefaultAxes(): void;
22
21
  update(animate?: boolean): void;
22
+ protected findMainVerticalAxisPosition(): AxisPositions.LEFT | AxisPositions.RIGHT;
23
+ protected findMainHorizontalAxisPosition(): AxisPositions.TOP | AxisPositions.BOTTOM;
24
+ protected findDomainAndRangeAxesPositions(mainVerticalAxisPosition: AxisPositions, mainHorizontalAxisPosition: AxisPositions): {
25
+ domainAxisPosition: any;
26
+ rangeAxisPosition: any;
27
+ };
28
+ findDomainAndRangeAxes(): void;
23
29
  determineOrientation(): void;
24
30
  getOrientation(): CartesianOrientations;
25
31
  getScaleByPosition(axisPosition: AxisPositions): any;
@@ -33,8 +39,10 @@ export declare class CartesianScales extends Service {
33
39
  getValueFromScale(axisPosition: AxisPositions, datum: any, index?: number): any;
34
40
  getDomainValue(d: any, i: any): any;
35
41
  getRangeValue(d: any, i: any): any;
36
- /** Uses the primary Y Axis to get data items associated with that value. */
37
- getDataFromDomain(domainValue: any): any[];
42
+ getDomainIdentifier(): any;
43
+ getRangeIdentifier(): any;
44
+ /** Uses the primary Y Axis to get data items associated with that value. */
45
+ getDataFromDomain(domainValue: any): any;
38
46
  protected getScaleDomain(axisPosition: AxisPositions): any;
39
47
  protected createScale(axisPosition: AxisPositions): any;
40
48
  }