UNPKG

scichart

Version:

Fast WebGL JavaScript Charting Library and Framework

146 lines (145 loc) 8.32 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.NonUniformHeatMapDataLabelProvider = void 0; var Point_1 = require("../../../../Core/Point"); var Rect_1 = require("../../../../Core/Rect"); var AxisType_1 = require("../../../../types/AxisType"); var DataLabelProviderType_1 = require("../../../../types/DataLabelProviderType"); var Size_1 = require("../../../../types/Size"); var parseColor_1 = require("../../../../utils/parseColor"); var NativeObject_1 = require("../../Helpers/NativeObject"); var DpiHelper_1 = require("../../TextureManager/DpiHelper"); var HeatMapDataLabelProvider_1 = require("./HeatMapDataLabelProvider"); var NonUniformHeatMapDataLabelProvider = /** @class */ (function (_super) { __extends(NonUniformHeatMapDataLabelProvider, _super); function NonUniformHeatMapDataLabelProvider() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.type = DataLabelProviderType_1.EDataLabelProviderType.NonUniformHeatmap; _this.cellSizeThresholdCoefficient = 1; return _this; } NonUniformHeatMapDataLabelProvider.prototype.getPosition = function (xIndex, yIndex, xVal, yVal, textSize, cellWidth, cellHeight, renderPassData) { var x = renderPassData.xCoordinateCalculator.getCoordinate(xVal); var y = renderPassData.yCoordinateCalculator.getCoordinate(yVal); if (renderPassData.isVerticalChart) { var c = x; x = y; y = c; } var xCalc = renderPassData.isVerticalChart ? renderPassData.yCoordinateCalculator : renderPassData.xCoordinateCalculator; var yCalc = renderPassData.isVerticalChart ? renderPassData.xCoordinateCalculator : renderPassData.yCoordinateCalculator; if (xCalc.hasFlippedCoordinates) { x += (cellWidth - textSize.width) / 2; } else { x -= cellWidth - (cellWidth - textSize.width) / 2; } if (yCalc.hasFlippedCoordinates) { y += cellHeight - (cellHeight - textSize.height) / 2; } else { y -= (cellHeight - textSize.height) / 2; } return { position: new Point_1.Point(x, y), rotationCenter: new Point_1.Point(x, y), rotationAngle: 0 }; }; NonUniformHeatMapDataLabelProvider.prototype.generateDataLabels = function (renderContext, renderPassData) { var _a; // clear any previous labels this.dataLabels = []; if (!this.style || !this.style.fontFamily || !this.style.fontSize) { return; } this.dataSeries = this.parentSeries.dataSeries; this.zValues = this.dataSeries.getZValues(); // this.state = new DataLabelState(renderContext, renderPassData, this.style, yValues, this.parentSeries); var bounds = (0, NativeObject_1.getTextBounds)(this.webAssemblyContext); var dpiAdjustedStyle = DpiHelper_1.DpiHelper.adjustTextStyle(this.style); var font = renderContext.getFont(dpiAdjustedStyle); // NonUniform-specific logic var heatmapWidth = Math.abs(renderPassData.xCoordinateCalculator.getCoordinate(this.dataSeries.getXValue(this.dataSeries.arrayWidth)) - renderPassData.xCoordinateCalculator.getCoordinate(this.dataSeries.getXValue(0))); var heatmapHeight = Math.abs(renderPassData.yCoordinateCalculator.getCoordinate(this.dataSeries.getYValue(this.dataSeries.arrayHeight)) - renderPassData.yCoordinateCalculator.getCoordinate(this.dataSeries.getYValue(0))); var getXCoordFn = function (x) { return x; }; if (this.parentSeries.xAxis.type === AxisType_1.EAxisType.BaseValueAxis || this.parentSeries.xAxis.type === AxisType_1.EAxisType.DiscontinuousDateAxis) { getXCoordFn = function (x) { return renderPassData.xCoordinateCalculator.getCoordinate(x); }; } var relativeXCellSizes = this.dataSeries.getXCellSizes(getXCoordFn); var relativeYCellSizes = this.dataSeries.getYCellSizes(); font.CalculateStringBounds((_a = this.getText(0, 0)) !== null && _a !== void 0 ? _a : "", bounds, this.getLineSpacing()); var minCellHeight = bounds.m_fHeight * this.cellSizeThresholdCoefficient; var minCellWidth = bounds.m_fWidth * this.cellSizeThresholdCoefficient; // TODO figure out how it should work for NonUniform // if (!this.shouldGenerate(new Size(bounds.m_fWidth, bounds.m_fHeight), cellWidth, cellHeight)) return; this.colorValue = (0, parseColor_1.parseColorToUIntArgb)(this.color); for (var yIndex = 0; yIndex < this.dataSeries.arrayHeight; yIndex++) { var cellHeight = heatmapHeight * relativeYCellSizes[yIndex]; if (cellHeight < minCellHeight) { continue; } var yVal = this.dataSeries.getYValue(yIndex); var yValNext = this.dataSeries.yCellOffsets[yIndex + 1]; if (renderPassData.yCoordinateCalculator.visibleMin > yVal || renderPassData.yCoordinateCalculator.visibleMax < yValNext) { continue; } for (var xIndex = 0; xIndex < this.dataSeries.arrayWidth; xIndex++) { var cellWidth = heatmapWidth * relativeXCellSizes[xIndex]; if (cellWidth < minCellWidth) { continue; } var xVal = this.dataSeries.getXValue(xIndex); var xValNext = this.dataSeries.xCellOffsets[xIndex + 1]; if (renderPassData.xCoordinateCalculator.visibleMin > xVal || renderPassData.xCoordinateCalculator.visibleMax < xValNext) { continue; } var text = this.getText(xIndex, yIndex); if (!text) { continue; } font.CalculateStringBounds(text !== null && text !== void 0 ? text : "", bounds, this.getLineSpacing()); var textSize = new Size_1.Size(bounds.m_fWidth, bounds.m_fHeight); var cw = renderPassData.isVerticalChart ? cellHeight : cellWidth; var ch = renderPassData.isVerticalChart ? cellWidth : cellHeight; var _b = this.getPosition(xIndex, yIndex, xVal, yVal, textSize, cw, ch, renderPassData), position = _b.position, rotationAngle = _b.rotationAngle, rotationCenter = _b.rotationCenter; var lineBounds = bounds.GetLineBounds(0); var label = { text: text, position: position, rect: new Rect_1.Rect(position.x, position.y - lineBounds.m_fHeight, textSize.width, textSize.height), color: this.getColor(xIndex, yIndex, text), dataX: xVal, dataY: yVal, rotationAngle: rotationAngle, rotationCenter: rotationCenter }; lineBounds.delete(); if (!this.shouldSkipLabel(xIndex, yIndex, label, cellWidth, cellHeight)) { this.dataLabels.push(label); } } } }; return NonUniformHeatMapDataLabelProvider; }(HeatMapDataLabelProvider_1.HeatMapDataLabelProvider)); exports.NonUniformHeatMapDataLabelProvider = NonUniformHeatMapDataLabelProvider;