scichart
Version:
Fast WebGL JavaScript Charting Library and Framework
177 lines (176 loc) • 8.78 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 __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LegendModifier3D = void 0;
var EventHandler_1 = require("../../Core/EventHandler");
var ChartModifierType_1 = require("../../types/ChartModifierType");
var ChartModifierBase3D_1 = require("./ChartModifierBase3D");
var SciChart3DLegend_1 = require("../../Charting/Visuals/Legend/SciChart3DLegend");
/**
* The LegendModifier3D provides interactive legend behavior on a 3D {@link SciChart3DSurface}
* within SciChart - High Performance {@link https://www.scichart.com/javascript-chart-features | JavaScript Charts}
* @remarks
*
* To apply the LegendModifier3D to a {@link SciChart3DSurface} and add tooltip behavior,
* use the following code:
*
* ```ts
* const sciChartSurface: SciChart3DSurface;
* sciChartSurface.chartModifiers.add(new LegendModifier3D());
* ```
*
* ---
* 📚 Docs: todo
*/
var LegendModifier3D = /** @class */ (function (_super) {
__extends(LegendModifier3D, _super);
/**
* Creates an instance of the LegendModifier3D
* @param options Optional parameters {@link ILegendModifier3DOptions} used to configure the modifier
*
* ---
* 📚 Docs: todo
*/
function LegendModifier3D(options) {
var _this = this;
var _a;
_this = _super.call(this, options) || this;
_this._legendOptions = {};
_this.type = ChartModifierType_1.EChart3DModifierType.Legend;
/**
* An event handler raised when a {@link SciChart3DLegend} row checkbox is checked or unchecked
*/
_this.isCheckedChanged = new EventHandler_1.EventHandler();
_this._legendOptions = __assign({}, options);
_this.legendItemCheckedChanged = _this.legendItemCheckedChanged.bind(_this);
_this.sciChart3DLegend = (_a = options === null || options === void 0 ? void 0 : options.legend) !== null && _a !== void 0 ? _a : new SciChart3DLegend_1.SciChart3DLegend(options);
_this.applyLegendOptions(_this.sciChart3DLegend, options);
return _this;
}
LegendModifier3D.prototype.applyLegendOptions = function (legend, options) {
var _a, _b, _c, _d, _e, _f;
legend.showCheckboxes = (_a = options === null || options === void 0 ? void 0 : options.showCheckboxes) !== null && _a !== void 0 ? _a : legend.showCheckboxes;
legend.showSeriesMarkers = (_b = options === null || options === void 0 ? void 0 : options.showSeriesMarkers) !== null && _b !== void 0 ? _b : legend.showSeriesMarkers;
legend.margin = (_c = options === null || options === void 0 ? void 0 : options.margin) !== null && _c !== void 0 ? _c : legend.margin;
legend.orientation = (_d = options === null || options === void 0 ? void 0 : options.orientation) !== null && _d !== void 0 ? _d : legend.orientation;
legend.placement = (_e = options === null || options === void 0 ? void 0 : options.placement) !== null && _e !== void 0 ? _e : legend.placement;
legend.showLegend = (_f = options === null || options === void 0 ? void 0 : options.showLegend) !== null && _f !== void 0 ? _f : legend.showLegend;
legend.legendItemCheckedChangedCallback = this.legendItemCheckedChanged;
if (options === null || options === void 0 ? void 0 : options.isCheckedChangedCallback) {
this.isCheckedChanged.subscribe(function (arg) {
return options.isCheckedChangedCallback(arg.series, arg.isChecked);
});
}
};
/** @inheritDoc */
LegendModifier3D.prototype.applyTheme = function (themeProvider) {
var _a;
_super.prototype.applyTheme.call(this, themeProvider);
(_a = this.sciChart3DLegend) === null || _a === void 0 ? void 0 : _a.applyTheme();
};
/** @inheritDoc */
LegendModifier3D.prototype.onParentSurfaceRendered = function () {
_super.prototype.onParentSurfaceRendered.call(this);
};
/** @inheritDoc */
LegendModifier3D.prototype.onAttach = function () {
var _a;
_super.prototype.onAttach.call(this);
if (!this.sciChart3DLegend) {
this.sciChart3DLegend = (_a = this._legendOptions.legend) !== null && _a !== void 0 ? _a : new SciChart3DLegend_1.SciChart3DLegend(this._legendOptions);
this.applyLegendOptions(this.sciChart3DLegend, this._legendOptions);
}
this.sciChart3DLegend.attachTo(this.parentSurface);
this.sciChart3DLegend.setRenderableSeriesArray(this.getIncludedRenderableSeries());
};
/** @inheritDoc */
LegendModifier3D.prototype.onDetach = function () {
var _a, _b;
if (this.sciChart3DLegend) {
this._legendOptions.margin = this.sciChart3DLegend.margin;
this._legendOptions.orientation = this.sciChart3DLegend.orientation;
this._legendOptions.placement = this.sciChart3DLegend.placement;
this._legendOptions.showCheckboxes = this.sciChart3DLegend.showCheckboxes;
this._legendOptions.showLegend = this.sciChart3DLegend.showLegend;
this._legendOptions.showSeriesMarkers = this.sciChart3DLegend.showSeriesMarkers;
}
_super.prototype.onDetach.call(this);
(_a = this.sciChart3DLegend) === null || _a === void 0 ? void 0 : _a.setRenderableSeriesArray([]);
(_b = this.sciChart3DLegend) === null || _b === void 0 ? void 0 : _b.detach();
this.sciChart3DLegend = undefined;
};
/** @inheritDoc */
LegendModifier3D.prototype.includeSeries = function (series, isIncluded) {
var _a;
if (_super.prototype.includeSeries.call(this, series, isIncluded)) {
if (this.isAttached) {
this.sciChart3DLegend.setRenderableSeriesArray(this.getIncludedRenderableSeries());
}
(_a = this.parentSurface) === null || _a === void 0 ? void 0 : _a.invalidateElement();
return true;
}
return false;
};
/**
* Tests if the series is included or excluded
*/
LegendModifier3D.prototype.testIsIncludedSeries = function (series) {
return this.includedSeries.testIsIncluded(series.id);
};
/** @inheritDoc */
LegendModifier3D.prototype.toJSON = function () {
var json = _super.prototype.toJSON.call(this);
var options = {
margin: this.sciChart3DLegend.margin,
orientation: this.sciChart3DLegend.orientation,
placement: this.sciChart3DLegend.placement,
showCheckboxes: this.sciChart3DLegend.showCheckboxes,
showLegend: this.sciChart3DLegend.showLegend,
showSeriesMarkers: this.sciChart3DLegend.showSeriesMarkers
};
Object.assign(json.options, options);
return json;
};
/** @inheritDoc */
LegendModifier3D.prototype.delete = function () {
_super.prototype.delete.call(this);
this.onDetach();
};
/**
* Callback called from inner {@link SciChart3DLegend} when a checkbox is checked or unchecked
* @param series
* @param isChecked
* @protected
*/
LegendModifier3D.prototype.legendItemCheckedChanged = function (series, isChecked) {
var _a;
(_a = this.isCheckedChanged) === null || _a === void 0 ? void 0 : _a.raiseEvent({ series: series, isChecked: isChecked });
};
return LegendModifier3D;
}(ChartModifierBase3D_1.ChartModifierBase3D));
exports.LegendModifier3D = LegendModifier3D;