@apptane/react-ui-charts
Version:
Chart components in Apptane React UI framework
62 lines (60 loc) • 1.6 kB
JavaScript
import { useMemo } from "react";
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
/**
* Generates gradient definitions for series.
*/
export function useGradientDefs(data, required) {
return useMemo(() => {
if (data && data.length > 0 && required) {
const gradientsMap = new Map();
data.forEach(_ref => {
let {
hiColor,
loColor,
gradientId
} = _ref;
if (!gradientsMap.has(gradientId)) {
gradientsMap.set(gradientId, {
id: gradientId,
stops: [{
offset: 0,
color: hiColor,
opacity: 0.6
}, {
offset: 100,
color: loColor,
opacity: 0.3
}]
});
gradientsMap.set(gradientId + "-active", {
id: gradientId + "-active",
stops: [{
offset: 0,
color: hiColor,
opacity: 0.9
}, {
offset: 100,
color: loColor,
opacity: 0.9
}]
});
}
});
return Array.from(gradientsMap.values()).map(d => _jsx("linearGradient", {
id: d.id,
x1: 0,
x2: 0,
y1: 0,
y2: 1,
children: d.stops.map((s, index) => _jsx("stop", {
offset: "".concat(s.offset, "%"),
stopColor: s.color,
stopOpacity: s.opacity
}, "_".concat(index)))
}, d.id));
} else {
return null;
}
}, [data, required]);
}
//# sourceMappingURL=gradients.js.map