UNPKG

29.2 kBJavaScriptView Raw
1import { a as __extends, _ as __assign } from './tslib.es6-863e3717.js';
2import { U as Utils } from './Utils-5f9f1f09.js';
3import { mouse, extent, select, scaleSequential, interpolateViridis, scaleLinear, hcl, scaleTime } from 'd3';
4import { L as Legend } from './Legend-1be9e8e0.js';
5import { E as EllipsisMenu } from './EllipsisMenu-8802ae90.js';
6import { C as ChartComponent } from './ChartComponent-63d99ac0.js';
7import { T as TemporalXAxisComponent } from './TemporalXAxisComponent-daca2af1.js';
8
9var HeatmapData = /** @class */ (function () {
10 function HeatmapData(chartComponentData, aggKey) {
11 var _this = this;
12 this.visibleSBs = [];
13 this.timeStamps = [];
14 this.numRows = 0;
15 this.numCols = 0;
16 this.aggKey = aggKey;
17 this.chartComponentData = chartComponentData;
18 this.chartComponentData.isFromHeatmap = true;
19 this.visibleSBs = Object.keys(this.chartComponentData.displayState[aggKey].splitBys).filter(function (sb) {
20 return (_this.chartComponentData.getSplitByVisible(aggKey, sb));
21 });
22 this.numRows = this.visibleSBs.length;
23 this.from = new Date(chartComponentData.displayState[aggKey].aggregateExpression.searchSpan.from);
24 this.to = new Date(chartComponentData.displayState[aggKey].aggregateExpression.searchSpan.to);
25 this.bucketSize = Utils.parseTimeInput(chartComponentData.displayState[aggKey].aggregateExpression.searchSpan.bucketSize);
26 this.createTimeValues();
27 }
28 HeatmapData.prototype.adjustStartTime = function () {
29 return new Date(Utils.adjustStartMillisToAbsoluteZero(new Date(this.from).valueOf(), this.bucketSize));
30 };
31 HeatmapData.prototype.createTimeValues = function () {
32 var _this = this;
33 this.timeValues = {};
34 this.allValues = [];
35 //turn time array into an object keyed by timestamp
36 var colI = 0;
37 var adjustedStartTime = this.adjustStartTime();
38 for (var currTime = adjustedStartTime; (currTime.valueOf() < this.to.valueOf()); currTime = new Date(currTime.valueOf() + this.bucketSize)) {
39 this.timeValues[currTime.toISOString()] = this.visibleSBs.reduce(function (obj, splitBy, splitByI) {
40 obj[splitBy] = {
41 colI: colI,
42 rowI: splitByI,
43 value: null
44 };
45 return obj;
46 }, {});
47 colI += 1;
48 }
49 this.numCols = Object.keys(this.timeValues).length;
50 this.visibleSBs.forEach(function (splitBy, rowI) {
51 _this.chartComponentData.timeArrays[_this.aggKey][splitBy].forEach(function (valueObject, colI) {
52 var timestamp = new Date(valueObject.dateTime.valueOf()).toISOString();
53 var visibleMeasure = _this.chartComponentData.getVisibleMeasure(_this.aggKey, splitBy);
54 if (_this.timeValues[timestamp]) {
55 _this.timeValues[timestamp][splitBy].value = valueObject.measures ? valueObject.measures[visibleMeasure] : null;
56 if (Utils.safeNotNullOrUndefined(function () { return valueObject.measures[visibleMeasure]; }))
57 _this.allValues.push(valueObject.measures[visibleMeasure]);
58 }
59 });
60 });
61 };
62 return HeatmapData;
63}());
64
65var HeatmapCanvas = /** @class */ (function (_super) {
66 __extends(HeatmapCanvas, _super);
67 function HeatmapCanvas(renderTarget) {
68 var _this = _super.call(this, renderTarget) || this;
69 _this.gradientWidth = 8;
70 _this.focusedXIndex = -1;
71 _this.focusedYIndex = -1;
72 _this.legendWidth = 80;
73 return _this;
74 }
75 HeatmapCanvas.prototype.renderScale = function () {
76 var _this = this;
77 this.colorLegend.selectAll("*").remove();
78 if (this.colorScale.domain() === null || isNaN(this.colorScale.domain()[0]) || isNaN(this.colorScale.domain()[1])) {
79 return;
80 }
81 var gradientGuid = Utils.guid();
82 var gradient = this.colorLegend.append("defs")
83 .append("linearGradient")
84 .attr("id", "gradient" + this.aggI + gradientGuid)
85 .attr("x1", "0%")
86 .attr("y1", "100%")
87 .attr("x2", "0%")
88 .attr("y2", "0%");
89 var percentileCalc = function (i) { return i * (_this.colorScale.domain()[1] - _this.colorScale.domain()[0]) + _this.colorScale.domain()[0]; };
90 for (var i = 0; i <= 20; i++) {
91 var interpolatedColor = this.colorScale(percentileCalc(i / 20));
92 gradient.append("stop")
93 .attr("offset", (i * 5) + "%")
94 .attr("stop-color", interpolatedColor)
95 .attr("stop-opacity", 1);
96 }
97 var gradientRect = this.colorLegend.append("rect")
98 .attr("x", this.legendWidth - this.gradientWidth)
99 .attr("y", 6)
100 .attr("width", this.gradientWidth)
101 .attr("height", Math.max(0, this.height - 12))
102 .style("fill", "url(#gradient" + String(this.aggI) + gradientGuid + ")");
103 var highlightedValueY = null;
104 var range = this.colorScale.domain()[1] - this.colorScale.domain()[0];
105 var highlightedText = this.colorLegend.append("text").attr("class", "highlightedValueText");
106 var highlightedLine = this.colorLegend.append("line").attr("class", "highlightedValueLine");
107 var minText = this.colorLegend.append("text");
108 var maxText = this.colorLegend.append("text");
109 var setHighlightedValueLineAndText = function (line, text) {
110 var percentile;
111 if (range == 0) {
112 percentile = .5;
113 }
114 else {
115 percentile = (_this.highlightedValue != null) ? (_this.highlightedValue - _this.colorScale.domain()[0]) / range : 0;
116 }
117 highlightedValueY = (_this.height - 6) + (12 - _this.height) * percentile;
118 text.attr("x", _this.legendWidth - _this.gradientWidth - 10)
119 .attr("y", highlightedValueY)
120 .style("stroke-width", 2)
121 .text(Utils.formatYAxisNumber(_this.highlightedValue));
122 line.attr("x1", _this.legendWidth - _this.gradientWidth - 5)
123 .attr("x2", _this.legendWidth)
124 .attr("y1", highlightedValueY)
125 .attr("y2", highlightedValueY)
126 .style("stroke-width", 2);
127 minText.attr("fill-opacity", ((highlightedValueY == null) || highlightedValueY < _this.height - 18) ? 1 : 0);
128 maxText.attr("fill-opacity", ((highlightedValueY == null) || highlightedValueY > 18) ? 1 : 0);
129 };
130 minText.attr("x", this.legendWidth - this.gradientWidth - 5)
131 .attr("y", this.height - 6)
132 .text(Utils.formatYAxisNumber(this.colorScale.domain()[0]))
133 .attr("fill-width", ((highlightedValueY == null) || highlightedValueY < this.height - 18) ? 1 : 0);
134 maxText.attr("x", this.legendWidth - this.gradientWidth - 5)
135 .attr("y", 6)
136 .text(Utils.formatYAxisNumber(this.colorScale.domain()[1]))
137 .attr("fill-opacity", ((highlightedValueY == null) || highlightedValueY > 18) ? 1 : 0);
138 //render highlightedValue text and line IF there is a highlighted time and split by, OR IF there is an
139 // artificially produced value from hovering over the color gradient
140 if (this.highlightedTime && this.highlightedSplitBy != null && this.highlightedValue != null) {
141 setHighlightedValueLineAndText(highlightedLine, highlightedText);
142 minText.attr("fill-opacity", ((highlightedValueY == null) || highlightedValueY < this.height - 18) ? 1 : 0);
143 maxText.attr("fill-opacity", ((highlightedValueY == null) || highlightedValueY > 18) ? 1 : 0);
144 }
145 var self = this;
146 gradientRect.on("mousemove", function () {
147 var yPos = mouse(this)[1];
148 var percentile = 1 - ((yPos - 6) / (self.height - 12));
149 self.highlightedValue = self.colorScale.domain()[0] + (range * percentile);
150 setHighlightedValueLineAndText(highlightedLine, highlightedText);
151 })
152 .on("mouseleave", function () {
153 _this.render(_this.data, _this.chartOptions, _this.aggKey, null, null, _this.onCellFocus, null, _this.isOnlyAgg);
154 });
155 };
156 HeatmapCanvas.prototype.getExtent = function () {
157 var rawExtent = extent(this.heatmapData.allValues);
158 var extent$1 = rawExtent;
159 if (rawExtent[0] === rawExtent[1]) {
160 extent$1 = [rawExtent[0] - .05, rawExtent[1] + .05];
161 }
162 return extent$1;
163 };
164 HeatmapCanvas.prototype.render = function (data, chartOptions, aggKey, highlightedSplitBy, highlightedTime, onCellFocus, aggI, isOnlyAgg) {
165 var _this = this;
166 if (highlightedSplitBy === void 0) { highlightedSplitBy = null; }
167 if (highlightedTime === void 0) { highlightedTime = null; }
168 this.chartOptions.setOptions(chartOptions);
169 this.aggKey = aggKey;
170 this.data = data;
171 this.isOnlyAgg = isOnlyAgg;
172 if (aggI != null) {
173 this.aggI = aggI;
174 }
175 this.heatmapData = new HeatmapData(data, aggKey);
176 var container = select(this.renderTarget).classed("tsi-heatmapCanvasWrapper", true);
177 _super.prototype.themify.call(this, container, this.chartOptions.theme);
178 if (highlightedSplitBy != null)
179 this.highlightedSplitBy = highlightedSplitBy;
180 this.highlightedTime = highlightedTime;
181 if (this.highlightedSplitBy != null && this.highlightedTime) {
182 if (this.heatmapData.timeValues[this.highlightedTime.toISOString()][this.highlightedSplitBy] != null) {
183 this.highlightedValue = this.heatmapData.timeValues[this.highlightedTime.toISOString()][this.highlightedSplitBy].value;
184 }
185 }
186 if (onCellFocus)
187 this.onCellFocus = onCellFocus;
188 if (!container.select("canvas").empty())
189 this.canvas = container.select("canvas");
190 else
191 this.canvas = container.append("canvas").attr("class", "tsi-heatmapCanvas");
192 this.width = Math.floor(container.node().getBoundingClientRect().width - this.legendWidth - 10);
193 this.height = Math.floor(container.node().getBoundingClientRect().height);
194 this.canvas.attr("width", this.width);
195 this.canvas.attr("height", this.height);
196 this.ctx = this.canvas.node().getContext("2d");
197 this.ctx.clearRect(0, 0, this.width, this.height);
198 container.selectAll("svg").remove();
199 var self = this;
200 this.canvas.on("mousemove", function () {
201 var mouseCoords = mouse(this);
202 var indexesChanged = false;
203 var newXIndex = self.calcCellXIndex(mouseCoords[0]);
204 var newYIndex = self.calcCellYIndex(mouseCoords[1]);
205 var visibleSplitBys = Object.keys(self.data.displayState[aggKey].splitBys).filter(function (splitBy) {
206 return self.data.isSplitByVisible(self.aggKey, splitBy);
207 });
208 if (newXIndex != self.focusedXIndex) {
209 self.focusedXIndex = newXIndex;
210 indexesChanged = true;
211 }
212 if (newYIndex != self.focusedYIndex) {
213 self.focusedYIndex = newYIndex;
214 indexesChanged = true;
215 }
216 var highlightedSplitBy = visibleSplitBys[self.focusedYIndex];
217 if (indexesChanged && self.focusedXIndex >= 0 && self.focusedYIndex >= 0) {
218 var cellX = self.calcCellX(self.focusedXIndex);
219 var sortedDates = Object.keys(self.heatmapData.timeValues)
220 .sort(function (a, b) {
221 return ((new Date(a)).valueOf() < (new Date(b)).valueOf()) ? -1 : 1;
222 });
223 var startDate = new Date(sortedDates[self.focusedXIndex]);
224 this.highlightedTime = startDate;
225 self.onCellFocus(startDate, new Date(startDate.valueOf() + self.heatmapData.bucketSize), Math.max(0, cellX), cellX + self.calcCellWidth(self.focusedXIndex), self.calcCellY(self.focusedYIndex), highlightedSplitBy);
226 }
227 self.render(self.data, self.chartOptions, self.aggKey, highlightedSplitBy, this.highlightedTime, self.onCellFocus, null, self.isOnlyAgg);
228 }).on("mouseout", function () {
229 self.focusedXIndex = -1;
230 self.focusedYIndex = -1;
231 self.render(self.data, self.chartOptions, self.aggKey, null, null, self.onCellFocus, null, self.isOnlyAgg);
232 });
233 this.aggKey = aggKey;
234 this.rawCellHeight = Math.floor(this.height / this.heatmapData.numRows);
235 this.cellHeightMod = this.height % this.heatmapData.numRows;
236 this.rawCellWidth = this.width / this.heatmapData.numCols;
237 this.cellWidthMod = this.width % this.heatmapData.numCols;
238 this.colorLegend = container.append("svg").attr("class", "tsi-heatmapColorLegend");
239 this.colorLegend.attr("width", this.legendWidth)
240 .attr("height", this.height)
241 .style("left", (this.width) + "px");
242 var aggColor = data.displayState[aggKey].color;
243 if (isOnlyAgg) {
244 this.colorScale = scaleSequential(interpolateViridis).domain(this.getExtent());
245 }
246 else {
247 this.colorScale = scaleLinear().domain(this.getExtent())
248 .range([hcl(aggColor).brighter(), hcl(aggColor).darker()]);
249 }
250 this.renderScale();
251 var sortedTimes = Object.keys(this.heatmapData.timeValues).sort(function (a, b) {
252 return ((new Date(a)).valueOf() < (new Date(b)).valueOf()) ? -1 : 1;
253 });
254 sortedTimes.forEach(function (ts, tsI) {
255 Object.keys(_this.heatmapData.timeValues[ts]).forEach(function (splitBy, sBI) {
256 var cellData = _this.heatmapData.timeValues[ts][splitBy];
257 if (cellData != null) {
258 if (highlightedSplitBy && highlightedSplitBy != splitBy) {
259 _this.drawCell(cellData.rowI, cellData.colI, cellData.value, true);
260 }
261 else {
262 _this.drawCell(cellData.rowI, cellData.colI, cellData.value);
263 }
264 }
265 });
266 });
267 };
268 HeatmapCanvas.prototype.calcCellXIndex = function (x) {
269 var xI = 0;
270 while (Math.round(xI * this.rawCellWidth) < x) {
271 xI++;
272 }
273 return Math.max(xI - 1, 0);
274 };
275 HeatmapCanvas.prototype.calcCellYIndex = function (y) {
276 if (y < (this.cellHeightMod * (this.rawCellHeight + 1)))
277 return Math.floor(y / (this.rawCellHeight + 1));
278 var modOffset = this.cellHeightMod * (this.rawCellHeight + 1);
279 return Math.floor((y - modOffset) / this.rawCellHeight) + this.cellHeightMod;
280 };
281 HeatmapCanvas.prototype.calcCellHeight = function (i) {
282 return this.rawCellHeight + (i < this.cellHeightMod ? 1 : 0) - (this.rawCellWidth > 10 ? 1 : 0);
283 };
284 HeatmapCanvas.prototype.calcCellX = function (i) {
285 return Math.round(this.rawCellWidth * i);
286 };
287 HeatmapCanvas.prototype.calcCellWidth = function (i) {
288 return (Math.round(this.rawCellWidth * (i + 1)) - Math.round(this.rawCellWidth * i) - (this.rawCellWidth > 10 ? 1 : 0));
289 };
290 HeatmapCanvas.prototype.calcCellY = function (i) {
291 return Math.min(i, this.cellHeightMod) + (this.rawCellHeight * i);
292 };
293 HeatmapCanvas.prototype.drawCell = function (rowI, colI, value, outOfFocus) {
294 if (outOfFocus === void 0) { outOfFocus = false; }
295 var x = this.calcCellX(colI);
296 var y = this.calcCellY(rowI);
297 this.ctx.fillStyle = value !== null ? this.colorScale(value) : "transparent";
298 this.ctx.globalAlpha = outOfFocus ? .3 : 1;
299 this.ctx.fillRect(this.calcCellX(colI), this.calcCellY(rowI), this.calcCellWidth(colI), this.calcCellHeight(rowI));
300 };
301 return HeatmapCanvas;
302}(ChartComponent));
303
304var Heatmap = /** @class */ (function (_super) {
305 __extends(Heatmap, _super);
306 function Heatmap(renderTarget) {
307 var _this = _super.call(this, renderTarget) || this;
308 _this.lineHeight = 12;
309 _this.splitByLabelWidth = 140;
310 _this.timeLabels = null;
311 _this.timeLabelsHeight = 52;
312 _this.visibleAggs = null;
313 _this.mouseover = function (hoveredAggKey, hoveredSplitBy) {
314 var heatmapCanvas = _this.heatmapCanvasMap[hoveredAggKey];
315 if (heatmapCanvas)
316 heatmapCanvas.render(_this.chartComponentData, _this.chartOptions, hoveredAggKey, hoveredSplitBy, null, null, null, _this.visibleAggs.length === 1);
317 };
318 _this.mouseout = function (selection, hoveredAggKey) {
319 var heatmapCanvas = _this.heatmapCanvasMap[hoveredAggKey];
320 if (heatmapCanvas)
321 heatmapCanvas.render(_this.chartComponentData, _this.chartOptions, hoveredAggKey, null, null, null, null, _this.visibleAggs.length === 1);
322 };
323 _this.renderTimeLabels = function (focusStartTime, focusEndTime, focusX1, focusX2, focusY, yOffset, shiftMillis) {
324 _this.timeLabels.selectAll(".tsi-heatmapTimeLabels").remove();
325 _this.timeLabels.node().parentNode.appendChild(_this.timeLabels.node());
326 _this.timeLabels.append("line").attr("class", "tsi-heatmapFocusLine tsi-heatmapTimeLabels")
327 .attr("x1", focusX1)
328 .attr("x2", focusX1)
329 .attr("y1", focusY + yOffset)
330 .attr("y2", _this.chartHeight - _this.timeLabelsHeight);
331 _this.timeLabels.append("line").attr("class", "tsi-heatmapFocusLine tsi-heatmapTimeLabels")
332 .attr("x1", focusX2)
333 .attr("x2", focusX2)
334 .attr("y1", focusY + yOffset)
335 .attr("y2", _this.chartHeight - _this.timeLabelsHeight);
336 var textBoxG = _this.timeLabels.append("g")
337 .attr("class", "tsi-heatmapTimeLabelTextBox tsi-heatmapTimeLabels");
338 var text = textBoxG.append("text");
339 text.append("tspan").text(Utils.timeFormat(_this.chartComponentData.usesSeconds, _this.chartComponentData.usesMillis, _this.chartOptions.offset, _this.chartOptions.is24HourTime, shiftMillis, null, _this.chartOptions.dateLocale)(focusStartTime))
340 .attr("x", 0)
341 .attr("y", 16);
342 text.append("tspan").text(Utils.timeFormat(_this.chartComponentData.usesSeconds, _this.chartComponentData.usesMillis, _this.chartOptions.offset, _this.chartOptions.is24HourTime, shiftMillis, null, _this.chartOptions.dateLocale)(focusEndTime))
343 .attr("x", 0)
344 .attr("y", 30);
345 var textDimensions = text.node().getBoundingClientRect();
346 textBoxG.append("rect")
347 .attr("x", -(textDimensions.width / 2) - 5)
348 .attr("y", 0)
349 .attr("height", textDimensions.height + 12)
350 .attr("width", textDimensions.width + 10);
351 text.node().parentNode.appendChild(text.node());
352 var rawOffset = (focusX1 + focusX2) / 2;
353 var leftOffset = Math.floor(((rawOffset - ((textDimensions.width / 2) + 6)) > 0) ? rawOffset : ((textDimensions.width / 2) + 6));
354 textBoxG.attr("transform", "translate(" + leftOffset + "," + (_this.chartHeight - _this.timeLabelsHeight - _this.chartMargins.bottom) + ")");
355 };
356 _this.chartMargins = {
357 top: 0,
358 bottom: 8,
359 left: 40,
360 right: 20
361 };
362 return _this;
363 }
364 Heatmap.prototype.focusOnEllipsis = function () {
365 if (this.ellipsisContainer !== null) {
366 this.ellipsisContainer.select(".tsi-ellipsisButton").node().focus();
367 }
368 };
369 Heatmap.prototype.createControlsPanel = function () {
370 this.chartControlsPanel = Utils.createControlPanel(this.renderTarget, this.CONTROLSWIDTH, 52, this.chartOptions);
371 this.ellipsisContainer = this.chartControlsPanel.append("div")
372 .attr("class", "tsi-ellipsisContainerDiv");
373 this.ellipsisMenu = new EllipsisMenu(this.ellipsisContainer.node());
374 };
375 Heatmap.prototype.chartControlsExist = function () {
376 return (this.ellipsisItemsExist() && !this.chartOptions.hideChartControlPanel);
377 };
378 Heatmap.prototype.addTimeLabels = function () {
379 if (this.timeLabels === null || this.svgSelection === null) {
380 this.svgSelection = this.heatmapWrapper.append('svg')
381 .attr('class', 'tsi-heatmapSVG')
382 .attr('title', this.getString('Heatmap'));
383 this.timeLabels = this.svgSelection.append('g').attr("class", "tsi-heatmapTimeLabels")
384 .attr('transform', 'translate(' + this.chartMargins.left + ',0)');
385 }
386 if (!this.chartOptions.xAxisHidden) {
387 this.xAxis = this.timeLabels.selectAll(".xAxis").data([this.x]);
388 this.drawXAxis(this.chartHeight - 60);
389 this.xAxis.exit().remove();
390 var xAxisBaseline = this.timeLabels.selectAll(".xAxisBaseline").data([this.x]);
391 var xAxisBaselineEntered = xAxisBaseline.enter().append("line")
392 .attr("class", "xAxisBaseline")
393 .attr("x1", .5)
394 .merge(xAxisBaseline)
395 .attr("y2", this.chartHeight - (this.chartMargins.bottom + this.timeLabelsHeight))
396 .attr("y1", this.chartHeight - (this.chartMargins.bottom + this.timeLabelsHeight))
397 .attr("x2", this.chartWidth - 90);
398 xAxisBaseline.exit().remove();
399 }
400 if (this.timeLabels.selectAll(".xAxis").size() !== 0) {
401 this.timeLabels.selectAll(".xAxis").style("visibility", ((!this.chartOptions.xAxisHidden) ? "visible" : "hidden"));
402 }
403 };
404 Heatmap.prototype.render = function (data, chartOptions, aggregateExpressionOptions) {
405 var _this = this;
406 _super.prototype.render.call(this, data, chartOptions, aggregateExpressionOptions);
407 // override visibleSplitByCap
408 this.aggregateExpressionOptions = this.aggregateExpressionOptions.map(function (aE) {
409 return __assign(__assign({}, aE), { visibleSplitByCap: 10000 });
410 });
411 this.chartOptions.setOptions(chartOptions);
412 var targetElement = select(this.renderTarget).classed("tsi-heatmapComponent", true);
413 if (targetElement.style("position") == "static")
414 targetElement.style("position", "relative");
415 this.chartComponentData.mergeDataToDisplayStateAndTimeArrays(this.data, this.aggregateExpressionOptions);
416 if (this.chartControlsExist() && this.chartControlsPanel === null) {
417 this.createControlsPanel();
418 }
419 else if ((this.chartOptions.hideChartControlPanel || !this.ellipsisItemsExist()) && this.chartControlsPanel !== null) {
420 this.chartControlsPanel.remove();
421 this.chartControlsPanel = null;
422 }
423 if (this.chartControlsExist()) {
424 this.chartControlsPanel.style("top", (16 + (this.chartOptions.legend === 'compact' ? 32 : 0)) + 'px');
425 this.drawEllipsisMenu();
426 }
427 if (this.heatmapWrapper == null) {
428 this.heatmapWrapper = targetElement.append('div')
429 .attr("class", "tsi-heatmapWrapper");
430 this.draw = function (isFromResize) {
431 if (isFromResize === void 0) { isFromResize = false; }
432 _this.height = Math.floor(Math.max(select(_this.renderTarget).node().clientHeight, _this.MINHEIGHT));
433 _this.chartHeight = _this.height - ((12 + (_this.chartControlsExist() ? 28 : 0) + (_this.chartOptions.legend === 'compact' ? 48 : 0)));
434 _super.prototype.themify.call(_this, targetElement, _this.chartOptions.theme);
435 _this.width = _this.getWidth();
436 if (!isFromResize) {
437 _this.chartWidth = _this.getChartWidth();
438 }
439 _this.x = scaleTime()
440 .rangeRound([0, _this.chartWidth - 90]); // HARDCODED to be the width of a heatmapCanvas
441 var fromAndTo = _this.chartComponentData.setAllValuesAndVisibleTAs();
442 _this.x.domain(fromAndTo);
443 _this.heatmapWrapper.style("width", _this.chartWidth + (_this.chartMargins.left + _this.chartMargins.right) + "px")
444 .style("height", _this.chartHeight + "px")
445 .style("top", (20 + (_this.chartControlsExist() ? 36 : 0) + (_this.chartOptions.legend === 'compact' ? 40 : 0)) + "px");
446 if (_this.chartControlsExist()) {
447 _this.setControlsPanelWidth();
448 }
449 var canvasWrapperHeightTotal = _this.chartHeight - _this.timeLabelsHeight - _this.chartMargins.bottom;
450 _this.heatmapCanvasMap = {};
451 _this.visibleAggs = Object.keys(_this.chartComponentData.displayState).filter(function (aggKey) {
452 return _this.chartComponentData.getAggVisible(aggKey);
453 });
454 var self = _this;
455 var canvasWrappers = _this.heatmapWrapper.selectAll(".tsi-heatmapCanvasWrapper")
456 .data(_this.visibleAggs);
457 var canvasesEntered = canvasWrappers.enter()
458 .append("div")
459 .merge(canvasWrappers)
460 .attr("class", "tsi-heatmapCanvasWrapper")
461 .style("width", _this.chartWidth + 'px')
462 .style('left', _this.chartMargins.left + 'px')
463 .style("height", function (d, i) {
464 return (canvasWrapperHeightTotal * (1 / _this.visibleAggs.length)) + "px";
465 })
466 .style("top", function (d, i) {
467 return ((canvasWrapperHeightTotal * (1 / _this.visibleAggs.length)) * i) + "px";
468 }).each(function (aggKey, aggI) {
469 var heatmapCanvas = new HeatmapCanvas(this);
470 self.heatmapCanvasMap[aggKey] = heatmapCanvas;
471 var renderHeatmapCanvas = function () {
472 function onCellFocus(focusStartTime, focusEndTime, focusX1, focusX2, focusY, splitBy) {
473 var shiftMillis = self.chartComponentData.getTemporalShiftMillis(aggKey);
474 self.renderTimeLabels(focusStartTime, focusEndTime, focusX1, focusX2, focusY, (aggI * canvasWrapperHeightTotal / self.visibleAggs.length), shiftMillis);
475 self.legendObject.triggerSplitByFocus(aggKey, splitBy);
476 self.chartOptions.onMouseover(aggKey, splitBy);
477 }
478 heatmapCanvas.render(self.chartComponentData, self.chartOptions, aggKey, null, null, onCellFocus, aggI, self.visibleAggs.length === 1);
479 };
480 renderHeatmapCanvas();
481 }).on("mouseleave", function () {
482 self.timeLabels.selectAll(".tsi-heatmapTimeLabels").remove();
483 self.legendObject.legendElement.selectAll('.tsi-splitByLabel').classed("inFocus", false);
484 self.chartOptions.onMouseout();
485 });
486 canvasWrappers.exit().remove();
487 _this.legendObject.draw(_this.chartOptions.legend, _this.chartComponentData, _this.mouseover, _this.heatmapWrapper, _this.chartOptions, _this.mouseout);
488 //remove all the colorKeys
489 _this.legendObject.legendElement.selectAll(".seriesLabel").selectAll(".tsi-splitByLabel").selectAll(".colorKey").style("display", "none");
490 if (isFromResize) {
491 _this.addTimeLabels();
492 }
493 };
494 this.legendObject = new Legend(this.draw, this.renderTarget, this.CONTROLSWIDTH);
495 }
496 this.chartComponentData.mergeDataToDisplayStateAndTimeArrays(this.data, this.aggregateExpressionOptions);
497 this.draw();
498 this.gatedShowGrid();
499 this.addTimeLabels();
500 window.addEventListener("resize", function () {
501 if (!_this.chartOptions.suppressResizeListener) {
502 _this.draw();
503 _this.addTimeLabels();
504 }
505 });
506 this.legendPostRenderProcess(this.chartOptions.legend, this.heatmapWrapper, true);
507 };
508 return Heatmap;
509}(TemporalXAxisComponent));
510
511export { Heatmap as H };