scichart-react
Version:
React wrapper for SciChart JS
46 lines • 2.38 kB
JavaScript
"use client";
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.SciChartNestedLegend = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const scichart_1 = require("scichart");
const SciChartSurfaceContext_1 = require("./SciChartSurfaceContext");
/**
* @experimental This is a draft version of the component. Recommended to use only as a reference.
*
* A component for placing an external placement Legend within {@link SciChartReact}.
* Adds a corresponding {@link LegendModifier} to the surface.
*
* @remarks The component is intended to be used as a child component of {@link SciChartReact}
*
* @param props {@link ISciChartNestedLegendProps} - are propagated to the underlying div element which which will be used as root for the legend
* @returns legend {@link JSX.Element}
*/
const SciChartNestedLegend = (props) => {
const { options } = props, divProps = __rest(props, ["options"]);
const legendPlacementDivRef = (0, react_1.useRef)(null);
const initResult = (0, react_1.useContext)(SciChartSurfaceContext_1.SciChartSurfaceContext);
const parentSurface = initResult === null || initResult === void 0 ? void 0 : initResult.sciChartSurface;
(0, react_1.useEffect)(() => {
const legendModifier = new scichart_1.LegendModifier(Object.assign(Object.assign({}, props === null || props === void 0 ? void 0 : props.options), { placementDivId: legendPlacementDivRef.current }));
parentSurface.chartModifiers.add(legendModifier);
return () => {
parentSurface.chartModifiers.remove(legendModifier, true);
};
}, [parentSurface]);
return (0, jsx_runtime_1.jsx)("div", Object.assign({}, divProps, { ref: legendPlacementDivRef }));
};
exports.SciChartNestedLegend = SciChartNestedLegend;
//# sourceMappingURL=SciChartLegendComponent.js.map
;