UNPKG

scichart

Version:

Fast WebGL JavaScript Charting Library and Framework

153 lines (152 loc) 7.78 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 __()); }; })(); var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PolarMouseWheelZoomModifier = void 0; var ChartModifierType_1 = require("../../../types/ChartModifierType"); var ModifierType_1 = require("../../../types/ModifierType"); var XyDirection_1 = require("../../../types/XyDirection"); var ModifierMouseArgKey_1 = require("../../../types/ChartModifiers/ModifierMouseArgKey"); var MouseWheelZoomModifier_1 = require("../MouseWheelZoomModifier"); var NumberRange_1 = require("../../../Core/NumberRange"); /** * The PolarMouseWheelZoomModifier provides Mouse wheel zooming behavior on a 2D {@link SciChartPolarSurface} * within SciChart - High Performance {@link https://www.scichart.com/javascript-chart-features | JavaScript Charts} * @remarks * * To apply the PolarMouseWheelZoomModifier to a {@link SciChartPolarSurface} and add Mouse-wheel zoom behavior, * use the following code: * * ```ts * const sciChartSurface: SciChartPolarSurface; * sciChartSurface.chartModifiers.add(new PolarMouseWheelZoomModifier()); * ``` * * The speed of mouse-wheel zoom can be modified via the {@link PolarMouseWheelZoomModifier.growFactor} property. * * --- * 📚 Docs: {@link https://www.scichart.com/documentation/js/v4/2d-charts/chart-modifier-api/polar-modifiers/polar-mouse-wheel-zoom-modifier/} */ var PolarMouseWheelZoomModifier = /** @class */ (function (_super) { __extends(PolarMouseWheelZoomModifier, _super); /** * Creates an instance of PolarMouseWheelZoomModifier * @param options Optional parameters to configure the modifier via {@link IPolarMouseWheelZoomModifierOptions} * * --- * 📚 Docs: {@link https://www.scichart.com/documentation/js/v4/2d-charts/chart-modifier-api/polar-modifiers/polar-mouse-wheel-zoom-modifier/} */ function PolarMouseWheelZoomModifier(options) { var _this = this; var _a, _b, _c, _d; var _e = options !== null && options !== void 0 ? options : {}, executeCondition = _e.executeCondition, secondaryExecuteCondition = _e.secondaryExecuteCondition, rest = __rest(_e, ["executeCondition", "secondaryExecuteCondition"]); _this = _super.call(this, rest) || this; _this.type = ChartModifierType_1.EChart2DModifierType.PolarMouseWheelZoom; /** * Gets or sets the default action type */ _this.defaultActionType = MouseWheelZoomModifier_1.EActionType.Zoom; /** * If True uses length scale zoom on the radial axis, otherwise uses visible range zoom. Default True */ _this.zoomSize = true; _this.defaultActionType = (_a = options === null || options === void 0 ? void 0 : options.defaultActionType) !== null && _a !== void 0 ? _a : _this.defaultActionType; _this.executeCondition = (_b = options === null || options === void 0 ? void 0 : options.executeCondition) !== null && _b !== void 0 ? _b : { key: ModifierMouseArgKey_1.EModifierMouseArgKey.None }; _this.secondaryExecuteCondition = (_c = options === null || options === void 0 ? void 0 : options.secondaryExecuteCondition) !== null && _c !== void 0 ? _c : { key: ModifierMouseArgKey_1.EModifierMouseArgKey.Ctrl }; _this.zoomSize = (_d = options === null || options === void 0 ? void 0 : options.zoomSize) !== null && _d !== void 0 ? _d : _this.zoomSize; return _this; } Object.defineProperty(PolarMouseWheelZoomModifier.prototype, "modifierType", { /** @inheritDoc */ get: function () { return ModifierType_1.EModifierType.Chart2DPolarModifier; }, enumerable: false, configurable: true }); /** @inheritDoc */ PolarMouseWheelZoomModifier.prototype.modifierMouseWheel = function (args) { var _a = this.checkExecuteConditions(args), isPrimary = _a.isPrimary, isSecondary = _a.isSecondary; if (isPrimary) { this.actionType = this.defaultActionType; } else if (isSecondary) { this.actionType = this.defaultActionType === MouseWheelZoomModifier_1.EActionType.Pan ? MouseWheelZoomModifier_1.EActionType.Zoom : MouseWheelZoomModifier_1.EActionType.Pan; } else { this.actionType = undefined; } this.xyDirection = XyDirection_1.EXyDirection.XyDirection; _super.prototype.modifierMouseWheel.call(this, args); }; /** @inheritDoc */ PolarMouseWheelZoomModifier.prototype.performPan = function (wheelDelta) { var _this = this; var anyUpdated = false; if ([XyDirection_1.EXyDirection.XDirection, XyDirection_1.EXyDirection.XyDirection].includes(this.xyDirection)) { this.getIncludedXAxis().forEach(function (axis) { var size = Math.PI; var pixels = wheelDelta * _this.growFactor * size; axis.startAngle += pixels; anyUpdated = true; }); } if ([XyDirection_1.EXyDirection.YDirection, XyDirection_1.EXyDirection.XyDirection].includes(this.xyDirection)) { this.getIncludedYAxis().forEach(function (axis) { var size = Math.PI; var pixels = wheelDelta * _this.growFactor * size; axis.startAngle += pixels; anyUpdated = true; }); } return anyUpdated; }; PolarMouseWheelZoomModifier.prototype.toJSON = function () { var json = _super.prototype.toJSON.call(this); var options = { zoomSize: this.zoomSize, defaultActionType: this.defaultActionType }; Object.assign(json.options, options); return json; }; PolarMouseWheelZoomModifier.prototype.growBy = function (mousePoint, axis, fraction) { var polarAxis = axis; if (!polarAxis.isAngular) { if (!this.zoomSize) { var _a = polarAxis.visibleRange, min = _a.min, max = _a.max; var newMax = max * (1 + fraction); polarAxis.visibleRange = new NumberRange_1.NumberRange(min, newMax); } else { polarAxis.lengthScale -= fraction; } } }; return PolarMouseWheelZoomModifier; }(MouseWheelZoomModifier_1.MouseWheelZoomModifier)); exports.PolarMouseWheelZoomModifier = PolarMouseWheelZoomModifier;