scichart
Version:
Fast WebGL JavaScript Charting Library and Framework
258 lines (257 loc) • 13.3 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.PolarZoomExtentsModifier = void 0;
var DoubleAnimator_1 = require("../../../Core/Animations/DoubleAnimator");
var EasingFunctions_1 = require("../../../Core/Animations/EasingFunctions");
var GenericAnimation_1 = require("../../../Core/Animations/GenericAnimation");
var Point_1 = require("../../../Core/Point");
var ChartModifierType_1 = require("../../../types/ChartModifierType");
var ModifierType_1 = require("../../../types/ModifierType");
var XyDirection_1 = require("../../../types/XyDirection");
var ZoomState_1 = require("../../../types/ZoomState");
var ZoomExtentsModifier_1 = require("../ZoomExtentsModifier");
/**
* The PolarZoomExtentsModifier provides double-tap or double-click to zoom-to-fit (Zoom Extents) behavior
* on a 2D {@link SciChartPolarSurface} within SciChart - High Performance {@link https://www.scichart.com/javascript-chart-features | JavaScript Charts}
* @remarks
*
* To apply the PolarZoomExtentsModifier to a {@link SciChartPolarSurface} and add drag to zoom behavior,
* use the following code:
*
* ```ts
* const sciChartSurface: SciChartPolarSurface;
* sciChartSurface.chartModifiers.add(new PolarZoomExtentsModifier());
* ```
*
* Animation of the zoom extents be controlled via the {@link PolarZoomExtentsModifier.isAnimated},
* {@link PolarZoomExtentsModifier.animationDuration} and {@link PolarZoomExtentsModifier.easingFunction} properties.
*
* ---
* 📚 Docs: {@link https://www.scichart.com/documentation/js/v4/2d-charts/chart-modifier-api/polar-modifiers/polar-zoom-extents-modifier/}
*/
var PolarZoomExtentsModifier = /** @class */ (function (_super) {
__extends(PolarZoomExtentsModifier, _super);
/**
* Creates an instance of PolarZoomExtentsModifier
* @param options Optional parameters to configure the modifier via {@link IPolarZoomExtentsModifierOptions}
*
* ---
* 📚 Docs: {@link https://www.scichart.com/documentation/js/v4/2d-charts/chart-modifier-api/polar-modifiers/polar-zoom-extents-modifier/}
*/
function PolarZoomExtentsModifier(options) {
var _this = this;
var _a, _b, _c, _d, _e, _f;
_this = _super.call(this, options) || this;
_this.type = ChartModifierType_1.EChart2DModifierType.PolarZoomExtents;
/**
* Get or sets flag to reset X and Y visible ranges
*/
_this.resetRanges = true;
/**
* Get or sets flag to reset start angles for X and Y axes
*/
_this.resetStartAngles = true;
/**
* Get or sets flag to reset total angle for the angular axis
*/
_this.resetTotalAngle = true;
/**
* Gets of sets flag to reset length scale for radial axis
*/
_this.resetLengthScale = true;
/**
* Gets of sets flag to reset center point for X and Y axes
*/
_this.resetCenterPoint = true;
/**
* Gets of sets flag to reset inner radius for the radial axis
*/
_this.resetInnerRadius = true;
_this.xStartAngle = options === null || options === void 0 ? void 0 : options.xStartAngle;
_this.yStartAngle = options === null || options === void 0 ? void 0 : options.yStartAngle;
_this.totalAngle = options === null || options === void 0 ? void 0 : options.totalAngle;
_this.lengthScale = options === null || options === void 0 ? void 0 : options.lengthScale;
_this.centerPoint = options === null || options === void 0 ? void 0 : options.centerPoint;
_this.innerRadius = options === null || options === void 0 ? void 0 : options.innerRadius;
_this.resetRanges = (_a = options === null || options === void 0 ? void 0 : options.resetRanges) !== null && _a !== void 0 ? _a : _this.resetRanges;
_this.resetStartAngles = (_b = options === null || options === void 0 ? void 0 : options.resetStartAngles) !== null && _b !== void 0 ? _b : _this.resetStartAngles;
_this.resetTotalAngle = (_c = options === null || options === void 0 ? void 0 : options.resetTotalAngle) !== null && _c !== void 0 ? _c : _this.resetTotalAngle;
_this.resetLengthScale = (_d = options === null || options === void 0 ? void 0 : options.resetLengthScale) !== null && _d !== void 0 ? _d : _this.resetLengthScale;
_this.resetCenterPoint = (_e = options === null || options === void 0 ? void 0 : options.resetCenterPoint) !== null && _e !== void 0 ? _e : _this.resetCenterPoint;
_this.resetInnerRadius = (_f = options === null || options === void 0 ? void 0 : options.resetInnerRadius) !== null && _f !== void 0 ? _f : _this.resetInnerRadius;
if (!(options === null || options === void 0 ? void 0 : options.easingFunction)) {
_this.easingFunction = EasingFunctions_1.easing.outCubic;
}
return _this;
}
Object.defineProperty(PolarZoomExtentsModifier.prototype, "modifierType", {
/** @inheritDoc */
get: function () {
return ModifierType_1.EModifierType.Chart2DPolarModifier;
},
enumerable: false,
configurable: true
});
PolarZoomExtentsModifier.prototype.getAngularAxis = function () {
var xAxis = this.xAxis;
if (xAxis.isAngular) {
return xAxis;
}
else {
return this.yAxis;
}
};
PolarZoomExtentsModifier.prototype.getRadialAxis = function () {
var yAxis = this.yAxis;
if (!yAxis.isAngular) {
return yAxis;
}
else {
return this.xAxis;
}
};
/** @inheritDoc */
PolarZoomExtentsModifier.prototype.onAttach = function () {
_super.prototype.onAttach.call(this);
var xAxis = this.xAxis;
var yAxis = this.yAxis;
if (this.xStartAngle === undefined)
this.xStartAngle = xAxis.startAngle;
if (this.yStartAngle === undefined)
this.yStartAngle = yAxis.startAngle;
if (this.totalAngle === undefined)
this.totalAngle = this.getAngularAxis().totalAngle;
if (this.lengthScale === undefined)
this.lengthScale = this.getRadialAxis().lengthScale;
if (this.centerPoint === undefined) {
this.centerPoint = new Point_1.Point(xAxis.xCenterOffset, xAxis.yCenterOffset);
}
if (this.innerRadius === undefined)
this.innerRadius = this.getRadialAxis().innerRadius;
};
/** @inheritDoc */
PolarZoomExtentsModifier.prototype.modifierDoubleClick = function (args) {
var _this = this;
var scs = this.parentSurface;
if (!scs)
return;
var xAxis = this.xAxis;
var yAxis = this.yAxis;
// Visible Ranges
if (this.resetRanges) {
if (!this.onZoomExtents || this.onZoomExtents(scs)) {
switch (this.xyDirection) {
case XyDirection_1.EXyDirection.XyDirection:
scs.zoomExtents(this.animationDuration, this.easingFunction, function () {
return scs.setZoomState(ZoomState_1.EZoomState.AtExtents);
});
break;
case XyDirection_1.EXyDirection.XDirection:
scs.zoomExtentsX(this.animationDuration, this.easingFunction);
break;
case XyDirection_1.EXyDirection.YDirection:
scs.zoomExtentsY(this.animationDuration, this.easingFunction);
break;
}
}
}
// Angles
var xStartAngle0 = xAxis.startAngle;
var yStartAngle0 = yAxis.startAngle;
var totalAngle0 = this.getAngularAxis().totalAngle;
var xStartAngle1 = this.resetStartAngles ? this.xStartAngle : xStartAngle0;
var yStartAngle1 = this.resetStartAngles ? this.yStartAngle : yStartAngle0;
var totalAngle1 = this.resetTotalAngle ? this.totalAngle : totalAngle0;
// RESET Scale
var lengthScale0 = this.getRadialAxis().lengthScale;
var lengthScale1 = this.resetLengthScale ? this.lengthScale : lengthScale0;
// RESET Center Point
// we consider xAxis and yAxis center point is the same
var xAxisXCenterOffset0 = xAxis.xCenterOffset;
var xAxisYCenterOffset0 = xAxis.yCenterOffset;
var xAxisXCenterOffset1 = this.resetCenterPoint ? this.centerPoint.x : xAxisXCenterOffset0;
var xAxisYCenterOffset1 = this.resetCenterPoint ? this.centerPoint.y : xAxisYCenterOffset0;
// RESET inner radius
var innerRadius0 = this.getRadialAxis().innerRadius;
var innerRadius1 = this.resetInnerRadius ? this.innerRadius : innerRadius0;
var duration = this.isAnimated ? this.animationDuration : 0;
var ease = this.easingFunction;
args.handled = true;
var animation = new GenericAnimation_1.GenericAnimation({
from: {
xStartAngle: xStartAngle0,
yStartAngle: yStartAngle0,
totalAngle: totalAngle0,
lengthScale: lengthScale0,
xAxisXCenterOffset: xAxisXCenterOffset0,
xAxisYCenterOffset: xAxisYCenterOffset0,
innerRadius: innerRadius0
},
to: {
xStartAngle: xStartAngle1,
yStartAngle: yStartAngle1,
totalAngle: totalAngle1,
lengthScale: lengthScale1,
xAxisXCenterOffset: xAxisXCenterOffset1,
xAxisYCenterOffset: xAxisYCenterOffset1,
innerRadius: innerRadius1
},
duration: duration,
ease: ease,
onAnimate: function (from, to, progress) {
var xStartAngleCur = DoubleAnimator_1.DoubleAnimator.interpolate(from.xStartAngle, to.xStartAngle, progress);
var yStartAngleCur = DoubleAnimator_1.DoubleAnimator.interpolate(from.yStartAngle, to.yStartAngle, progress);
var totalAngleCur = DoubleAnimator_1.DoubleAnimator.interpolate(from.totalAngle, to.totalAngle, progress);
var lengthScaleCur = DoubleAnimator_1.DoubleAnimator.interpolate(from.lengthScale, to.lengthScale, progress);
xAxis.startAngle = xStartAngleCur;
yAxis.startAngle = yStartAngleCur;
var angularAxis = _this.getAngularAxis();
angularAxis.totalAngle = totalAngleCur;
_this.getRadialAxis().lengthScale = lengthScaleCur;
var xAxisXCenterOffsetCur = DoubleAnimator_1.DoubleAnimator.interpolate(from.xAxisXCenterOffset, to.xAxisXCenterOffset, progress);
var xAxisYCenterOffsetCur = DoubleAnimator_1.DoubleAnimator.interpolate(from.xAxisYCenterOffset, to.xAxisYCenterOffset, progress);
var innerRadiusCur = DoubleAnimator_1.DoubleAnimator.interpolate(from.innerRadius, to.innerRadius, progress);
angularAxis.xCenterOffset = xAxisXCenterOffsetCur;
angularAxis.yCenterOffset = xAxisYCenterOffsetCur;
_this.getRadialAxis().innerRadius = innerRadiusCur;
}
});
scs.addAnimation(animation);
};
PolarZoomExtentsModifier.prototype.toJSON = function () {
var json = _super.prototype.toJSON.call(this);
var options = {
centerPoint: this.centerPoint,
innerRadius: this.innerRadius,
lengthScale: this.lengthScale,
resetCenterPoint: this.resetCenterPoint,
resetInnerRadius: this.resetInnerRadius,
resetLengthScale: this.resetLengthScale,
resetRanges: this.resetRanges,
resetStartAngles: this.resetStartAngles,
resetTotalAngle: this.resetTotalAngle,
totalAngle: this.totalAngle,
xStartAngle: this.xStartAngle,
yStartAngle: this.yStartAngle
};
Object.assign(json.options, options);
return json;
};
return PolarZoomExtentsModifier;
}(ZoomExtentsModifier_1.ZoomExtentsModifier));
exports.PolarZoomExtentsModifier = PolarZoomExtentsModifier;