@carbon/charts 0.34.7 → 0.34.11

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 (173) hide show
  1. package/CHANGELOG.md +28 -9
  2. package/axis-chart.d.ts +2 -2
  3. package/axis-chart.js +27 -4
  4. package/axis-chart.js.map +1 -1
  5. package/build/demo/data/bar.d.ts +15 -0
  6. package/build/demo/data/zoom-bar.d.ts +74 -0
  7. package/build/src/axis-chart.d.ts +2 -2
  8. package/build/src/components/axes/axis.d.ts +4 -0
  9. package/build/src/components/axes/chart-clip.d.ts +11 -0
  10. package/build/src/components/axes/grid-brush.d.ts +8 -0
  11. package/build/src/components/axes/zoom-bar.d.ts +21 -0
  12. package/build/src/components/component.d.ts +3 -1
  13. package/build/src/components/essentials/legend.d.ts +1 -0
  14. package/build/src/components/graphs/bar.d.ts +1 -0
  15. package/build/src/components/graphs/scatter.d.ts +1 -0
  16. package/build/src/components/index.d.ts +3 -0
  17. package/build/src/configuration.d.ts +8 -1
  18. package/build/src/interfaces/charts.d.ts +6 -2
  19. package/build/src/interfaces/components.d.ts +39 -8
  20. package/build/src/interfaces/enums.d.ts +7 -0
  21. package/build/src/interfaces/events.d.ts +9 -0
  22. package/build/src/model.d.ts +3 -3
  23. package/build/src/services/index.d.ts +1 -0
  24. package/build/src/services/scales-cartesian.d.ts +7 -4
  25. package/build/src/services/zoom.d.ts +5 -0
  26. package/bundle.js +1 -1
  27. package/chart.js +5 -4
  28. package/chart.js.map +1 -1
  29. package/charts/area-stacked.js.map +1 -1
  30. package/charts/area.js.map +1 -1
  31. package/charts/bar-grouped.js.map +1 -1
  32. package/charts/bar-simple.js.map +1 -1
  33. package/charts/bar-stacked.js.map +1 -1
  34. package/charts/bubble.js.map +1 -1
  35. package/charts/donut.js.map +1 -1
  36. package/charts/line.js.map +1 -1
  37. package/charts/meter.js +7 -15
  38. package/charts/meter.js.map +1 -1
  39. package/charts/pie.js.map +1 -1
  40. package/charts/radar.js +3 -1
  41. package/charts/radar.js.map +1 -1
  42. package/charts/scatter.js.map +1 -1
  43. package/components/axes/axis.d.ts +4 -0
  44. package/components/axes/axis.js +33 -2
  45. package/components/axes/axis.js.map +1 -1
  46. package/components/axes/chart-clip.d.ts +11 -0
  47. package/components/axes/chart-clip.js +59 -0
  48. package/components/axes/chart-clip.js.map +1 -0
  49. package/components/axes/grid-brush.d.ts +8 -0
  50. package/components/axes/grid-brush.js +163 -0
  51. package/components/axes/grid-brush.js.map +1 -0
  52. package/components/axes/two-dimensional-axes.js +4 -0
  53. package/components/axes/two-dimensional-axes.js.map +1 -1
  54. package/components/axes/zoom-bar.d.ts +21 -0
  55. package/components/axes/zoom-bar.js +364 -0
  56. package/components/axes/zoom-bar.js.map +1 -0
  57. package/components/component.d.ts +3 -1
  58. package/components/component.js +11 -2
  59. package/components/component.js.map +1 -1
  60. package/components/essentials/legend.d.ts +1 -0
  61. package/components/essentials/legend.js +19 -1
  62. package/components/essentials/legend.js.map +1 -1
  63. package/components/essentials/title-meter.js +28 -17
  64. package/components/essentials/title-meter.js.map +1 -1
  65. package/components/essentials/title.js +2 -1
  66. package/components/essentials/title.js.map +1 -1
  67. package/components/essentials/tooltip-axis.js +4 -1
  68. package/components/essentials/tooltip-axis.js.map +1 -1
  69. package/components/essentials/tooltip.js +13 -0
  70. package/components/essentials/tooltip.js.map +1 -1
  71. package/components/graphs/area-stacked.js +1 -1
  72. package/components/graphs/area-stacked.js.map +1 -1
  73. package/components/graphs/area.js +1 -1
  74. package/components/graphs/area.js.map +1 -1
  75. package/components/graphs/bar-grouped.js +5 -1
  76. package/components/graphs/bar-grouped.js.map +1 -1
  77. package/components/graphs/bar-simple.js +5 -1
  78. package/components/graphs/bar-simple.js.map +1 -1
  79. package/components/graphs/bar-stacked.js +5 -1
  80. package/components/graphs/bar-stacked.js.map +1 -1
  81. package/components/graphs/bar.d.ts +1 -0
  82. package/components/graphs/bar.js +16 -1
  83. package/components/graphs/bar.js.map +1 -1
  84. package/components/graphs/line.js +1 -1
  85. package/components/graphs/line.js.map +1 -1
  86. package/components/graphs/meter.js +13 -12
  87. package/components/graphs/meter.js.map +1 -1
  88. package/components/graphs/pie.js +6 -2
  89. package/components/graphs/pie.js.map +1 -1
  90. package/components/graphs/radar.js.map +1 -1
  91. package/components/graphs/scatter-stacked.js +1 -1
  92. package/components/graphs/scatter-stacked.js.map +1 -1
  93. package/components/graphs/scatter.d.ts +1 -0
  94. package/components/graphs/scatter.js +14 -1
  95. package/components/graphs/scatter.js.map +1 -1
  96. package/components/index.d.ts +3 -0
  97. package/components/index.js +3 -0
  98. package/components/index.js.map +1 -1
  99. package/configuration.d.ts +8 -1
  100. package/configuration.js +20 -3
  101. package/configuration.js.map +1 -1
  102. package/demo/data/bar.d.ts +15 -0
  103. package/demo/data/bar.js +19 -4
  104. package/demo/data/bar.js.map +1 -1
  105. package/demo/data/bundle.js +1 -1
  106. package/demo/data/donut.js.map +1 -1
  107. package/demo/data/index.js +77 -0
  108. package/demo/data/index.js.map +1 -1
  109. package/demo/data/line.js.map +1 -1
  110. package/demo/data/meter.js.map +1 -1
  111. package/demo/data/pie.js.map +1 -1
  112. package/demo/data/radar.js.map +1 -1
  113. package/demo/data/time-series-axis.js +6 -6
  114. package/demo/data/time-series-axis.js.map +1 -1
  115. package/demo/data/zoom-bar.d.ts +74 -0
  116. package/demo/data/zoom-bar.js +91 -0
  117. package/demo/data/zoom-bar.js.map +1 -0
  118. package/demo/styles.css +376 -4
  119. package/demo/styles.css.map +1 -1
  120. package/demo/styles.min.css +1 -1
  121. package/demo/styles.min.css.map +1 -1
  122. package/demo/tsconfig.tsbuildinfo +41 -21
  123. package/interfaces/axis-scales.js.map +1 -1
  124. package/interfaces/charts.d.ts +6 -2
  125. package/interfaces/charts.js.map +1 -1
  126. package/interfaces/components.d.ts +39 -8
  127. package/interfaces/components.js.map +1 -1
  128. package/interfaces/enums.d.ts +7 -0
  129. package/interfaces/enums.js +8 -0
  130. package/interfaces/enums.js.map +1 -1
  131. package/interfaces/events.d.ts +9 -0
  132. package/interfaces/events.js +10 -0
  133. package/interfaces/events.js.map +1 -1
  134. package/model-meter.js +3 -1
  135. package/model-meter.js.map +1 -1
  136. package/model.d.ts +3 -3
  137. package/model.js +10 -9
  138. package/model.js.map +1 -1
  139. package/package.json +1 -1
  140. package/services/essentials/dom-utils.js +9 -3
  141. package/services/essentials/dom-utils.js.map +1 -1
  142. package/services/index.d.ts +1 -0
  143. package/services/index.js +1 -0
  144. package/services/index.js.map +1 -1
  145. package/services/scales-cartesian.d.ts +7 -4
  146. package/services/scales-cartesian.js +27 -12
  147. package/services/scales-cartesian.js.map +1 -1
  148. package/services/zoom.d.ts +5 -0
  149. package/services/zoom.js +73 -0
  150. package/services/zoom.js.map +1 -0
  151. package/styles/components/_grid-brush.scss +18 -0
  152. package/styles/components/_meter-title.scss +5 -1
  153. package/styles/components/_zoom-bar.scss +46 -0
  154. package/styles/components/index.scss +2 -0
  155. package/styles/graphs/_meter.scss +5 -1
  156. package/styles/styles.scss +1 -1
  157. package/styles-g10.css +47 -1
  158. package/styles-g10.css.map +1 -1
  159. package/styles-g10.min.css +1 -1
  160. package/styles-g10.min.css.map +1 -1
  161. package/styles-g100.css +47 -1
  162. package/styles-g100.css.map +1 -1
  163. package/styles-g100.min.css +1 -1
  164. package/styles-g100.min.css.map +1 -1
  165. package/styles-g90.css +47 -1
  166. package/styles-g90.css.map +1 -1
  167. package/styles-g90.min.css +1 -1
  168. package/styles-g90.min.css.map +1 -1
  169. package/styles.css +47 -1
  170. package/styles.css.map +1 -1
  171. package/styles.min.css +1 -1
  172. package/styles.min.css.map +1 -1
  173. package/tsconfig.tsbuildinfo +158 -66
