scichart
Version:
Fast WebGL JavaScript Charting Library and Framework
241 lines (240 loc) • 14.2 kB
JavaScript
"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.PolarLayoutManager = void 0;
var Rect_1 = require("../../../Core/Rect");
var LayoutManagerType_1 = require("../../../types/LayoutManagerType");
var AngularAxisLayoutStrategy_1 = require("./AngularAxisLayoutStrategy");
var LayoutManager_1 = require("../LayoutManager");
var RadialAxisLayoutStrategy_1 = require("./RadialAxisLayoutStrategy");
var MIN_SERIES_AREA_SIZE = 10;
var PolarLayoutManager = /** @class */ (function (_super) {
__extends(PolarLayoutManager, _super);
function PolarLayoutManager() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.type = LayoutManagerType_1.ELayoutManagerType.Polar;
/**
* Layout strategy for the outer angular axes
*/
_this.angularOuterAxesLayoutStrategyProperty = new AngularAxisLayoutStrategy_1.AngularAxisLayoutStrategy();
/**
* Layout strategy for the inner angular axes
*/
_this.angularInnerAxesLayoutStrategyProperty = new AngularAxisLayoutStrategy_1.AngularAxisLayoutStrategy();
/**
* Layout strategy for layout of outer radial axes
*/
_this.radialOuterAxesLayoutStrategyProperty = new RadialAxisLayoutStrategy_1.RadialAxisLayoutStrategy();
/**
* Layout strategy for layout of inner radial axes
*/
_this.radialInnerAxesLayoutStrategyProperty = new RadialAxisLayoutStrategy_1.RadialAxisLayoutStrategy();
return _this;
}
Object.defineProperty(PolarLayoutManager.prototype, "angularOuterAxesLayoutStrategy", {
get: function () {
return this.angularOuterAxesLayoutStrategyProperty;
},
set: function (value) {
var _a;
var currentValue = this.angularOuterAxesLayoutStrategyProperty;
if (currentValue !== value) {
this.angularOuterAxesLayoutStrategyProperty = value;
if (currentValue.isStacked && !value.isStacked) {
this.groupAxesByLayoutStrategy();
// Use Top Axes for Angular
this.resetAxes(this.axesGroupedByLayoutStrategy.topOuterAxes);
}
(_a = this.sciChartSurface) === null || _a === void 0 ? void 0 : _a.invalidateElement();
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(PolarLayoutManager.prototype, "angularInnerAxesLayoutStrategy", {
get: function () {
return this.angularInnerAxesLayoutStrategyProperty;
},
set: function (value) {
var _a;
var currentValue = this.angularInnerAxesLayoutStrategyProperty;
if (currentValue !== value) {
this.angularInnerAxesLayoutStrategyProperty = value;
if (currentValue.isStacked && !value.isStacked) {
this.groupAxesByLayoutStrategy();
// Use Top Axes for Angular
this.resetAxes(this.axesGroupedByLayoutStrategy.topInnerAxes);
}
(_a = this.sciChartSurface) === null || _a === void 0 ? void 0 : _a.invalidateElement();
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(PolarLayoutManager.prototype, "radialOuterAxesLayoutStrategy", {
get: function () {
return this.radialOuterAxesLayoutStrategyProperty;
},
set: function (value) {
var _a;
var currentValue = this.radialOuterAxesLayoutStrategyProperty;
if (currentValue !== value) {
this.radialOuterAxesLayoutStrategyProperty = value;
if (currentValue.isStacked && !value.isStacked) {
this.groupAxesByLayoutStrategy();
// Use Right Axes for Radial
this.resetAxes(this.axesGroupedByLayoutStrategy.rightOuterAxes);
}
(_a = this.sciChartSurface) === null || _a === void 0 ? void 0 : _a.invalidateElement();
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(PolarLayoutManager.prototype, "radialInnerAxesLayoutStrategy", {
get: function () {
return this.radialInnerAxesLayoutStrategyProperty;
},
set: function (value) {
var _a;
var currentValue = this.radialInnerAxesLayoutStrategyProperty;
if (currentValue !== value) {
this.radialInnerAxesLayoutStrategyProperty = value;
if (currentValue.isStacked && !value.isStacked) {
this.groupAxesByLayoutStrategy();
// Use Right Axes for Radial
this.resetAxes(this.axesGroupedByLayoutStrategy.rightInnerAxes);
}
(_a = this.sciChartSurface) === null || _a === void 0 ? void 0 : _a.invalidateElement();
}
},
enumerable: false,
configurable: true
});
PolarLayoutManager.prototype.getAxisLayoutStrategy = function (axis) {
if (!axis.isPolarAxis) {
throw new Error("Cannot get Polar LayoutStrategy for a non-polar axis");
}
if (axis.isAngular) {
return axis.isInnerAxis ? this.angularInnerAxesLayoutStrategy : this.angularOuterAxesLayoutStrategy;
}
else {
return axis.isInnerAxis ? this.radialInnerAxesLayoutStrategy : this.radialOuterAxesLayoutStrategy;
}
};
PolarLayoutManager.prototype.layoutChart = function (viewportSize, padding) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
this.groupAxesByLayoutStrategy();
var paddingRight = (_a = padding === null || padding === void 0 ? void 0 : padding.right) !== null && _a !== void 0 ? _a : 0;
var paddingLeft = (_b = padding === null || padding === void 0 ? void 0 : padding.left) !== null && _b !== void 0 ? _b : 0;
var paddingTop = (_c = padding === null || padding === void 0 ? void 0 : padding.top) !== null && _c !== void 0 ? _c : 0;
var paddingBottom = (_d = padding === null || padding === void 0 ? void 0 : padding.bottom) !== null && _d !== void 0 ? _d : 0;
var availableWidth = viewportSize.width - paddingLeft - paddingRight;
var availableHeight = viewportSize.height - paddingTop - paddingBottom;
var surfacePadding = this.sciChartSurface.adjustedPadding;
this.chartLayoutState.leftOuterAreaSize =
((_e = surfacePadding === null || surfacePadding === void 0 ? void 0 : surfacePadding.left) !== null && _e !== void 0 ? _e : 0) +
this.sciChartSurface.leftViewportBorder +
this.sciChartSurface.leftCanvasBorder;
this.chartLayoutState.rightOuterAreaSize =
((_f = surfacePadding === null || surfacePadding === void 0 ? void 0 : surfacePadding.right) !== null && _f !== void 0 ? _f : 0) +
this.sciChartSurface.rightViewportBorder +
this.sciChartSurface.rightCanvasBorder;
this.chartLayoutState.topOuterAreaSize =
((_g = surfacePadding === null || surfacePadding === void 0 ? void 0 : surfacePadding.top) !== null && _g !== void 0 ? _g : 0) + this.sciChartSurface.topViewportBorder + this.sciChartSurface.topCanvasBorder;
this.chartLayoutState.bottomOuterAreaSize =
((_h = surfacePadding === null || surfacePadding === void 0 ? void 0 : surfacePadding.bottom) !== null && _h !== void 0 ? _h : 0) +
this.sciChartSurface.bottomViewportBorder +
this.sciChartSurface.bottomCanvasBorder;
this.setSeriesViewRect(this.chartLayoutState.leftOuterAreaSize, this.chartLayoutState.topOuterAreaSize, viewportSize.width - this.chartLayoutState.rightOuterAreaSize, viewportSize.height - this.chartLayoutState.bottomOuterAreaSize);
try {
// measure angular axes areas
this.angularOuterAxesLayoutStrategy.measureAxes(this.sciChartSurface, this.chartLayoutState, this.axesGroupedByLayoutStrategy.topOuterAxes);
this.angularInnerAxesLayoutStrategy.measureAxes(this.sciChartSurface, this.chartLayoutState, this.axesGroupedByLayoutStrategy.topInnerAxes);
// Measure radial axes.
this.radialOuterAxesLayoutStrategy.measureAxes(this.sciChartSurface, this.chartLayoutState, this.axesGroupedByLayoutStrategy.rightOuterAxes);
this.radialInnerAxesLayoutStrategy.measureAxes(this.sciChartSurface, this.chartLayoutState, this.axesGroupedByLayoutStrategy.rightInnerAxes);
var remainingWidth = availableWidth - this.chartLayoutState.leftOuterAreaSize - this.chartLayoutState.rightOuterAreaSize;
var remainingHeight = availableHeight - this.chartLayoutState.topOuterAreaSize - this.chartLayoutState.bottomOuterAreaSize;
var leftStart = paddingLeft;
var leftEnd = leftStart + this.chartLayoutState.leftOuterAreaSize;
var rightStart = leftEnd + (remainingWidth < MIN_SERIES_AREA_SIZE ? MIN_SERIES_AREA_SIZE : remainingWidth);
var rightEnd = rightStart + this.chartLayoutState.rightOuterAreaSize;
var topStart = paddingTop;
var topEnd = topStart + this.chartLayoutState.topOuterAreaSize;
var bottomStart = topEnd + (remainingHeight < MIN_SERIES_AREA_SIZE ? MIN_SERIES_AREA_SIZE : remainingHeight);
var bottomEnd = bottomStart + this.chartLayoutState.bottomOuterAreaSize;
// layout center parts
this.sciChartSurface.annotationUnderlaySurfaceViewRect = Rect_1.Rect.createWithCoords(leftStart, topStart, rightEnd, bottomEnd);
this.sciChartSurface.annotationOverlaySurfaceViewRect = Rect_1.Rect.createWithCoords(leftStart, topStart, rightEnd, bottomEnd);
this.sciChartSurface.chartModifierSurfaceViewRect = Rect_1.Rect.createWithCoords(leftStart, topStart, rightEnd, bottomEnd);
// layout Angular axes
this.angularOuterAxesLayoutStrategy.layoutAxes(leftEnd, topEnd, rightStart, bottomStart, this.axesGroupedByLayoutStrategy.topOuterAxes);
var innerRadius = (_m = (_k = (_j = this.axesGroupedByLayoutStrategy.rightOuterAxes[0]) === null || _j === void 0 ? void 0 : _j.offset) !== null && _k !== void 0 ? _k : (_l = this.axesGroupedByLayoutStrategy.rightInnerAxes[0]) === null || _l === void 0 ? void 0 : _l.offset) !== null && _m !== void 0 ? _m : 0;
this.angularInnerAxesLayoutStrategy.layoutAxes(leftEnd + innerRadius, topEnd + innerRadius, rightStart - innerRadius, bottomStart - innerRadius, this.axesGroupedByLayoutStrategy.topInnerAxes);
var outerViewRect = Rect_1.Rect.createZero();
if (this.axesGroupedByLayoutStrategy.topOuterAxes.length > 0) {
outerViewRect = this.axesGroupedByLayoutStrategy.topOuterAxes[0].viewRect;
}
else if (this.axesGroupedByLayoutStrategy.topInnerAxes.length > 0) {
outerViewRect = this.axesGroupedByLayoutStrategy.topInnerAxes[0].viewRect;
}
// layout radial axes
this.radialOuterAxesLayoutStrategy.layoutAxes(outerViewRect.left, // x
outerViewRect.top, // y
outerViewRect.width, // radius
outerViewRect.height, this.axesGroupedByLayoutStrategy.rightOuterAxes);
this.radialInnerAxesLayoutStrategy.layoutAxes(outerViewRect.left, outerViewRect.top, outerViewRect.width, outerViewRect.height, this.axesGroupedByLayoutStrategy.rightInnerAxes);
return this.sciChartSurface.seriesViewRect;
}
finally {
this.chartLayoutState.clear();
}
return undefined;
};
PolarLayoutManager.prototype.groupAxesByLayoutStrategy = function () {
this.axesGroupedByLayoutStrategy.clear();
var _a = this.axesGroupedByLayoutStrategy, topOuterAxes = _a.topOuterAxes, topInnerAxes = _a.topInnerAxes, rightOuterAxes = _a.rightOuterAxes, rightInnerAxes = _a.rightInnerAxes;
var groupAxes = function (axes) {
axes.forEach(function (axis) {
if (axis.isPolarAxis) {
var isAngular = axis.isAngular;
if (isAngular) {
if (axis.isInnerAxis) {
topInnerAxes.push(axis);
}
else {
topOuterAxes.push(axis);
}
}
else {
if (axis.isInnerAxis) {
rightInnerAxes.push(axis);
}
else {
rightOuterAxes.push(axis);
}
}
}
});
};
groupAxes(this.sciChartSurface.xAxes.asArray());
groupAxes(this.sciChartSurface.yAxes.asArray());
};
return PolarLayoutManager;
}(LayoutManager_1.LayoutManager));
exports.PolarLayoutManager = PolarLayoutManager;