UNPKG

35 kBJavaScriptView Raw
1import { a as __extends } from './tslib.es6-863e3717.js';
2import { U as Utils, T as TooltipMeasureFormat } from './Utils-5f9f1f09.js';
3import { select, event, scaleLinear, extent, easeExp, mouse, axisLeft } from 'd3';
4import { L as Legend } from './Legend-1be9e8e0.js';
5import { C as ChartVisualizationComponent } from './ChartVisualizationComponent-84b467ae.js';
6import { C as ContextMenu } from './ContextMenu-4ba8fc74.js';
7import { T as Tooltip } from './Tooltip-4daae28d.js';
8import { G as GroupedBarChartData } from './GroupedBarChartData-4d21fe07.js';
9import { S as Slider } from './Slider-e28a6a90.js';
10
11var GroupedBarChart = /** @class */ (function (_super) {
12 __extends(GroupedBarChart, _super);
13 function GroupedBarChart(renderTarget) {
14 var _this = _super.call(this, renderTarget) || this;
15 _this.isStacked = null;
16 _this.stackedButton = null;
17 _this.chartComponentData = new GroupedBarChartData();
18 _this.chartMargins = {
19 top: 52,
20 bottom: 48,
21 left: 70,
22 right: 60
23 };
24 return _this;
25 }
26 GroupedBarChart.prototype.GroupedBarChart = function () { };
27 GroupedBarChart.prototype.render = function (data, options, aggregateExpressionOptions) {
28 var _this = this;
29 _super.prototype.render.call(this, data, options, aggregateExpressionOptions);
30 if (options && options.stacked || this.isStacked == null) {
31 this.isStacked = this.chartOptions.stacked;
32 }
33 this.chartMargins.top = (this.chartOptions.legend === 'compact') ? 84 : 52;
34 this.width = Math.max(select(this.renderTarget).node().clientWidth, this.MINWIDTH);
35 var height = Math.max(select(this.renderTarget).node().clientHeight, this.MINHEIGHT);
36 this.chartComponentData.mergeDataToDisplayStateAndTimeArrays(this.data, this.timestamp, this.aggregateExpressionOptions);
37 this.timestamp = (options && options.timestamp != undefined) ? options.timestamp : this.chartComponentData.allTimestampsArray[0];
38 var chartHeight = height - this.chartMargins.bottom - this.chartMargins.top;
39 this.chartWidth = this.getChartWidth();
40 if (this.svgSelection == null) {
41 var targetElement = select(this.renderTarget)
42 .classed("tsi-barChart", true);
43 var svgSelection = targetElement.append("svg")
44 .attr("class", "tsi-barChartSVG tsi-chartSVG")
45 .attr('title', this.getString('Bar chart'))
46 .style("height", height)
47 .style("width", this.getSVGWidth() + 'px');
48 this.svgSelection = svgSelection;
49 var g = svgSelection.append("g")
50 .attr("transform", "translate(" + this.chartMargins.left + "," + this.chartMargins.top + ")");
51 var baseLine = g.append("line")
52 .classed("tsi-baseLine", true)
53 .attr("stroke-width", 1);
54 var focus = g.append("g")
55 .attr("transform", "translate(-100,-100)")
56 .attr("class", "tsi-focus");
57 focus.append("line")
58 .attr("class", "tsi-focusLine")
59 .attr("x1", 0)
60 .attr("x2", this.chartWidth)
61 .attr("y1", 0)
62 .attr("y2", 0);
63 var vHoverG = focus.append("g")
64 .attr("class", 'vHoverG');
65 var vHoverBox = vHoverG.append("rect")
66 .attr("class", 'vHoverBox')
67 .attr("x", -5)
68 .attr("y", 0)
69 .attr("width", 0)
70 .attr("height", 0);
71 var vHoverText = vHoverG.append("text")
72 .attr("class", "vHoverText hoverText")
73 .attr("dy", ".32em")
74 .attr("x", -10)
75 .text(function (d) { return d; });
76 select(this.renderTarget).append('div').classed('tsi-sliderWrapper', true);
77 var tooltip = new Tooltip(select(this.renderTarget));
78 var measureMap = this.chartComponentData.data.map(function (aggregate, aggI) {
79 var aggName = Object.keys(aggregate)[0];
80 var aggKey = Utils.createEntityKey(Object.keys(aggregate)[0], aggI);
81 });
82 var labelMouseover = function (aggKey, splitBy) {
83 if (splitBy === void 0) { splitBy = null; }
84 var self = _this;
85 svgSelection.selectAll(".tsi-valueElement")
86 .attr("stroke-opacity", 1)
87 .attr("fill-opacity", 1);
88 //filter out the selected timeseries/splitby
89 var selectedFilter = function (d, j) {
90 var currAggKey;
91 var currSplitBy;
92 if (d.aggKey) {
93 currAggKey = d.aggKey;
94 currSplitBy = d.splitBy;
95 }
96 else if (d && d.length) {
97 currAggKey = d[0].aggKey;
98 currSplitBy = d[0].splitBy;
99 }
100 else
101 return true;
102 return !(aggKey == currAggKey && (splitBy == null || splitBy == currSplitBy));
103 };
104 svgSelection.selectAll(".tsi-valueElement")
105 .filter(selectedFilter)
106 .attr("stroke-opacity", .3)
107 .attr("fill-opacity", .3);
108 var text = svgSelection.selectAll(".barGroup")
109 .filter(function (d) {
110 return d == aggKey;
111 })
112 .select(".labelGroup").select("text").text(null);
113 var dy = parseFloat(text.attr("dy"));
114 var aggLabelGroup = text.append("tspan").attr('class', "tsi-labelGroupLine");
115 Utils.appendFormattedElementsFromString(aggLabelGroup, self.chartComponentData.displayState[aggKey].name, { inSvg: true, additionalClassName: "tsi-aggregateLabelGroupText" });
116 var splitByLabelGroup = text.append("tspan").attr('class', "tsi-labelGroupLine");
117 Utils.appendFormattedElementsFromString(splitByLabelGroup, splitBy, { inSvg: true, additionalClassName: "tsi-splitByLabelGroupText" });
118 splitByLabelGroup.selectAll('.tsi-splitByLabelGroupText').each(function (d, i) {
119 if (i == 0) {
120 select(this).attr("y", text.attr("y"))
121 .attr("x", text.attr("x"))
122 .attr("dy", (dy + dy * 2) + "em")
123 .attr("text-anchor", "middle");
124 }
125 });
126 rePositionLabelGroupBoxes(svgSelection, aggKey);
127 };
128 var labelMouseout = function (svgSelection, aggKey) {
129 var self = _this;
130 var allText = svgSelection.selectAll(".barGroup")
131 .selectAll(".labelGroup")
132 .selectAll("text")
133 .text(null);
134 allText.each(function (aggKey) {
135 var text = select(this);
136 if (self.chartComponentData.displayState[aggKey] != undefined) {
137 Utils.appendFormattedElementsFromString(text, self.chartComponentData.displayState[aggKey].name, { inSvg: true, additionalClassName: "tsi-aggregateLabelGroupText" });
138 }
139 });
140 rePositionLabelGroupBoxes(svgSelection);
141 };
142 var calcSpacePerAgg = function () {
143 var aggregateCount = Math.max(Object.keys(_this.chartComponentData.filteredAggregates).length, 1);
144 return Math.max((_this.chartWidth / 2) / aggregateCount, 0);
145 };
146 var rePositionLabelGroupBoxes = function (svgSelection, aggKey) {
147 if (aggKey === void 0) { aggKey = null; }
148 svgSelection.selectAll(".barGroup").filter(function (d, i) {
149 if (aggKey == null)
150 return true;
151 return d == aggKey;
152 })
153 .each(function () {
154 if (select(this).select('.labelGroup').select('text').node() == null)
155 return;
156 var textElemDimensions = select(this).select('.labelGroup').select('text').node()
157 .getBoundingClientRect();
158 var spacePerAgg = calcSpacePerAgg();
159 var aggregateWidth = select(this).attr("width");
160 // //truncate text to fit in spacePerAggregate of width
161 var textSelection = select(this).select('.labelGroup').select("text");
162 var truncateText = function (textSelection, childrenSize) {
163 if (childrenSize === void 0) { childrenSize = 1; }
164 if (textSelection.node().getComputedTextLength) {
165 var textLength = textSelection.node().getComputedTextLength();
166 var text = textSelection.text();
167 while (textLength > ((spacePerAgg - 6) / childrenSize) && text.length > 0) {
168 text = text.slice(0, -1);
169 textSelection.text(text + '...');
170 textLength = textSelection.node().getComputedTextLength();
171 }
172 }
173 };
174 //text is either in tspans or just in text. Either truncate text directly or through tspan
175 if (textSelection.selectAll("tspan").filter(function () { return !select(this).classed("tsi-labelGroupLine"); }).size() === 0)
176 truncateText(textSelection);
177 else {
178 textSelection.selectAll("tspan").filter(function () { return !select(this).classed("tsi-labelGroupLine"); }).each(function () {
179 var tspanTextSelection = select(this);
180 var childrenSize = tspanTextSelection.classed("tsi-splitByLabelGroupText") ? textSelection.selectAll(".tsi-splitByLabelGroupText").size() : textSelection.selectAll(".tsi-aggregateLabelGroupText").size();
181 truncateText(tspanTextSelection, childrenSize);
182 });
183 }
184 select(this).select('.labelGroup').select("rect")
185 .attr("height", textElemDimensions.height + 4)
186 .attr("y", chartHeight + 6)
187 .attr("x", 0)
188 .attr("width", spacePerAgg);
189 });
190 };
191 var draw = function (isFromResize) {
192 if (isFromResize === void 0) { isFromResize = false; }
193 var self = _this;
194 _this.width = _this.getWidth();
195 height = Math.max(select(_this.renderTarget).node().clientHeight, _this.MINHEIGHT);
196 _this.chartComponentData.timestamp = (_this.chartOptions.timestamp != undefined) ? _this.chartOptions.timestamp : _this.chartComponentData.allTimestampsArray[0];
197 _this.chartComponentData.setFilteredAggregates();
198 if (!isFromResize) {
199 _this.chartWidth = _this.getChartWidth();
200 }
201 _super.prototype.themify.call(_this, targetElement, _this.chartOptions.theme);
202 if (!_this.chartOptions.hideChartControlPanel && _this.chartControlsPanel === null) {
203 _this.chartControlsPanel = Utils.createControlPanel(_this.renderTarget, _this.CONTROLSWIDTH, _this.chartMargins.top, _this.chartOptions);
204 _this.stackedButton = _this.chartControlsPanel.append("button")
205 .style("left", "60px")
206 .attr("class", "tsi-stackedButton").on("click", function () {
207 self.chartOptions.stacked = !self.chartOptions.stacked;
208 self.draw();
209 })
210 .attr("type", "button")
211 .attr('title', _this.getString('Stack/Unstack Bars'));
212 }
213 else if (_this.chartOptions.hideChartControlPanel && _this.chartControlsPanel !== null) {
214 _this.removeControlPanel();
215 }
216 if (_this.chartControlsPanel) {
217 _this.stackedButton.attr('aria-label', _this.chartOptions.stacked ? _this.getString("Unstack bars") : _this.getString("Stack bars"));
218 }
219 if (_this.chartControlsPanel !== null && _this.ellipsisItemsExist()) {
220 _this.drawEllipsisMenu();
221 _this.chartControlsPanel.style("top", Math.max((_this.chartMargins.top - 24), 0) + 'px');
222 }
223 else {
224 _this.removeEllipsisMenu();
225 }
226 /********* Determine the number of timestamps present, add margin for slider *********/
227 if (_this.chartComponentData.allTimestampsArray.length > 1)
228 _this.chartMargins.bottom = 88;
229 /*******************/
230 chartHeight = height - _this.chartMargins.bottom - _this.chartMargins.top;
231 focus.select("line").attr("x2", _this.chartWidth);
232 svgSelection.style("width", _this.getSVGWidth() + "px");
233 if (_this.timestamp.substring(_this.timestamp.length - 5, _this.timestamp.length) == ".000Z")
234 _this.timestamp = _this.timestamp.substring(0, _this.timestamp.length - 5) + "Z";
235 var aggregateCount = Math.max(Object.keys(_this.chartComponentData.filteredAggregates).length, 1);
236 svgSelection.select('g').attr("transform", "translate(" + _this.chartMargins.left + "," + _this.chartMargins.top + ")")
237 .selectAll('.barGroup')
238 .attr("visibility", "hidden");
239 var barGroups = g.selectAll('.barGroup').data(Object.keys(_this.chartComponentData.displayState));
240 var spacePerAggregate = calcSpacePerAgg();
241 //map to x position
242 var xPosMap = _this.chartComponentData.filteredAggregates.reduce(function (map, aggKey, aggKeyI) {
243 map[aggKey] = ((1 / (aggregateCount + 1)) * (aggKeyI + 1) * _this.chartWidth - (spacePerAggregate / 2));
244 return map;
245 }, {});
246 _this.legendObject.draw(_this.chartOptions.legend, _this.chartComponentData, labelMouseover, svgSelection, _this.chartOptions, labelMouseout);
247 barGroups = barGroups.enter()
248 .append("g")
249 .attr("class", "barGroup")
250 .merge(barGroups)
251 .attr("display", function (d, i) { return (_this.chartComponentData.displayState[d].visible ? "inherit" : "none"); })
252 .attr("visibility", "visible")
253 .attr("transform", function (d, i) {
254 if (xPosMap[d])
255 return "translate(" + xPosMap[d] + ",0)";
256 return "";
257 });
258 _this.chartComponentData.setEntireRangeData(_this.chartOptions.scaledToCurrentTime);
259 var allValues = _this.chartComponentData.valuesOfVisibleType;
260 var aggsSeries = _this.chartComponentData.aggsSeries;
261 var yScale = scaleLinear()
262 .range([chartHeight, 0]);
263 var extent$1 = extent(allValues);
264 if (!_this.chartOptions.stacked) {
265 if (allValues.length > 0) { //check to make sure there are values present
266 if (_this.chartOptions.zeroYAxis) {
267 if (extent$1[0] > 0)
268 yScale.domain([0, extent(allValues)[1]]);
269 else
270 yScale.domain([extent(allValues)[0], Math.max(extent(allValues)[1], 0)]);
271 }
272 else {
273 var offset = (Math.abs(extent(allValues)[1]) * .05);
274 yScale.domain([extent(allValues)[0] - offset, (extent(allValues)[1] + offset)]);
275 }
276 }
277 else {
278 yScale.domain([0, 0]);
279 }
280 }
281 else {
282 yScale.domain([Math.min(_this.chartComponentData.globalMin, _this.chartComponentData.globalMax),
283 Math.max(_this.chartComponentData.globalMin, _this.chartComponentData.globalMax)]);
284 }
285 var barBase = (yScale.domain()[0] > 0) ? yScale(yScale.domain()[0]) : yScale(0);
286 var legendObject = _this.legendObject;
287 barGroups.each(function (aggKey, i) {
288 var splitBys = Object.keys(self.chartComponentData.displayState[aggKey].splitBys);
289 var filteredSplitBys = splitBys.filter(function (splitBy) {
290 return self.chartComponentData.displayState[aggKey].splitBys[splitBy].visible;
291 });
292 var splitByCount = filteredSplitBys.length;
293 var barWidth = spacePerAggregate / splitByCount;
294 var valueElements = select(this).selectAll('.tsi-valueElement').data(self.chartComponentData.getValueContainerData(aggKey));
295 var labelGroup = select(this).selectAll(".labelGroup").data([aggKey]);
296 var labelGroupEntered = labelGroup.enter()
297 .append("g")
298 .attr("class", "labelGroup");
299 labelGroupEntered.append("rect");
300 var labelGroupText = labelGroupEntered.append("text")
301 .attr("dy", ".71em");
302 Utils.appendFormattedElementsFromString(labelGroupText, self.chartComponentData.displayState[aggKey].name, { inSvg: true, additionalClassName: "tsi-aggregateLabelGroupText" });
303 var labelGroupBox = labelGroupEntered.merge(labelGroup)
304 .select("rect")
305 .attr("class", 'aggregateLabelBox')
306 .attr("x", 0)
307 .attr("y", 1)
308 .attr("width", 0)
309 .attr("height", 0);
310 select(this).select(".labelGroup").select("text")
311 .transition()
312 .duration(self.TRANSDURATION)
313 .ease(easeExp)
314 .attr("x", function (d) { return (spacePerAggregate / 2); })
315 .attr("y", chartHeight + 12)
316 .style("fill", function (d) { return self.chartComponentData.displayState[aggKey].color; })
317 .attr("text-anchor", "middle");
318 labelGroup.exit().remove();
319 rePositionLabelGroupBoxes(svgSelection, aggKey);
320 var xScale = scaleLinear()
321 .domain([0, splitByCount])
322 .range([0, spacePerAggregate]);
323 //yOffset to position 0 at the appropriate place
324 var yOffset = chartHeight - filteredSplitBys.reduce(function (offset, splitBy) {
325 var measureType = self.chartComponentData.displayState[aggKey].splitBys[splitBy].visibleType;
326 var yScaledVal; // either 0 or the value
327 if (self.chartComponentData.valuesAtTimestamp[aggKey].splitBys[splitBy].measurements)
328 yScaledVal = yScale(self.chartComponentData.valuesAtTimestamp[aggKey].splitBys[splitBy].measurements[measureType]);
329 else
330 yScaledVal = 0;
331 return offset + yScaledVal;
332 }, 0);
333 //calculate the yPosition of an element, either by its data or explicitly through its value
334 var calcYPos = function (d, i) {
335 if (!self.chartOptions.stacked) {
336 if (d.val > 0)
337 return yScale(d.val);
338 return yScale(0);
339 }
340 if (aggsSeries[d.aggKey] != undefined && aggsSeries[d.aggKey].length != 0) {
341 return yScale(aggsSeries[d.aggKey][i][0][1]);
342 }
343 return 0;
344 };
345 //calculate the height of an element given its data
346 var calcHeight = function (d, i, dValue) {
347 if (dValue === void 0) { dValue = null; }
348 if (!self.chartOptions.stacked) {
349 if (yScale.domain()[0] >= 0)
350 return chartHeight - calcYPos(d, i);
351 dValue = (dValue != null) ? dValue : d.val;
352 if (dValue > 0)
353 return Math.abs(calcYPos(d, i) - yScale(0));
354 return yScale(dValue) - yScale(0);
355 }
356 return Math.max(Math.abs(yScale(d.val) - yScale(0)), 0);
357 };
358 //map to x position for grouped, map to y position for stacked
359 var splitByXPosMap = filteredSplitBys.reduce(function (map, splitBy, splitByI) {
360 map[splitBy] = xScale(splitByI);
361 return map;
362 }, {});
363 var valueElementsEntered = valueElements.enter()
364 .append("g")
365 .attr("class", "tsi-valueElement");
366 valueElementsEntered.append("rect");
367 valueElementsEntered.append("line");
368 var valueElementMouseout = function (d, j) {
369 if (self.contextMenu && self.contextMenu.contextMenuVisible)
370 return;
371 focus.style("display", "none");
372 legendObject.legendElement.selectAll('.tsi-splitByLabel').filter(function (filteredSplitBy) {
373 return (select(this.parentNode).datum() == d.aggKey) && (filteredSplitBy == d.splitBy);
374 }).classed("inFocus", false);
375 event.stopPropagation();
376 svgSelection.selectAll(".tsi-valueElement")
377 .attr("stroke-opacity", 1)
378 .attr("fill-opacity", 1);
379 labelMouseout(svgSelection, d.aggKey);
380 tooltip.hide();
381 };
382 var mouseOutValueElementOnContextMenuClick = function () {
383 valueElementsEntered.selectAll("path").each(valueElementMouseout);
384 };
385 var splitByColors = Utils.createSplitByColors(self.chartComponentData.displayState, aggKey, self.chartOptions.keepSplitByColor);
386 valueElementsEntered.merge(valueElements)
387 .select("rect")
388 .attr("fill", function (d, j) {
389 return splitByColors[j];
390 })
391 .on("mouseover", function (d, j) {
392 if (self.contextMenu && self.contextMenu.contextMenuVisible)
393 return;
394 (legendObject.legendElement.selectAll('.tsi-splitByLabel').filter(function (filteredSplitBy) {
395 return (select(this.parentNode).datum() == d.aggKey) && (filteredSplitBy == d.splitBy);
396 })).classed("inFocus", true);
397 labelMouseover(d.aggKey, d.splitBy);
398 var yPos = calcYPos(d, j);
399 if (d.val < 0) {
400 yPos = yPos + calcHeight(d, j);
401 }
402 focus.style("display", "block")
403 .attr("transform", "translate(0," + yPos + ")");
404 focus.select('.vHoverG')
405 .select("text")
406 .text(function () {
407 if (!self.chartOptions.stacked)
408 return Utils.formatYAxisNumber(d.val);
409 var yVal = yScale.invert(calcYPos(d, j));
410 if (d.val < 0)
411 yVal += d.val;
412 return Utils.formatYAxisNumber(yVal);
413 });
414 var textElemDimensions = focus.select('.vHoverG').select("text")
415 .node().getBoundingClientRect();
416 focus.select(".vHoverG").select("rect")
417 .attr("x", -(textElemDimensions.width) - 13)
418 .attr("y", -(textElemDimensions.height / 2) - 3)
419 .attr("width", textElemDimensions.width + 6)
420 .attr("height", textElemDimensions.height + 4);
421 focus.node().parentNode.appendChild(focus.node());
422 })
423 .on("mousemove", function (d, i) {
424 if (self.chartOptions.tooltip) {
425 var mousePos = mouse(g.node());
426 tooltip.render(self.chartOptions.theme);
427 tooltip.draw(d, self.chartComponentData, mousePos[0], mousePos[1], self.chartMargins, function (text) {
428 self.tooltipFormat(self.convertToTimeValueFormat(d), text, TooltipMeasureFormat.SingleValue);
429 }, null, 20, 20, splitByColors[i]);
430 }
431 else {
432 tooltip.hide();
433 }
434 })
435 .on("mouseout", valueElementMouseout)
436 .on("contextmenu", function (d, i) {
437 if (self.chartComponentData.displayState[d.aggKey].contextMenuActions &&
438 self.chartComponentData.displayState[d.aggKey].contextMenuActions.length) {
439 var mousePosition = mouse(targetElement.node());
440 event.preventDefault();
441 self.contextMenu.draw(self.chartComponentData, self.renderTarget, self.chartOptions, mousePosition, d.aggKey, d.splitBy, mouseOutValueElementOnContextMenuClick, new Date(self.chartComponentData.timestamp));
442 }
443 })
444 .transition()
445 .duration(self.TRANSDURATION)
446 .ease(easeExp)
447 .attr("y", function (d, i) { return calcYPos(d, i); })
448 .attr("height", function (d, i) {
449 if (self.chartOptions.stacked && (splitByXPosMap[d.splitBy] == undefined))
450 return 0;
451 return Math.max(calcHeight(d, i), 0);
452 })
453 .attr("x", function (d, i) {
454 if (self.chartOptions.stacked)
455 return 0;
456 if (splitByXPosMap[d.splitBy] != undefined)
457 return splitByXPosMap[d.splitBy];
458 //if invisible, put it in the empty space where it would be
459 var splitBys = Object.keys(self.chartComponentData.displayState[aggKey].splitBys);
460 var prevSplitBy = splitBys[0];
461 for (var splitByI = 0; splitBys[splitByI] != d.splitBy; splitByI++) {
462 if (splitByXPosMap[splitBys[splitByI]] != undefined)
463 prevSplitBy = splitBys[splitByI];
464 }
465 if (splitByXPosMap[prevSplitBy] != undefined)
466 return splitByXPosMap[prevSplitBy] + barWidth;
467 return 0;
468 })
469 .attr("width", function (d, i) {
470 if (self.chartOptions.stacked)
471 return spacePerAggregate;
472 if (splitByXPosMap[d.splitBy] != undefined)
473 return barWidth;
474 return 0;
475 });
476 valueElementsEntered.merge(valueElements)
477 .select("line")
478 .classed("tsi-baseLine", true)
479 .attr("stroke-width", 2)
480 .transition()
481 .duration(self.TRANSDURATION)
482 .ease(easeExp)
483 .attr("x1", function (d, i) {
484 if (self.chartOptions.stacked)
485 return 0;
486 if (splitByXPosMap[d.splitBy] != undefined)
487 return splitByXPosMap[d.splitBy];
488 return 0;
489 })
490 .attr("x2", function (d, i) {
491 if (self.chartOptions.stacked)
492 return spacePerAggregate;
493 if (splitByXPosMap[d.splitBy] != undefined)
494 return splitByXPosMap[d.splitBy] + barWidth;
495 return 0;
496 })
497 .attr("y1", function (d, i) {
498 if (!self.chartOptions.stacked) {
499 return barBase;
500 }
501 var dValue = d.val;
502 if (self.chartOptions.stacked && (splitByXPosMap[d.splitBy] == undefined))
503 return calcYPos(d, i);
504 return calcYPos(d, i) + calcHeight(d, i);
505 })
506 .attr("y2", function (d, i) {
507 if (!self.chartOptions.stacked) {
508 return barBase;
509 }
510 var dValue = d.val;
511 if (self.chartOptions.stacked && (splitByXPosMap[d.splitBy] == undefined))
512 return calcYPos(d, i);
513 return calcYPos(d, i) + calcHeight(d, i);
514 });
515 valueElements.exit().remove();
516 });
517 barGroups.exit().remove();
518 var yAxis = g.selectAll(".yAxis")
519 .data([yScale]);
520 yAxis.enter()
521 .append("g")
522 .attr("class", "yAxis")
523 .merge(yAxis)
524 .call(axisLeft(yScale).tickFormat(Utils.formatYAxisNumber).ticks(4));
525 yAxis.exit().remove();
526 baseLine
527 .attr("x1", 0)
528 .attr("x2", _this.chartWidth)
529 .attr("y1", barBase + 1)
530 .attr("y2", barBase + 1);
531 /******************** Stack/Unstack button ************************/
532 _this.stackedButton.style("opacity", _this.chartOptions.stacked ? 1 : .5)
533 .classed('tsi-lightTheme', _this.chartOptions.theme == 'light')
534 .classed('tsi-darkTheme', _this.chartOptions.theme == 'dark');
535 /******************** Temporal Slider ************************/
536 if (_this.chartComponentData.allTimestampsArray.length > 1) {
537 select(_this.renderTarget).select('.tsi-sliderWrapper').classed('tsi-hidden', false);
538 slider.render(_this.chartComponentData.allTimestampsArray.map(function (ts) {
539 var action = function () {
540 _this.chartOptions.timestamp = ts;
541 _this.render(_this.chartComponentData.data, _this.chartOptions, _this.aggregateExpressionOptions);
542 };
543 return { label: Utils.timeFormat(_this.chartComponentData.usesSeconds, _this.chartComponentData.usesMillis, _this.chartOptions.offset, _this.chartOptions.is24HourTime, null, null, _this.chartOptions.dateLocale)(new Date(ts)), action: action };
544 }), _this.chartOptions, _this.getSVGWidth(), Utils.timeFormat(_this.chartComponentData.usesSeconds, _this.chartComponentData.usesMillis, _this.chartOptions.offset, _this.chartOptions.is24HourTime, null, null, _this.chartOptions.dateLocale)(new Date(_this.chartComponentData.timestamp)));
545 }
546 else {
547 slider.remove();
548 select(_this.renderTarget).select('.tsi-sliderWrapper').classed('tsi-hidden', true);
549 }
550 _this.setControlsPanelWidth();
551 };
552 this.legendObject = new Legend(draw, this.renderTarget, this.CONTROLSWIDTH);
553 this.contextMenu = new ContextMenu(this.draw, this.renderTarget);
554 // temporal slider
555 var slider = new Slider(select(this.renderTarget).select('.tsi-sliderWrapper').node());
556 this.draw = draw;
557 window.addEventListener("resize", function () {
558 if (!_this.chartOptions.suppressResizeListener)
559 _this.draw();
560 });
561 }
562 select("html").on("click." + Utils.guid(), function () {
563 if (_this.ellipsisContainer && event.target != _this.ellipsisContainer.select(".tsi-ellipsisButton").node()) {
564 _this.ellipsisMenu.setMenuVisibility(false);
565 }
566 });
567 this.chartComponentData.mergeDataToDisplayStateAndTimeArrays(this.data, this.timestamp, this.aggregateExpressionOptions);
568 this.draw();
569 this.gatedShowGrid();
570 this.legendPostRenderProcess(this.chartOptions.legend, this.svgSelection, true);
571 };
572 return GroupedBarChart;
573}(ChartVisualizationComponent));
574
575export { GroupedBarChart as G };