@@ -0,0 +1,364 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ // Internal Imports
15
+ import { Component } from "../component";
16
+ import { Tools } from "../../tools";
17
+ import { Events, ScaleTypes, ZoomBarTypes } from "../../interfaces";
18
+ import { DOMUtils } from "../../services";
19
+ import * as Configuration from "../../configuration";
20
+ // D3 Imports
21
+ import { extent } from "d3-array";
22
+ import { brushX } from "d3-brush";
23
+ import { area, line } from "d3-shape";
24
+ import { event } from "d3-selection";
25
+ var ZoomBar = /** @class */ (function (_super) {
26
+ __extends(ZoomBar, _super);
27
+ function ZoomBar() {
28
+ var _this = _super !== null && _super.apply(this, arguments) || this;
29
+ _this.type = "zoom-bar";
30
+ // The minimum selection x range to trigger handler update
31
+ // Smaller number may introduce a handler flash during initialization
32
+ // Bigger number may not trigger handler update while selection area on chart is very small
33
+ _this.MIN_SELECTION_DIFF = 9e-10;
34
+ // needs to match the style in _zoom-bar.scss
35
+ _this.brushSelector = "g.zoom-bar-brush";
36
+ // Give every zoomBarClip a distinct ID
37
+ // so they don't interfere the other zoom bars in a page
38
+ _this.clipId = "zoomBarClip-" + Math.floor(Math.random() * 99999999999);
39
+ _this.brush = brushX();
40
+ return _this;
41
+ }
42
+ ZoomBar.prototype.init = function () {
43
+ this.services.events.addEventListener(Events.ZoomBar.UPDATE, this.render.bind(this));
44
+ // get initZoomDomain
45
+ var initialZoomDomain = Tools.getProperty(this.model.getOptions(), "zoomBar", "top", "initialZoomDomain");
46
+ if (initialZoomDomain !== null) {
47
+ this.model.set({ zoomDomain: initialZoomDomain }, { skipUpdate: true });
48
+ }
49
+ };
50
+ ZoomBar.prototype.render = function (animate) {
51
+ var _this = this;
52
+ if (animate === void 0) { animate = true; }
53
+ var svg = this.getContainerSVG();
54
+ var options = this.model.getOptions();
55
+ var isDataLoading = Tools.getProperty(options, "data", "loading");
56
+ var zoombarType = Tools.getProperty(this.model.getOptions(), "zoomBar", "top", "type");
57
+ var zoombarHeight = Configuration.zoomBar.height[zoombarType];
58
+ var width = DOMUtils.getSVGElementSize(this.parent, {
59
+ useAttrs: true
60
+ }).width;
61
+ // get axes margins
62
+ var axesLeftMargin = 0;
63
+ var axesMargins = this.model.get("axesMargins");
64
+ if (axesMargins && axesMargins.left) {
65
+ axesLeftMargin = axesMargins.left;
66
+ }
67
+ var container = DOMUtils.appendOrSelect(svg, "svg.zoom-container")
68
+ .attr("width", "100%")
69
+ .attr("height", zoombarHeight)
70
+ .attr("opacity", 1);
71
+ var spacer = DOMUtils.appendOrSelect(svg, "rect.zoom-spacer")
72
+ .attr("x", 0)
73
+ .attr("y", zoombarHeight)
74
+ .attr("width", "100%")
75
+ .attr("height", Configuration.zoomBar.spacerHeight)
76
+ .attr("opacity", 1)
77
+ .attr("fill", "none");
78
+ if (zoombarType === ZoomBarTypes.GRAPH_VIEW) {
79
+ // Draw zoombar background rectangle
80
+ DOMUtils.appendOrSelect(container, "rect.zoom-bg")
81
+ .attr("x", axesLeftMargin)
82
+ .attr("y", 0)
83
+ .attr("width", width - axesLeftMargin)
84
+ .attr("height", "100%");
85
+ }
86
+ else if (zoombarType === ZoomBarTypes.SLIDER_VIEW) {
87
+ // Draw zoombar background line
88
+ DOMUtils.appendOrSelect(container, "rect.zoom-slider-bg")
89
+ .attr("x", axesLeftMargin)
90
+ .attr("y", zoombarHeight / 2 - 1)
91
+ .attr("width", width - axesLeftMargin)
92
+ .attr("height", 2);
93
+ }
94
+ if (isDataLoading) {
95
+ // TODO - zoom bar skeleton could be improved in the future
96
+ return;
97
+ }
98
+ var cartesianScales = this.services.cartesianScales;
99
+ var mainXScale = cartesianScales.getMainXScale();
100
+ var mainYScale = cartesianScales.getMainYScale();
101
+ var mainXScaleType = cartesianScales.getMainXScaleType();
102
+ if (mainXScale && mainXScaleType === ScaleTypes.TIME) {
103
+ var zoomBarData = this.services.zoom.getZoomBarData();
104
+ this.xScale = mainXScale.copy();
105
+ this.yScale = mainYScale.copy();
106
+ var defaultDomain = this.services.zoom.getDefaultZoomBarDomain();
107
+ // add value 0 to the extended domain for zoom bar area graph
108
+ this.compensateDataForDefaultDomain(zoomBarData, defaultDomain);
109
+ this.xScale.range([axesLeftMargin, width]).domain(defaultDomain);
110
+ // keep max selection range
111
+ this.maxSelectionRange = this.xScale.range();
112
+ this.yScale
113
+ .range([0, zoombarHeight - 6])
114
+ .domain(extent(zoomBarData, function (d) { return d.value; }));
115
+ var zoomDomain = this.model.get("zoomDomain");
116
+ if (zoombarType === ZoomBarTypes.GRAPH_VIEW) {
117
+ this.renderZoomBarArea(container, "path.zoom-graph-area-unselected", zoomBarData, null);
118
+ this.updateClipPath(svg, this.clipId, 0, 0, 0, 0);
119
+ this.renderZoomBarArea(container, "path.zoom-graph-area", zoomBarData, this.clipId);
120
+ // Draw the zoom base line
121
+ var baselineGenerator = line()([
122
+ [axesLeftMargin, zoombarHeight],
123
+ [width, zoombarHeight]
124
+ ]);
125
+ var zoomBaseline = DOMUtils.appendOrSelect(container, "path.zoom-bg-baseline").attr("d", baselineGenerator);
126
+ }
127
+ // Attach brushing event listeners
128
+ this.addBrushEventListener(zoomDomain, axesLeftMargin, width);
129
+ // Draw the brushing area
130
+ var brushArea = DOMUtils.appendOrSelect(svg, this.brushSelector).call(this.brush);
131
+ if (zoomDomain === undefined) {
132
+ // do nothing, initialization not completed yet
133
+ // don't update brushHandle to avoid flash
134
+ }
135
+ else if (zoomDomain[0].valueOf() === zoomDomain[1].valueOf()) {
136
+ brushArea.call(this.brush.move, this.xScale.range()); // default to full range
137
+ this.updateBrushHandle(this.getContainerSVG(), this.xScale.range(), this.xScale.domain());
138
+ }
139
+ else {
140
+ var selected = zoomDomain.map(function (domain) {
141
+ return _this.xScale(domain);
142
+ });
143
+ if (selected[1] - selected[0] < this.MIN_SELECTION_DIFF) {
144
+ // initialization not completed yet
145
+ // don't update brushHandle to avoid flash
146
+ }
147
+ else {
148
+ brushArea.call(this.brush.move, selected); // set brush to correct position
149
+ this.updateBrushHandle(this.getContainerSVG(), selected, zoomDomain);
150
+ }
151
+ }
152
+ }
153
+ };
154
+ ZoomBar.prototype.addBrushEventListener = function (zoomDomain, axesLeftMargin, width) {
155
+ var _this = this;
156
+ var brushEventListener = function () {
157
+ var selection = event.selection;
158
+ // follow d3 behavior: when selection is null, reset default full range
159
+ // select behavior is completed, but nothing selected
160
+ if (selection === null) {
161
+ _this.handleBrushedEvent(zoomDomain, _this.xScale, _this.xScale.range());
162
+ }
163
+ else if (selection[0] === selection[1]) {
164
+ // select behavior is not completed yet, do nothing
165
+ }
166
+ else {
167
+ _this.handleBrushedEvent(zoomDomain, _this.xScale, selection);
168
+ }
169
+ };
170
+ var zoombarType = Tools.getProperty(this.model.getOptions(), "zoomBar", "top", "type");
171
+ var zoombarHeight = Configuration.zoomBar.height[zoombarType];
172
+ // Initialize the d3 brush
173
+ this.brush
174
+ .extent([
175
+ [axesLeftMargin, 0],
176
+ [width, zoombarHeight]
177
+ ])
178
+ .on("start brush end", null) // remove old listener first
179
+ .on("start brush end", brushEventListener);
180
+ };
181
+ // brush event listener
182
+ ZoomBar.prototype.handleBrushedEvent = function (zoomDomain, scale, selection) {
183
+ var newDomain = [
184
+ scale.invert(selection[0]),
185
+ scale.invert(selection[1])
186
+ ];
187
+ // update brush handle position
188
+ this.updateBrushHandle(this.getContainerSVG(), selection, newDomain);
189
+ // be aware that the value of d3.event changes during an event!
190
+ // update zoomDomain only if the event comes from mouse event
191
+ if (event.sourceEvent != null &&
192
+ (event.sourceEvent.type === "mousemove" ||
193
+ event.sourceEvent.type === "mouseup" ||
194
+ event.sourceEvent.type === "mousedown")) {
195
+ // only if zoomDomain is never set or needs update
196
+ if (zoomDomain === undefined ||
197
+ zoomDomain[0] !== newDomain[0] ||
198
+ zoomDomain[1] !== newDomain[1]) {
199
+ this.model.set({ zoomDomain: newDomain }, { animate: false });
200
+ }
201
+ // dispatch selection events
202
+ var zoomBarEventType = void 0;
203
+ if (event.type === "start") {
204
+ zoomBarEventType = Events.ZoomBar.SELECTION_START;
205
+ }
206
+ else if (event.type === "brush") {
207
+ zoomBarEventType = Events.ZoomBar.SELECTION_IN_PROGRESS;
208
+ }
209
+ else if (event.type === "end") {
210
+ zoomBarEventType = Events.ZoomBar.SELECTION_END;
211
+ }
212
+ this.services.events.dispatchEvent(zoomBarEventType, {
213
+ selection: selection,
214
+ newDomain: newDomain
215
+ });
216
+ }
217
+ };
218
+ ZoomBar.prototype.updateBrushHandle = function (svg, selection, domain) {
219
+ var self = this;
220
+ var handleWidth = 5;
221
+ var zoombarType = Tools.getProperty(this.model.getOptions(), "zoomBar", "top", "type");
222
+ var handleHeight = Configuration.zoomBar.height[zoombarType];
223
+ var handleXDiff = -handleWidth / 2;
224
+ var handleBarWidth = 1;
225
+ var handleBarHeight = zoombarType === ZoomBarTypes.GRAPH_VIEW ? 12 : 6;
226
+ var handleBarXDiff = -handleBarWidth / 2;
227
+ var handleYBarDiff = (handleHeight - handleBarHeight) / 2;
228
+ // handle
229
+ svg.select(this.brushSelector)
230
+ .selectAll("rect.handle")
231
+ .data([{ type: "w" }, { type: "e" }])
232
+ .attr("x", function (d) {
233
+ if (d.type === "w") {
234
+ // handle should not exceed zoom bar range
235
+ return Math.max(selection[0] + handleXDiff, self.maxSelectionRange[0]);
236
+ }
237
+ else if (d.type === "e") {
238
+ // handle should not exceed zoom bar range
239
+ return Math.min(selection[1] + handleXDiff, self.maxSelectionRange[1] - handleWidth);
240
+ }
241
+ })
242
+ .attr("y", 0)
243
+ .attr("width", handleWidth)
244
+ .attr("height", handleHeight)
245
+ .attr("cursor", "pointer")
246
+ .style("display", null); // always display
247
+ // handle-bar
248
+ var handleBars = svg
249
+ .select(this.brushSelector)
250
+ .selectAll("rect.handle-bar")
251
+ .data([{ type: "w" }, { type: "e" }]);
252
+ // create rect if not exists
253
+ handleBars
254
+ .enter()
255
+ .append("rect")
256
+ .attr("class", function (d) {
257
+ return "handle-bar handle-bar--" + d.type;
258
+ });
259
+ // update positions
260
+ handleBars
261
+ .attr("x", function (d) {
262
+ if (d.type === "w") {
263
+ return Math.max(selection[0] + handleBarXDiff, self.maxSelectionRange[0] - handleXDiff + handleBarXDiff);
264
+ }
265
+ else if (d.type === "e") {
266
+ return Math.min(selection[1] + handleBarXDiff, self.maxSelectionRange[1] + handleXDiff + handleBarXDiff);
267
+ }
268
+ })
269
+ .attr("y", handleYBarDiff)
270
+ .attr("width", handleBarWidth)
271
+ .attr("height", handleBarHeight)
272
+ .attr("cursor", "pointer");
273
+ // Update slider selected area
274
+ if (zoombarType === ZoomBarTypes.SLIDER_VIEW) {
275
+ this.updateSliderSelectedArea(selection);
276
+ }
277
+ this.updateClipPath(svg, this.clipId, selection[0], 0, selection[1] - selection[0], handleHeight);
278
+ };
279
+ ZoomBar.prototype.updateSliderSelectedArea = function (selection) {
280
+ var zoombarType = Tools.getProperty(this.model.getOptions(), "zoomBar", "top", "type");
281
+ var zoombarHeight = Configuration.zoomBar.height[zoombarType];
282
+ var width = DOMUtils.getSVGElementSize(this.parent, {
283
+ useAttrs: true
284
+ }).width;
285
+ // get axes margins
286
+ var axesLeftMargin = 0;
287
+ var axesMargins = this.model.get("axesMargins");
288
+ if (axesMargins && axesMargins.left) {
289
+ axesLeftMargin = axesMargins.left;
290
+ }
291
+ var svg = this.getContainerSVG();
292
+ var container = svg.select("svg.zoom-container");
293
+ // Draw zoombar background line
294
+ DOMUtils.appendOrSelect(container, "rect.zoom-slider-selected-area")
295
+ .attr("x", selection[0])
296
+ .attr("y", zoombarHeight / 2 - 1)
297
+ .attr("width", selection[1] - selection[0])
298
+ .attr("height", 2);
299
+ };
300
+ ZoomBar.prototype.renderZoomBarArea = function (container, querySelector, data, clipId) {
301
+ var cartesianScales = this.services.cartesianScales;
302
+ var mainXAxisPosition = cartesianScales.getMainXAxisPosition();
303
+ var mainYAxisPosition = cartesianScales.getMainYAxisPosition();
304
+ var mainXScaleType = cartesianScales.getMainXScaleType();
305
+ var mainYScaleType = cartesianScales.getMainYScaleType();
306
+ var accessorFunction = function (scale, scaleType, axisPosition) {
307
+ return function (d, i) {
308
+ return cartesianScales.getValueFromScale(scale, scaleType, axisPosition, d, i);
309
+ };
310
+ };
311
+ var xAccessor = accessorFunction(this.xScale, mainXScaleType, mainXAxisPosition);
312
+ var yAccessor = accessorFunction(this.yScale, mainYScaleType, mainYAxisPosition);
313
+ var zoombarType = Tools.getProperty(this.model.getOptions(), "zoomBar", "top", "type");
314
+ var zoombarHeight = Configuration.zoomBar.height[zoombarType];
315
+ var areaGenerator = area()
316
+ .x(function (d, i) { return xAccessor(d, i); })
317
+ .y0(zoombarHeight)
318
+ .y1(function (d, i) { return zoombarHeight - yAccessor(d, i); });
319
+ var areaGraph = DOMUtils.appendOrSelect(container, querySelector)
320
+ .datum(data)
321
+ .attr("d", areaGenerator);
322
+ if (clipId) {
323
+ areaGraph.attr("clip-path", "url(#" + clipId + ")");
324
+ }
325
+ };
326
+ ZoomBar.prototype.updateClipPath = function (svg, clipId, x, y, width, height) {
327
+ var zoomBarClipPath = DOMUtils.appendOrSelect(svg, "clipPath").attr("id", clipId);
328
+ DOMUtils.appendOrSelect(zoomBarClipPath, "rect")
329
+ .attr("x", x)
330
+ .attr("y", y)
331
+ .attr("width", width)
332
+ .attr("height", height);
333
+ };
334
+ // assume the domains in data are already sorted
335
+ ZoomBar.prototype.compensateDataForDefaultDomain = function (data, defaultDomain) {
336
+ if (!data || data.length < 2) {
337
+ return;
338
+ }
339
+ var domainIdentifier = this.services.cartesianScales.getDomainIdentifier();
340
+ var rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();
341
+ // if min domain is extended
342
+ if (Number(defaultDomain[0]) < Number(data[0][domainIdentifier])) {
343
+ var newDatum = {};
344
+ newDatum[domainIdentifier] = defaultDomain[0];
345
+ newDatum[rangeIdentifier] = 0;
346
+ data.unshift(newDatum);
347
+ }
348
+ // if max domain is extended
349
+ if (Number(defaultDomain[1]) >
350
+ Number(data[data.length - 1][domainIdentifier])) {
351
+ var newDatum = {};
352
+ newDatum[domainIdentifier] = defaultDomain[1];
353
+ newDatum[rangeIdentifier] = 0;
354
+ data.push(newDatum);
355
+ }
356
+ };
357
+ ZoomBar.prototype.destroy = function () {
358
+ this.brush.on("start brush end", null); // remove event listener
359
+ this.services.events.removeEventListener(Events.ZoomBar.UPDATE, this.render.bind(this));
360
+ };
361
+ return ZoomBar;
362
+ }(Component));
363
+ export { ZoomBar };
364
+ //# sourceMappingURL=../../../src/components/axes/zoom-bar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zoom-bar.js","sourceRoot":"","sources":["zoom-bar.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AAErD,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC;IAA6B,2BAAS;IAAtC;QAAA,qEA2eC;QA1eA,UAAI,GAAG,UAAU,CAAC;QAElB,0DAA0D;QAC1D,qEAAqE;QACrE,2FAA2F;QAC3F,wBAAkB,GAAG,KAAK,CAAC;QAE3B,6CAA6C;QAC7C,mBAAa,GAAG,kBAAkB,CAAC;QAKnC,uCAAuC;QACvC,wDAAwD;QACxD,YAAM,GAAG,c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MAAM,GAAG,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,EAC9C;YACD,IAAM,QAAQ,GAAG,EAAE,CAAC;YACpB,QAAQ,CAAC,gBAAgB,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;YAC9C,QAAQ,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;YAC9B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACpB;IACF,CAAC;IAED,yBAAO,GAAP;QACC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC,CAAC,wBAAwB;QAChE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,mBAAmB,CACvC,MAAM,CAAC,OAAO,CAAC,MAAM,EACrB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CACtB,CAAC;IACH,CAAC;IACF,cAAC;AAAD,CAAC,AA3eD,CAA6B,SAAS,GA2erC","sourcesContent":["// Internal Imports\nimport { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport { Events, ScaleTypes, ZoomBarTypes } from \"../../interfaces\";\nimport { DOMUtils } from \"../../services\";\nimport * as Configuration from \"../../configuration\";\n\n// D3 Imports\nimport { extent } from \"d3-array\";\nimport { brushX } from \"d3-brush\";\nimport { area, line } from \"d3-shape\";\nimport { event } from \"d3-selection\";\n\nexport class ZoomBar extends Component {\n\ttype = \"zoom-bar\";\n\n\t// The minimum selection x range to trigger handler update\n\t// Smaller number may introduce a handler flash during initialization\n\t// Bigger number may not trigger handler update while selection area on chart is very small\n\tMIN_SELECTION_DIFF = 9e-10;\n\n\t// needs to match the style in _zoom-bar.scss\n\tbrushSelector = \"g.zoom-bar-brush\";\n\n\t// The max allowed selection range, will be updated soon in render()\n\tmaxSelectionRange: [0, 0];\n\n\t// Give every zoomBarClip a distinct ID\n\t// so they don't interfere the other zoom bars in a page\n\tclipId = \"zoomBarClip-\" + Math.floor(Math.random() * 99999999999);\n\n\tbrush = brushX();\n\txScale: any;\n\tyScale: any;\n\n\tinit() {\n\t\tthis.services.events.addEventListener(\n\t\t\tEvents.ZoomBar.UPDATE,\n\t\t\tthis.render.bind(this)\n\t\t);\n\n\t\t// get initZoomDomain\n\t\tconst initialZoomDomain = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"zoomBar\",\n\t\t\t\"top\",\n\t\t\t\"initialZoomDomain\"\n\t\t);\n\t\tif (initialZoomDomain !== null) {\n\t\t\tthis.model.set(\n\t\t\t\t{ zoomDomain: initialZoomDomain },\n\t\t\t\t{ skipUpdate: true }\n\t\t\t);\n\t\t}\n\t}\n\n\trender(animate = true) {\n\t\tconst svg = this.getContainerSVG();\n\t\tconst options = this.model.getOptions();\n\n\t\tconst isDataLoading = Tools.getProperty(options, \"data\", \"loading\");\n\n\t\tconst zoombarType = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"zoomBar\",\n\t\t\t\"top\",\n\t\t\t\"type\"\n\t\t);\n\t\tconst zoombarHeight = Configuration.zoomBar.height[zoombarType];\n\n\t\tconst { width } = DOMUtils.getSVGElementSize(this.parent, {\n\t\t\tuseAttrs: true\n\t\t});\n\n\t\t// get axes margins\n\t\tlet axesLeftMargin = 0;\n\t\tconst axesMargins = this.model.get(\"axesMargins\");\n\t\tif (axesMargins && axesMargins.left) {\n\t\t\taxesLeftMargin = axesMargins.left;\n\t\t}\n\n\t\tconst container = DOMUtils.appendOrSelect(svg, \"svg.zoom-container\")\n\t\t\t.attr(\"width\", \"100%\")\n\t\t\t.attr(\"height\", zoombarHeight)\n\t\t\t.attr(\"opacity\", 1);\n\n\t\tconst spacer = DOMUtils.appendOrSelect(svg, \"rect.zoom-spacer\")\n\t\t\t.attr(\"x\", 0)\n\t\t\t.attr(\"y\", zoombarHeight)\n\t\t\t.attr(\"width\", \"100%\")\n\t\t\t.attr(\"height\", Configuration.zoomBar.spacerHeight)\n\t\t\t.attr(\"opacity\", 1)\n\t\t\t.attr(\"fill\", \"none\");\n\n\t\tif (zoombarType === ZoomBarTypes.GRAPH_VIEW) {\n\t\t\t// Draw zoombar background rectangle\n\t\t\tDOMUtils.appendOrSelect(container, \"rect.zoom-bg\")\n\t\t\t\t.attr(\"x\", axesLeftMargin)\n\t\t\t\t.attr(\"y\", 0)\n\t\t\t\t.attr(\"width\", width - axesLeftMargin)\n\t\t\t\t.attr(\"height\", \"100%\");\n\t\t} else if (zoombarType === ZoomBarTypes.SLIDER_VIEW) {\n\t\t\t// Draw zoombar background line\n\t\t\tDOMUtils.appendOrSelect(container, \"rect.zoom-slider-bg\")\n\t\t\t\t.attr(\"x\", axesLeftMargin)\n\t\t\t\t.attr(\"y\", zoombarHeight / 2 - 1)\n\t\t\t\t.attr(\"width\", width - axesLeftMargin)\n\t\t\t\t.attr(\"height\", 2);\n\t\t}\n\n\t\tif (isDataLoading) {\n\t\t\t// TODO - zoom bar skeleton could be improved in the future\n\t\t\treturn;\n\t\t}\n\n\t\tconst { cartesianScales } = this.services;\n\t\tconst mainXScale = cartesianScales.getMainXScale();\n\t\tconst mainYScale = cartesianScales.getMainYScale();\n\t\tconst mainXScaleType = cartesianScales.getMainXScaleType();\n\n\t\tif (mainXScale && mainXScaleType === ScaleTypes.TIME) {\n\t\t\tconst zoomBarData = this.services.zoom.getZoomBarData();\n\t\t\tthis.xScale = mainXScale.copy();\n\t\t\tthis.yScale = mainYScale.copy();\n\n\t\t\tconst defaultDomain = this.services.zoom.getDefaultZoomBarDomain();\n\n\t\t\t// add value 0 to the extended domain for zoom bar area graph\n\t\t\tthis.compensateDataForDefaultDomain(zoomBarData, defaultDomain);\n\n\t\t\tthis.xScale.range([axesLeftMargin, width]).domain(defaultDomain);\n\n\t\t\t// keep max selection range\n\t\t\tthis.maxSelectionRange = this.xScale.range();\n\n\t\t\tthis.yScale\n\t\t\t\t.range([0, zoombarHeight - 6])\n\t\t\t\t.domain(extent(zoomBarData, (d: any) => d.value));\n\n\t\t\tconst zoomDomain = this.model.get(\"zoomDomain\");\n\n\t\t\tif (zoombarType === ZoomBarTypes.GRAPH_VIEW) {\n\t\t\t\tthis.renderZoomBarArea(\n\t\t\t\t\tcontainer,\n\t\t\t\t\t\"path.zoom-graph-area-unselected\",\n\t\t\t\t\tzoomBarData,\n\t\t\t\t\tnull\n\t\t\t\t);\n\t\t\t\tthis.updateClipPath(svg, this.clipId, 0, 0, 0, 0);\n\t\t\t\tthis.renderZoomBarArea(\n\t\t\t\t\tcontainer,\n\t\t\t\t\t\"path.zoom-graph-area\",\n\t\t\t\t\tzoomBarData,\n\t\t\t\t\tthis.clipId\n\t\t\t\t);\n\n\t\t\t\t// Draw the zoom base line\n\t\t\t\tconst baselineGenerator = line()([\n\t\t\t\t\t[axesLeftMargin, zoombarHeight],\n\t\t\t\t\t[width, zoombarHeight]\n\t\t\t\t]);\n\t\t\t\tconst zoomBaseline = DOMUtils.appendOrSelect(\n\t\t\t\t\tcontainer,\n\t\t\t\t\t\"path.zoom-bg-baseline\"\n\t\t\t\t).attr(\"d\", baselineGenerator);\n\t\t\t}\n\n\t\t\t// Attach brushing event listeners\n\t\t\tthis.addBrushEventListener(zoomDomain, axesLeftMargin, width);\n\n\t\t\t// Draw the brushing area\n\t\t\tconst brushArea = DOMUtils.appendOrSelect(\n\t\t\t\tsvg,\n\t\t\t\tthis.brushSelector\n\t\t\t).call(this.brush);\n\n\t\t\tif (zoomDomain === undefined) {\n\t\t\t\t// do nothing, initialization not completed yet\n\t\t\t\t// don't update brushHandle to avoid flash\n\t\t\t} else if (zoomDomain[0].valueOf() === zoomDomain[1].valueOf()) {\n\t\t\t\tbrushArea.call(this.brush.move, this.xScale.range()); // default to full range\n\t\t\t\tthis.updateBrushHandle(\n\t\t\t\t\tthis.getContainerSVG(),\n\t\t\t\t\tthis.xScale.range(),\n\t\t\t\t\tthis.xScale.domain()\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst selected = zoomDomain.map((domain) =>\n\t\t\t\t\tthis.xScale(domain)\n\t\t\t\t);\n\t\t\t\tif (selected[1] - selected[0] < this.MIN_SELECTION_DIFF) {\n\t\t\t\t\t// initialization not completed yet\n\t\t\t\t\t// don't update brushHandle to avoid flash\n\t\t\t\t} else {\n\t\t\t\t\tbrushArea.call(this.brush.move, selected); // set brush to correct position\n\t\t\t\t\tthis.updateBrushHandle(\n\t\t\t\t\t\tthis.getContainerSVG(),\n\t\t\t\t\t\tselected,\n\t\t\t\t\t\tzoomDomain\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\taddBrushEventListener(zoomDomain, axesLeftMargin, width) {\n\t\tconst brushEventListener = () => {\n\t\t\tconst selection = event.selection;\n\t\t\t// follow d3 behavior: when selection is null, reset default full range\n\t\t\t// select behavior is completed, but nothing selected\n\t\t\tif (selection === null) {\n\t\t\t\tthis.handleBrushedEvent(\n\t\t\t\t\tzoomDomain,\n\t\t\t\t\tthis.xScale,\n\t\t\t\t\tthis.xScale.range()\n\t\t\t\t);\n\t\t\t} else if (selection[0] === selection[1]) {\n\t\t\t\t// select behavior is not completed yet, do nothing\n\t\t\t} else {\n\t\t\t\tthis.handleBrushedEvent(zoomDomain, this.xScale, selection);\n\t\t\t}\n\t\t};\n\n\t\tconst zoombarType = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"zoomBar\",\n\t\t\t\"top\",\n\t\t\t\"type\"\n\t\t);\n\t\tconst zoombarHeight = Configuration.zoomBar.height[zoombarType];\n\n\t\t// Initialize the d3 brush\n\t\tthis.brush\n\t\t\t.extent([\n\t\t\t\t[axesLeftMargin, 0],\n\t\t\t\t[width, zoombarHeight]\n\t\t\t])\n\t\t\t.on(\"start brush end\", null) // remove old listener first\n\t\t\t.on(\"start brush end\", brushEventListener);\n\t}\n\n\t// brush event listener\n\thandleBrushedEvent(zoomDomain, scale, selection) {\n\t\tconst newDomain = [\n\t\t\tscale.invert(selection[0]),\n\t\t\tscale.invert(selection[1])\n\t\t];\n\n\t\t// update brush handle position\n\t\tthis.updateBrushHandle(this.getContainerSVG(), selection, newDomain);\n\n\t\t// be aware that the value of d3.event changes during an event!\n\t\t// update zoomDomain only if the event comes from mouse event\n\t\tif (\n\t\t\tevent.sourceEvent != null &&\n\t\t\t(event.sourceEvent.type === \"mousemove\" ||\n\t\t\t\tevent.sourceEvent.type === \"mouseup\" ||\n\t\t\t\tevent.sourceEvent.type === \"mousedown\")\n\t\t) {\n\t\t\t// only if zoomDomain is never set or needs update\n\t\t\tif (\n\t\t\t\tzoomDomain === undefined ||\n\t\t\t\tzoomDomain[0] !== newDomain[0] ||\n\t\t\t\tzoomDomain[1] !== newDomain[1]\n\t\t\t) {\n\t\t\t\tthis.model.set({ zoomDomain: newDomain }, { animate: false });\n\t\t\t}\n\n\t\t\t// dispatch selection events\n\t\t\tlet zoomBarEventType;\n\t\t\tif (event.type === \"start\") {\n\t\t\t\tzoomBarEventType = Events.ZoomBar.SELECTION_START;\n\t\t\t} else if (event.type === \"brush\") {\n\t\t\t\tzoomBarEventType = Events.ZoomBar.SELECTION_IN_PROGRESS;\n\t\t\t} else if (event.type === \"end\") {\n\t\t\t\tzoomBarEventType = Events.ZoomBar.SELECTION_END;\n\t\t\t}\n\t\t\tthis.services.events.dispatchEvent(zoomBarEventType, {\n\t\t\t\tselection,\n\t\t\t\tnewDomain\n\t\t\t});\n\t\t}\n\t}\n\n\tupdateBrushHandle(svg, selection, domain) {\n\t\tconst self = this;\n\t\tconst handleWidth = 5;\n\n\t\tconst zoombarType = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"zoomBar\",\n\t\t\t\"top\",\n\t\t\t\"type\"\n\t\t);\n\t\tconst handleHeight = Configuration.zoomBar.height[zoombarType];\n\t\tconst handleXDiff = -handleWidth / 2;\n\n\t\tconst handleBarWidth = 1;\n\t\tconst handleBarHeight =\n\t\t\tzoombarType === ZoomBarTypes.GRAPH_VIEW ? 12 : 6;\n\t\tconst handleBarXDiff = -handleBarWidth / 2;\n\t\tconst handleYBarDiff = (handleHeight - handleBarHeight) / 2;\n\n\t\t// handle\n\t\tsvg.select(this.brushSelector)\n\t\t\t.selectAll(\"rect.handle\")\n\t\t\t.data([{ type: \"w\" }, { type: \"e\" }])\n\t\t\t.attr(\"x\", function (d) {\n\t\t\t\tif (d.type === \"w\") {\n\t\t\t\t\t// handle should not exceed zoom bar range\n\t\t\t\t\treturn Math.max(\n\t\t\t\t\t\tselection[0] + handleXDiff,\n\t\t\t\t\t\tself.maxSelectionRange[0]\n\t\t\t\t\t);\n\t\t\t\t} else if (d.type === \"e\") {\n\t\t\t\t\t// handle should not exceed zoom bar range\n\t\t\t\t\treturn Math.min(\n\t\t\t\t\t\tselection[1] + handleXDiff,\n\t\t\t\t\t\tself.maxSelectionRange[1] - handleWidth\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.attr(\"y\", 0)\n\t\t\t.attr(\"width\", handleWidth)\n\t\t\t.attr(\"height\", handleHeight)\n\t\t\t.attr(\"cursor\", \"pointer\")\n\t\t\t.style(\"display\", null); // always display\n\n\t\t// handle-bar\n\t\tconst handleBars = svg\n\t\t\t.select(this.brushSelector)\n\t\t\t.selectAll(\"rect.handle-bar\")\n\t\t\t.data([{ type: \"w\" }, { type: \"e\" }]);\n\t\t// create rect if not exists\n\t\thandleBars\n\t\t\t.enter()\n\t\t\t.append(\"rect\")\n\t\t\t.attr(\"class\", function (d) {\n\t\t\t\treturn \"handle-bar handle-bar--\" + d.type;\n\t\t\t});\n\t\t// update positions\n\t\thandleBars\n\t\t\t.attr(\"x\", function (d) {\n\t\t\t\tif (d.type === \"w\") {\n\t\t\t\t\treturn Math.max(\n\t\t\t\t\t\tselection[0] + handleBarXDiff,\n\t\t\t\t\t\tself.maxSelectionRange[0] - handleXDiff + handleBarXDiff\n\t\t\t\t\t);\n\t\t\t\t} else if (d.type === \"e\") {\n\t\t\t\t\treturn Math.min(\n\t\t\t\t\t\tselection[1] + handleBarXDiff,\n\t\t\t\t\t\tself.maxSelectionRange[1] + handleXDiff + handleBarXDiff\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.attr(\"y\", handleYBarDiff)\n\t\t\t.attr(\"width\", handleBarWidth)\n\t\t\t.attr(\"height\", handleBarHeight)\n\t\t\t.attr(\"cursor\", \"pointer\");\n\n\t\t// Update slider selected area\n\t\tif (zoombarType === ZoomBarTypes.SLIDER_VIEW) {\n\t\t\tthis.updateSliderSelectedArea(selection);\n\t\t}\n\n\t\tthis.updateClipPath(\n\t\t\tsvg,\n\t\t\tthis.clipId,\n\t\t\tselection[0],\n\t\t\t0,\n\t\t\tselection[1] - selection[0],\n\t\t\thandleHeight\n\t\t);\n\t}\n\n\tupdateSliderSelectedArea(selection) {\n\t\tconst zoombarType = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"zoomBar\",\n\t\t\t\"top\",\n\t\t\t\"type\"\n\t\t);\n\t\tconst zoombarHeight = Configuration.zoomBar.height[zoombarType];\n\n\t\tconst { width } = DOMUtils.getSVGElementSize(this.parent, {\n\t\t\tuseAttrs: true\n\t\t});\n\n\t\t// get axes margins\n\t\tlet axesLeftMargin = 0;\n\t\tconst axesMargins = this.model.get(\"axesMargins\");\n\t\tif (axesMargins && axesMargins.left) {\n\t\t\taxesLeftMargin = axesMargins.left;\n\t\t}\n\n\t\tconst svg = this.getContainerSVG();\n\t\tconst container = svg.select(\"svg.zoom-container\");\n\n\t\t// Draw zoombar background line\n\t\tDOMUtils.appendOrSelect(container, \"rect.zoom-slider-selected-area\")\n\t\t\t.attr(\"x\", selection[0])\n\t\t\t.attr(\"y\", zoombarHeight / 2 - 1)\n\t\t\t.attr(\"width\", selection[1] - selection[0])\n\t\t\t.attr(\"height\", 2);\n\t}\n\n\trenderZoomBarArea(container, querySelector, data, clipId) {\n\t\tconst { cartesianScales } = this.services;\n\t\tconst mainXAxisPosition = cartesianScales.getMainXAxisPosition();\n\t\tconst mainYAxisPosition = cartesianScales.getMainYAxisPosition();\n\t\tconst mainXScaleType = cartesianScales.getMainXScaleType();\n\t\tconst mainYScaleType = cartesianScales.getMainYScaleType();\n\n\t\tconst accessorFunction = (scale, scaleType, axisPosition) => {\n\t\t\treturn (d, i) => {\n\t\t\t\treturn cartesianScales.getValueFromScale(\n\t\t\t\t\tscale,\n\t\t\t\t\tscaleType,\n\t\t\t\t\taxisPosition,\n\t\t\t\t\td,\n\t\t\t\t\ti\n\t\t\t\t);\n\t\t\t};\n\t\t};\n\n\t\tconst xAccessor = accessorFunction(\n\t\t\tthis.xScale,\n\t\t\tmainXScaleType,\n\t\t\tmainXAxisPosition\n\t\t);\n\t\tconst yAccessor = accessorFunction(\n\t\t\tthis.yScale,\n\t\t\tmainYScaleType,\n\t\t\tmainYAxisPosition\n\t\t);\n\n\t\tconst zoombarType = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"zoomBar\",\n\t\t\t\"top\",\n\t\t\t\"type\"\n\t\t);\n\t\tconst zoombarHeight = Configuration.zoomBar.height[zoombarType];\n\t\tconst areaGenerator = area()\n\t\t\t.x((d, i) => xAccessor(d, i))\n\t\t\t.y0(zoombarHeight)\n\t\t\t.y1((d, i) => zoombarHeight - yAccessor(d, i));\n\n\t\tconst areaGraph = DOMUtils.appendOrSelect(container, querySelector)\n\t\t\t.datum(data)\n\t\t\t.attr(\"d\", areaGenerator);\n\n\t\tif (clipId) {\n\t\t\tareaGraph.attr(\"clip-path\", `url(#${clipId})`);\n\t\t}\n\t}\n\n\tupdateClipPath(svg, clipId, x, y, width, height) {\n\t\tconst zoomBarClipPath = DOMUtils.appendOrSelect(svg, `clipPath`).attr(\n\t\t\t\"id\",\n\t\t\tclipId\n\t\t);\n\t\tDOMUtils.appendOrSelect(zoomBarClipPath, \"rect\")\n\t\t\t.attr(\"x\", x)\n\t\t\t.attr(\"y\", y)\n\t\t\t.attr(\"width\", width)\n\t\t\t.attr(\"height\", height);\n\t}\n\n\t// assume the domains in data are already sorted\n\tcompensateDataForDefaultDomain(data, defaultDomain) {\n\t\tif (!data || data.length < 2) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst domainIdentifier = this.services.cartesianScales.getDomainIdentifier();\n\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\t// if min domain is extended\n\t\tif (Number(defaultDomain[0]) < Number(data[0][domainIdentifier])) {\n\t\t\tconst newDatum = {};\n\t\t\tnewDatum[domainIdentifier] = defaultDomain[0];\n\t\t\tnewDatum[rangeIdentifier] = 0;\n\t\t\tdata.unshift(newDatum);\n\t\t}\n\t\t// if max domain is extended\n\t\tif (\n\t\t\tNumber(defaultDomain[1]) >\n\t\t\tNumber(data[data.length - 1][domainIdentifier])\n\t\t) {\n\t\t\tconst newDatum = {};\n\t\t\tnewDatum[domainIdentifier] = defaultDomain[1];\n\t\t\tnewDatum[rangeIdentifier] = 0;\n\t\t\tdata.push(newDatum);\n\t\t}\n\t}\n\n\tdestroy() {\n\t\tthis.brush.on(\"start brush end\", null); // remove event listener\n\t\tthis.services.events.removeEventListener(\n\t\t\tEvents.ZoomBar.UPDATE,\n\t\t\tthis.render.bind(this)\n\t\t);\n\t}\n}\n"]}
@@ -13,5 +13,7 @@ export declare class Component {
13
13
  setServices(newObj: any): void;
14
14
  setParent(parent: any): void;
15
15
  getParent(): any;
16
- getContainerSVG(): any;
16
+ getContainerSVG(configs?: {
17
+ withinChartClip: boolean;
18
+ }): any;
17
19
  }
