UNPKG

scichart

Version:

Fast WebGL JavaScript Charting Library and Framework

130 lines (129 loc) 7.7 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.AngularAxisLayoutStrategy = void 0; var Rect_1 = require("../../../Core/Rect"); var LayoutStrategyType_1 = require("../../../types/LayoutStrategyType"); var BasePolarAxisLayoutStrategy_1 = require("./BasePolarAxisLayoutStrategy"); var labelHelper_1 = require("../../Visuals/Helpers/labelHelper"); var twoPI = 2 * Math.PI; var quarter = Math.PI / 2; var AngularAxisLayoutStrategy = /** @class */ (function (_super) { __extends(AngularAxisLayoutStrategy, _super); function AngularAxisLayoutStrategy() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.type = LayoutStrategyType_1.ELayoutStrategyType.TopOuter; return _this; } AngularAxisLayoutStrategy.prototype.measureAxes = function (sciChartSurface, chartLayoutState, axes) { if (!axes || axes.length === 0) return 0; var firstAngularAxis = axes[0]; var firstRadialAxis = (firstAngularAxis.isXAxis ? sciChartSurface.yAxes.get(0) : sciChartSurface.xAxes.get(0)); var firstAngularAxisStartAngle = axes[0].startAngle; var firstAngularAxisTotalAngle = axes[0].totalAngle; var _a = this.partialArcLayout(firstRadialAxis.innerRadius, firstAngularAxisStartAngle, firstAngularAxisTotalAngle), rightScale = _a.rightScale, topScale = _a.topScale, leftScale = _a.leftScale, bottomScale = _a.bottomScale; axes.forEach(function (axis) { var pAxis = axis; if (firstAngularAxisStartAngle !== pAxis.startAngle || firstAngularAxisTotalAngle !== pAxis.totalAngle) { throw new Error("AngularAxisLayoutStrategy assumes all angular axes have the same startAngle and totalAngle. To vary this use StackedAngularAxisLayoutStrategy."); } axis.measure(); var axisRenderer = pAxis.axisRenderer, axisLayoutState = pAxis.axisLayoutState, axisBorder = pAxis.axisBorder; axisLayoutState.clear(); var borderHeight = axisBorder.borderBottom + axisBorder.borderTop; var basePadding = 0; var axisVerticalSize = basePadding + axisRenderer.desiredHeight + borderHeight; axisLayoutState.axisSize = axisVerticalSize; var borderWidth = axisBorder.borderLeft + axisBorder.borderRight; var axisHorizontalSize = basePadding + axisRenderer.desiredWidth + borderWidth; axisLayoutState.leftScale = leftScale; axisLayoutState.rightScale = rightScale; axisLayoutState.topScale = topScale; axisLayoutState.bottomScale = bottomScale; if (pAxis.isAngular) { chartLayoutState.topOuterAreaSize += axisVerticalSize; chartLayoutState.bottomOuterAreaSize += axisVerticalSize; chartLayoutState.leftOuterAreaSize += axisHorizontalSize; chartLayoutState.rightOuterAreaSize += axisHorizontalSize; } }); return 0; }; AngularAxisLayoutStrategy.prototype.layoutAxes = function (left, top, right, bottom, axes) { if (!axes || axes.length === 0) return; // Assuming all axes are the same scale var axis = axes[0]; var _a = axis.axisLayoutState, leftScale = _a.leftScale, rightScale = _a.rightScale, topScale = _a.topScale, bottomScale = _a.bottomScale, axisSize = _a.axisSize; var widthScale = rightScale - leftScale; var heightScale = topScale - bottomScale; var chartAspectRatio = widthScale / heightScale; // try max height first var availableHeight = bottom - top; var availableWidth = right - left; var canvasAspectRatio = availableWidth / availableHeight; var chartWidth = canvasAspectRatio > chartAspectRatio ? availableHeight * chartAspectRatio : availableWidth; var chartHeight = canvasAspectRatio > chartAspectRatio ? availableHeight : availableWidth / chartAspectRatio; var circleRadius = chartWidth / widthScale; // find center var x = left + (availableWidth - chartWidth) / 2 - (chartWidth * leftScale) / (rightScale - leftScale); var y = top + (availableHeight - chartHeight) / 2 + chartHeight * (1 + bottomScale / (topScale - bottomScale)); axes.forEach(function (axis) { axis.axisLength = axis.totalAngle; axis.offset = 0; // Layout axis label space first, inner to outer var _a = axis, axisSize = _a.axisLayoutState.axisSize, axisRenderer = _a.axisRenderer, xCenterOffset = _a.xCenterOffset, yCenterOffset = _a.yCenterOffset; axis.viewRect = Rect_1.Rect.create(x + xCenterOffset, y + yCenterOffset, circleRadius, circleRadius + axisSize); axisRenderer.layout(axis.viewRect); circleRadius += axisSize; }); }; AngularAxisLayoutStrategy.prototype.partialArcLayout = function (innerRadius, startAngleInput, totalAngleInput) { var rightScale = 1; var topScale = 1; var leftScale = -1; var bottomScale = -1; if (totalAngleInput < twoPI) { var startAngle = labelHelper_1.labelHelper.normalizeAngle(startAngleInput); var endAngle = startAngle + totalAngleInput; var cosStart = Math.cos(startAngle); var cosEnd = Math.cos(endAngle); var sinStart = Math.sin(startAngle); var sinEnd = Math.sin(endAngle); var hasRightPoint = startAngle === 0 || twoPI <= endAngle; if (!hasRightPoint) { rightScale = Math.max(cosStart, cosEnd, cosStart * innerRadius, cosEnd * innerRadius); } var hasLeftPoint = (startAngle <= Math.PI && Math.PI <= endAngle) || 3 * Math.PI <= endAngle; if (!hasLeftPoint) { leftScale = Math.min(cosStart, cosEnd, cosStart * innerRadius, cosEnd * innerRadius); } var hasTopPoint = (startAngle <= quarter && quarter <= endAngle) || twoPI + quarter <= endAngle; if (!hasTopPoint) { topScale = Math.max(sinStart, sinEnd, sinStart * innerRadius, sinEnd * innerRadius); } var hasBottomPoint = (startAngle <= 3 * quarter && 3 * quarter <= endAngle) || twoPI + 3 * quarter <= endAngle; if (!hasBottomPoint) { bottomScale = Math.min(sinStart, sinEnd, sinStart * innerRadius, sinEnd * innerRadius); } } return { rightScale: rightScale, leftScale: leftScale, topScale: topScale, bottomScale: bottomScale }; }; return AngularAxisLayoutStrategy; }(BasePolarAxisLayoutStrategy_1.BasePolarAxisLayoutStrategy)); exports.AngularAxisLayoutStrategy = AngularAxisLayoutStrategy;