@@ -48,10 +48,19 @@ var Component = /** @class */ (function () {
48
48
  Component.prototype.getParent = function () {
49
49
  return this.parent;
50
50
  };
51
- Component.prototype.getContainerSVG = function () {
51
+ Component.prototype.getContainerSVG = function (configs) {
52
+ if (configs === void 0) { configs = { withinChartClip: false }; }
52
53
  if (this.type) {
53
54
  var chartprefix = Tools.getProperty(this.model.getOptions(), "style", "prefix");
54
- return DOMUtils.appendOrSelect(this.parent, "g." + settings.prefix + "--" + chartprefix + "--" + this.type);
55
+ var svg = DOMUtils.appendOrSelect(this.parent, "g." + settings.prefix + "--" + chartprefix + "--" + this.type);
56
+ if (configs.withinChartClip) {
57
+ // get unique chartClipId int this chart from model
58
+ var chartClipId = this.model.get("chartClipId");
59
+ if (chartClipId) {
60
+ svg.attr("clip-path", "url(#" + chartClipId + ")");
61
+ }
62
+ }
63
+ return svg;
55
64
  }
56
65
  return this.parent;
57
66
  };
@@ -1 +1 @@
1
- {"version":3,"file":"component.js","sourceRoot":"","sources":["component.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,yCAAyC;AACzC,OAAO,QAAQ,MAAM,0CAA0C,CAAC;AAEhE;IAUC,mBAAY,KAAiB,EAAE,QAAa,EAAE,OAAa;QALjD,YAAO,GAAQ,EAAE,CAAC;QAM3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,OAAO,EAAE;YACZ,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;SACvB;QAED,oEAAoE;QACpE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACjB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;SAC5D;IACF,CAAC;IAED,wBAAI,GAAJ,cAAQ,CAAC;IAET,0BAAM,GAAN,UAAO,OAAc;QAAd,wBAAA,EAAA,cAAc;QACpB,OAAO,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACrD,CAAC;IAED,2BAAO,GAAP,cAAW,CAAC;IAEZ,kDAAkD;IAClD,4BAAQ,GAAR,UAAS,MAAM;QACd,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;IACrB,CAAC;IAED,kDAAkD;IACl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{ DOMUtils } from \"../services\";\nimport { Tools } from \"../tools\";\n\n// D3 Imports\nimport { select } from \"d3-selection\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/es/globals/js/settings\";\n\nexport class Component {\n\tpublic type: string;\n\n\tprotected parent: any;\n\n\tprotected configs: any = {};\n\n\tprotected model: ChartModel;\n\tprotected services: any;\n\n\tconstructor(model: ChartModel, services: any, configs?: any) {\n\t\tthis.model = model;\n\t\tthis.services = services;\n\n\t\tif (configs) {\n\t\t\tthis.configs = configs;\n\t\t}\n\n\t\t// Set parent element to shell SVG if no parent exists for component\n\t\tif (!this.parent) {\n\t\t\tthis.setParent(select(this.services.domUtils.getMainSVG()));\n\t\t}\n\t}\n\n\tinit() {}\n\n\trender(animate = true) {\n\t\tconsole.error(\"render() method is not implemented\");\n\t}\n\n\tdestroy() {}\n\n\t// Used to pass down information to the components\n\tsetModel(newObj) {\n\t\tthis.model = newObj;\n\t}\n\n\t// Used to pass down information to the components\n\tsetServices(newObj) {\n\t\tthis.services = newObj;\n\t}\n\n\tsetParent(parent) {\n\t\tconst oldParent = this.parent;\n\t\tthis.parent = parent;\n\n\t\tif (oldParent && oldParent.node() === parent.node()) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.type) {\n\t\t\tconst chartprefix = Tools.getProperty(\n\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\"style\",\n\t\t\t\t\"prefix\"\n\t\t\t);\n\t\t\tthis.parent.classed(\n\t\t\t\t`${settings.prefix}--${chartprefix}--${this.type}`,\n\t\t\t\ttrue\n\t\t\t);\n\n\t\t\tif (oldParent) {\n\t\t\t\toldParent.classed(\n\t\t\t\t\t`${settings.prefix}--${chartprefix}--${this.type}`,\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tgetParent() {\n\t\treturn this.parent;\n\t}\n\n\tgetContainerSVG() {\n\t\tif (this.type) {\n\t\t\tconst chartprefix = Tools.getProperty(\n\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\"style\",\n\t\t\t\t\"prefix\"\n\t\t\t);\n\t\t\treturn DOMUtils.appendOrSelect(\n\t\t\t\tthis.parent,\n\t\t\t\t`g.${settings.prefix}--${chartprefix}--${this.type}`\n\t\t\t);\n\t\t}\n\n\t\treturn this.parent;\n\t}\n}\n"]}
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["component.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,yCAAyC;AACzC,OAAO,QAAQ,MAAM,0CAA0C,CAAC;AAEhE;IAUC,mBAAY,KAAiB,EAAE,QAAa,EAAE,OAAa;QALjD,YAAO,GAAQ,EAAE,CAAC;QAM3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,OAAO,EAAE;YACZ,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;SACvB;QAED,oEAAoE;QACpE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACjB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;SAC5D;IACF,CAAC;IAED,wBAAI,GAAJ,cAAQ,CAAC;IAET,0BAAM,GAAN,UAAO,OAAc;QAAd,wBAAA,EAAA,cAAc;QACpB,OAAO,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACrD,CAAC;IAED,2BAAO,GAAP,cAAW,CAAC;IAEZ,kDAAkD;IAClD,4BAAQ,GAAR,UAAS,MAAM;QACd,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;IACrB,CAAC;IAED,kDAAkD;IAClD,+BAAW,GAAX,UAAY,MAAM;QACjB,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AAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;gBAClD,IAAI,WAAW,EAAE;oBAChB,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,UAAQ,WAAW,MAAG,CAAC,CAAC;iBAC9C;aACD;YAED,OAAO,GAAG,CAAC;SACX;QAED,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IACF,gBAAC;AAAD,CAAC,AApGD,IAoGC","sourcesContent":["// Internal Imports\nimport { ChartModel } from \"../model\";\nimport { DOMUtils } from \"../services\";\nimport { Tools } from \"../tools\";\n\n// D3 Imports\nimport { select } from \"d3-selection\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/es/globals/js/settings\";\n\nexport class Component {\n\tpublic type: string;\n\n\tprotected parent: any;\n\n\tprotected configs: any = {};\n\n\tprotected model: ChartModel;\n\tprotected services: any;\n\n\tconstructor(model: ChartModel, services: any, configs?: any) {\n\t\tthis.model = model;\n\t\tthis.services = services;\n\n\t\tif (configs) {\n\t\t\tthis.configs = configs;\n\t\t}\n\n\t\t// Set parent element to shell SVG if no parent exists for component\n\t\tif (!this.parent) {\n\t\t\tthis.setParent(select(this.services.domUtils.getMainSVG()));\n\t\t}\n\t}\n\n\tinit() {}\n\n\trender(animate = true) {\n\t\tconsole.error(\"render() method is not implemented\");\n\t}\n\n\tdestroy() {}\n\n\t// Used to pass down information to the components\n\tsetModel(newObj) {\n\t\tthis.model = newObj;\n\t}\n\n\t// Used to pass down information to the components\n\tsetServices(newObj) {\n\t\tthis.services = newObj;\n\t}\n\n\tsetParent(parent) {\n\t\tconst oldParent = this.parent;\n\t\tthis.parent = parent;\n\n\t\tif (oldParent && oldParent.node() === parent.node()) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.type) {\n\t\t\tconst chartprefix = Tools.getProperty(\n\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\"style\",\n\t\t\t\t\"prefix\"\n\t\t\t);\n\t\t\tthis.parent.classed(\n\t\t\t\t`${settings.prefix}--${chartprefix}--${this.type}`,\n\t\t\t\ttrue\n\t\t\t);\n\n\t\t\tif (oldParent) {\n\t\t\t\toldParent.classed(\n\t\t\t\t\t`${settings.prefix}--${chartprefix}--${this.type}`,\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tgetParent() {\n\t\treturn this.parent;\n\t}\n\n\tgetContainerSVG(configs = { withinChartClip: false }) {\n\t\tif (this.type) {\n\t\t\tconst chartprefix = Tools.getProperty(\n\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\"style\",\n\t\t\t\t\"prefix\"\n\t\t\t);\n\n\t\t\tconst svg = DOMUtils.appendOrSelect(\n\t\t\t\tthis.parent,\n\t\t\t\t`g.${settings.prefix}--${chartprefix}--${this.type}`\n\t\t\t);\n\n\t\t\tif (configs.withinChartClip) {\n\t\t\t\t// get unique chartClipId int this chart from model\n\t\t\t\tconst chartClipId = this.model.get(\"chartClipId\");\n\t\t\t\tif (chartClipId) {\n\t\t\t\t\tsvg.attr(\"clip-path\", `url(#${chartClipId})`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn svg;\n\t\t}\n\n\t\treturn this.parent;\n\t}\n}\n"]}
@@ -2,6 +2,7 @@ import { Component } from "../component";
2
2
  export declare class Legend extends Component {
3
3
  type: string;
4
4
  render(): void;
5
+ sortDataGroups(dataGroups: any, legendOrder: any): any;
5
6
  breakItemsIntoLines(addedLegendItems: any): void;
6
7
  addEventListeners(): void;
7
8
  }
@@ -30,9 +30,14 @@ var Legend = /** @class */ (function (_super) {
30
30
  var svg = this.getContainerSVG().attr("role", Roles.GRAPHICS_DOCUMENT + " " + Roles.DOCUMENT);
31
31
  var options = this.model.getOptions();
32
32
  var legendOptions = Tools.getProperty(options, "legend");
33
+ var dataGroups = this.model.getDataGroups();
34
+ var legendOrder = Tools.getProperty(legendOptions, "order");
35
+ if (legendOrder) {
36
+ dataGroups = this.sortDataGroups(dataGroups, legendOrder);
37
+ }
33
38
  var legendItems = svg
34
39
  .selectAll("g.legend-item")
35
- .data(this.model.getDataGroups(), function (dataGroup) { return dataGroup.name; });
40
+ .data(dataGroups, function (dataGroup) { return dataGroup.name; });
36
41
  // this.getLegendItemArray()
37
42
  var addedLegendItems = legendItems
38
43
  .enter()
@@ -98,6 +103,19 @@ var Legend = /** @class */ (function (_super) {
98
103
  var alignmentOffset = DOMUtils.getAlignmentOffset(alignment, svg, this.getParent());
99
104
  svg.attr("transform", "translate(" + alignmentOffset + ", 0)");
100
105
  };
106
+ Legend.prototype.sortDataGroups = function (dataGroups, legendOrder) {
107
+ // Sort data in user defined order
108
+ dataGroups.sort(function (dataA, dataB) {
109
+ return legendOrder.indexOf(dataA.name) - legendOrder.indexOf(dataB.name);
110
+ });
111
+ // If user only defined partial ordering, ordered items are placed before unordered ones
112
+ if (legendOrder.length < dataGroups.length) {
113
+ var definedOrderIndex = dataGroups.length - legendOrder.length;
114
+ var definedOrder = dataGroups.slice(definedOrderIndex);
115
+ return definedOrder.concat(dataGroups.slice(0, definedOrderIndex));
116
+ }
117
+ return dataGroups;
118
+ };
101
119
  Legend.prototype.breakItemsIntoLines = function (addedLegendItems) {
102
120
  var self = this;
103
121
  var svg = this.getContainerSVG();