@spscommerce/ds-react-charts 5.13.0 → 5.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs.js +87 -92
- package/lib/index.es.js +107 -113
- package/lib/lineChart/SpsLineChart.d.ts +11 -10
- package/package.json +9 -9
package/lib/index.es.js
CHANGED
|
@@ -20,6 +20,7 @@ var __spreadProps = (a2, b) => __defProps(a2, __getOwnPropDescs(b));
|
|
|
20
20
|
import * as React from "react";
|
|
21
21
|
import React__default, { useMemo, useState, useRef, useEffect, useContext, useCallback, createContext } from "react";
|
|
22
22
|
import * as DSColors from "@spscommerce/ds-colors";
|
|
23
|
+
import { colors } from "@spscommerce/ds-colors";
|
|
23
24
|
import { SpsTooltip, useElementId } from "@spscommerce/ds-react";
|
|
24
25
|
import { code } from "@spscommerce/utils";
|
|
25
26
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
@@ -3028,10 +3029,10 @@ var interpolateRgb = function rgbGamma(y2) {
|
|
|
3028
3029
|
return rgb$1;
|
|
3029
3030
|
}(1);
|
|
3030
3031
|
function rgbSpline(spline) {
|
|
3031
|
-
return function(
|
|
3032
|
-
var n2 =
|
|
3032
|
+
return function(colors2) {
|
|
3033
|
+
var n2 = colors2.length, r2 = new Array(n2), g = new Array(n2), b = new Array(n2), i2, color2;
|
|
3033
3034
|
for (i2 = 0; i2 < n2; ++i2) {
|
|
3034
|
-
color2 = rgb(
|
|
3035
|
+
color2 = rgb(colors2[i2]);
|
|
3035
3036
|
r2[i2] = color2.r || 0;
|
|
3036
3037
|
g[i2] = color2.g || 0;
|
|
3037
3038
|
b[i2] = color2.b || 0;
|
|
@@ -8776,7 +8777,7 @@ function SpsStackedHorizontalBarChart(props) {
|
|
|
8776
8777
|
}
|
|
8777
8778
|
return `rgb(${r2}, ${g}, ${b})`;
|
|
8778
8779
|
}
|
|
8779
|
-
const
|
|
8780
|
+
const colors2 = chartData.map((c2) => c2.color);
|
|
8780
8781
|
const keys2 = chartData.map((c2) => c2.label);
|
|
8781
8782
|
const values = chartData.map((c2) => c2.value);
|
|
8782
8783
|
const valuesSum = values.reduce((pv, cv) => pv + cv, 0);
|
|
@@ -8793,7 +8794,7 @@ function SpsStackedHorizontalBarChart(props) {
|
|
|
8793
8794
|
});
|
|
8794
8795
|
const legendScale = createOrdinalScale$2({
|
|
8795
8796
|
domain: keys2.map((c2) => `${c2}: ${(useAbsoluteLegend ? absoluteData : relativeData)[0][c2]}%`),
|
|
8796
|
-
range: [...
|
|
8797
|
+
range: [...colors2]
|
|
8797
8798
|
});
|
|
8798
8799
|
const xMax = chartWidth - margin.left - margin.right;
|
|
8799
8800
|
const yMax = chartHeight - margin.top - margin.bottom;
|
|
@@ -19875,41 +19876,44 @@ function LineSeries(props) {
|
|
|
19875
19876
|
}
|
|
19876
19877
|
const propsDoc = {
|
|
19877
19878
|
lines: "LinesChartProps[]",
|
|
19878
|
-
|
|
19879
|
-
|
|
19880
|
-
|
|
19881
|
-
|
|
19882
|
-
|
|
19883
|
-
|
|
19879
|
+
barTooltip: "(props: LineTooltipProps) => JSX.Element",
|
|
19880
|
+
grid: "GridProps",
|
|
19881
|
+
labels: "Array<string>",
|
|
19882
|
+
xAxis: "CommonProps<AxisScale>",
|
|
19883
|
+
xScale: "ScaleConfig<AxisScaleOutput, any, any>",
|
|
19884
|
+
yAxis: "CommonProps<AxisScale>",
|
|
19885
|
+
yScale: "ScaleConfig<AxisScaleOutput, any, any>"
|
|
19884
19886
|
};
|
|
19885
19887
|
const propTypes = {
|
|
19888
|
+
barTooltip: fun(),
|
|
19889
|
+
grid: impl(),
|
|
19890
|
+
labels: propTypes$4.exports.arrayOf(propTypes$4.exports.string).isRequired,
|
|
19886
19891
|
lines: propTypes$4.exports.arrayOf(impl()),
|
|
19887
|
-
curveType: "linear",
|
|
19888
|
-
yAxis: impl(),
|
|
19889
19892
|
xAxis: impl(),
|
|
19890
|
-
|
|
19891
|
-
|
|
19892
|
-
|
|
19893
|
+
xScale: impl().isRequired,
|
|
19894
|
+
yAxis: impl(),
|
|
19895
|
+
yScale: impl().isRequired
|
|
19893
19896
|
};
|
|
19894
19897
|
function SpsLineChart(props) {
|
|
19895
19898
|
const componentKey = useElementId(null);
|
|
19896
19899
|
const {
|
|
19897
19900
|
lines,
|
|
19898
|
-
|
|
19899
|
-
|
|
19901
|
+
xScale,
|
|
19902
|
+
yScale,
|
|
19900
19903
|
xAxis,
|
|
19901
|
-
|
|
19902
|
-
|
|
19904
|
+
yAxis,
|
|
19905
|
+
grid,
|
|
19906
|
+
labels,
|
|
19903
19907
|
barTooltip: BarTooltip
|
|
19904
19908
|
} = props;
|
|
19905
19909
|
const accessors = {
|
|
19906
19910
|
xAccessor: (d) => d.x,
|
|
19907
19911
|
yAccessor: (d) => d.y
|
|
19908
19912
|
};
|
|
19909
|
-
const tickFormat2 = (i2) =>
|
|
19913
|
+
const tickFormat2 = (i2) => labels[i2];
|
|
19910
19914
|
const legendScale = createOrdinalScale$2({
|
|
19911
19915
|
domain: lines.map((c2) => c2.name),
|
|
19912
|
-
range: lines.map((c2) => c2.color)
|
|
19916
|
+
range: lines.map((c2) => colors[c2.color])
|
|
19913
19917
|
});
|
|
19914
19918
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Ordinal, {
|
|
19915
19919
|
className: "fs-12 lh-18 gray600",
|
|
@@ -19929,37 +19933,32 @@ function SpsLineChart(props) {
|
|
|
19929
19933
|
}
|
|
19930
19934
|
}), /* @__PURE__ */ React.createElement(XYChart, {
|
|
19931
19935
|
height: 300,
|
|
19932
|
-
xScale
|
|
19933
|
-
yScale
|
|
19934
|
-
}, /* @__PURE__ */ React.createElement(Axis, {
|
|
19935
|
-
hideTicks: hideTicksX,
|
|
19936
|
+
xScale,
|
|
19937
|
+
yScale
|
|
19938
|
+
}, /* @__PURE__ */ React.createElement(Axis, __spreadValues({
|
|
19936
19939
|
strokeWidth: "1",
|
|
19937
19940
|
orientation: "bottom",
|
|
19938
19941
|
tickFormat: tickFormat2
|
|
19939
|
-
}), /* @__PURE__ */ React.createElement(Axis, {
|
|
19940
|
-
hideTicks: hideTicksY,
|
|
19942
|
+
}, xAxis)), /* @__PURE__ */ React.createElement(Axis, __spreadValues({
|
|
19941
19943
|
orientation: "left"
|
|
19942
|
-
}), /* @__PURE__ */ React.createElement(Grid, {
|
|
19943
|
-
rows: yAxis == null ? void 0 : yAxis.gridLines,
|
|
19944
|
-
columns: xAxis == null ? void 0 : xAxis.gridLines
|
|
19945
|
-
}), lines.map((line2, index2) => /* @__PURE__ */ React.createElement(React.Fragment, {
|
|
19944
|
+
}, yAxis)), /* @__PURE__ */ React.createElement(Grid, __spreadValues({}, grid)), lines.map((line2, index2) => /* @__PURE__ */ React.createElement(React.Fragment, {
|
|
19946
19945
|
key: `${componentKey.current}${index2}`
|
|
19947
19946
|
}, /* @__PURE__ */ React.createElement(GlyphSeries, __spreadValues({
|
|
19948
19947
|
dataKey: line2.name,
|
|
19949
|
-
colorAccessor: () => line2.color,
|
|
19948
|
+
colorAccessor: () => colors[line2.color],
|
|
19950
19949
|
data: [line2.data]
|
|
19951
19950
|
}, accessors)), /* @__PURE__ */ React.createElement(LineSeries, __spreadValues({
|
|
19952
19951
|
dataKey: line2.name,
|
|
19953
|
-
stroke: line2.color,
|
|
19952
|
+
stroke: colors[line2.color],
|
|
19954
19953
|
strokeDasharray: line2.strokeDashArray ? "4,3" : "",
|
|
19955
19954
|
data: line2.data
|
|
19956
19955
|
}, accessors)))), /* @__PURE__ */ React.createElement(Tooltip, {
|
|
19957
19956
|
snapTooltipToDatumX: true,
|
|
19958
19957
|
snapTooltipToDatumY: true,
|
|
19959
19958
|
className: "bg-dark white",
|
|
19960
|
-
renderTooltip: ({ tooltipData }) => /* @__PURE__ */ React.createElement(
|
|
19959
|
+
renderTooltip: ({ tooltipData }) => /* @__PURE__ */ React.createElement(React.Fragment, null, BarTooltip && /* @__PURE__ */ React.createElement(BarTooltip, {
|
|
19961
19960
|
yAxisName: tooltipData.nearestDatum.key,
|
|
19962
|
-
xLineName:
|
|
19961
|
+
xLineName: labels[accessors.xAccessor(tooltipData.nearestDatum.datum)],
|
|
19963
19962
|
value: accessors.yAccessor(tooltipData.nearestDatum.datum)
|
|
19964
19963
|
}))
|
|
19965
19964
|
})));
|
|
@@ -19972,86 +19971,81 @@ Object.assign(SpsLineChart, {
|
|
|
19972
19971
|
const SpsLineChartExamples = {
|
|
19973
19972
|
basic: {
|
|
19974
19973
|
label: "Basic",
|
|
19975
|
-
description: code
|
|
19976
|
-
<p>Line chart example.</p>
|
|
19977
|
-
`,
|
|
19974
|
+
description: () => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, "Line chart example."), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("code", null, "<grid>"), " allows override grid property. Optional. Type of ", /* @__PURE__ */ React.createElement("code", null, "GridProps"), " which comes from", /* @__PURE__ */ React.createElement("code", null, "@visx/xychart/lib/components/grid/Grid"), " package, which is a peer dependency of our React components."), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("code", null, "<xAxis>"), " and ", /* @__PURE__ */ React.createElement("code", null, "<yAxis>"), " allow override X/Y axes property. Optional. Type of", /* @__PURE__ */ React.createElement("code", null, "CommonProps<AxisScale>"), " which comes from", /* @__PURE__ */ React.createElement("code", null, "@visx/axis/lib/types"), " package, which is a peer dependency of our React components."), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("code", null, "<xScale>"), " and ", /* @__PURE__ */ React.createElement("code", null, "<yScale>"), " allow override scale configuration for X/Y axes. Type of", /* @__PURE__ */ React.createElement("code", null, "ScaleConfig<AxisScaleOutput, any, any>"), " comes from", /* @__PURE__ */ React.createElement("code", null, "@visx/scale"), " and ", /* @__PURE__ */ React.createElement("code", null, "@visx/axis"), " packages, which is a peer dependency of our React components.")),
|
|
19978
19975
|
examples: {
|
|
19979
19976
|
basic: {
|
|
19980
19977
|
react: code`
|
|
19981
|
-
|
|
19982
|
-
|
|
19983
|
-
|
|
19984
|
-
|
|
19985
|
-
|
|
19986
|
-
|
|
19987
|
-
|
|
19988
|
-
|
|
19989
|
-
|
|
19990
|
-
|
|
19991
|
-
|
|
19992
|
-
|
|
19993
|
-
|
|
19994
|
-
|
|
19995
|
-
|
|
19996
|
-
|
|
19997
|
-
|
|
19998
|
-
|
|
19999
|
-
|
|
20000
|
-
|
|
20001
|
-
|
|
20002
|
-
|
|
20003
|
-
|
|
20004
|
-
|
|
20005
|
-
|
|
20006
|
-
|
|
20007
|
-
|
|
20008
|
-
|
|
20009
|
-
|
|
20010
|
-
|
|
20011
|
-
|
|
20012
|
-
|
|
20013
|
-
|
|
20014
|
-
|
|
20015
|
-
|
|
20016
|
-
|
|
20017
|
-
|
|
20018
|
-
|
|
20019
|
-
|
|
20020
|
-
|
|
20021
|
-
|
|
20022
|
-
|
|
20023
|
-
|
|
20024
|
-
|
|
20025
|
-
|
|
20026
|
-
|
|
20027
|
-
|
|
20028
|
-
|
|
20029
|
-
|
|
20030
|
-
|
|
20031
|
-
|
|
20032
|
-
|
|
20033
|
-
|
|
20034
|
-
|
|
20035
|
-
|
|
20036
|
-
|
|
20037
|
-
|
|
20038
|
-
|
|
20039
|
-
|
|
20040
|
-
|
|
20041
|
-
|
|
20042
|
-
|
|
20043
|
-
|
|
20044
|
-
|
|
20045
|
-
|
|
20046
|
-
|
|
20047
|
-
|
|
20048
|
-
|
|
20049
|
-
|
|
20050
|
-
|
|
20051
|
-
|
|
20052
|
-
)
|
|
20053
|
-
}
|
|
20054
|
-
`
|
|
19978
|
+
function DemoComponent() {
|
|
19979
|
+
const lines = [
|
|
19980
|
+
{
|
|
19981
|
+
data: [
|
|
19982
|
+
{ x: 0, y: 30 },
|
|
19983
|
+
{ x: 1, y: 45 },
|
|
19984
|
+
{ x: 2, y: 85 },
|
|
19985
|
+
{ x: 3, y: 20 },
|
|
19986
|
+
{ x: 4, y: 10 },
|
|
19987
|
+
{ x: 5, y: 90 },
|
|
19988
|
+
{ x: 6, y: 30 },
|
|
19989
|
+
{ x: 7, y: 100 },
|
|
19990
|
+
{ x: 8, y: 70 },
|
|
19991
|
+
{ x: 9, y: 50 },
|
|
19992
|
+
],
|
|
19993
|
+
color: LineChartColors.ORANGE,
|
|
19994
|
+
name: "Line 1",
|
|
19995
|
+
strokeDashArray: true,
|
|
19996
|
+
},
|
|
19997
|
+
{
|
|
19998
|
+
data: [
|
|
19999
|
+
{ x: 0, y: 10 },
|
|
20000
|
+
{ x: 1, y: 30 },
|
|
20001
|
+
{ x: 2, y: 70 },
|
|
20002
|
+
{ x: 3, y: 70 },
|
|
20003
|
+
{ x: 4, y: 40 },
|
|
20004
|
+
{ x: 5, y: 90 },
|
|
20005
|
+
{ x: 6, y: 80 },
|
|
20006
|
+
{ x: 7, y: 80 },
|
|
20007
|
+
{ x: 8, y: 100 },
|
|
20008
|
+
{ x: 9, y: 30 },
|
|
20009
|
+
],
|
|
20010
|
+
color: LineChartColors.GREEN,
|
|
20011
|
+
name: "Line 2",
|
|
20012
|
+
},
|
|
20013
|
+
{
|
|
20014
|
+
data: [
|
|
20015
|
+
{ x: 0, y: 15 },
|
|
20016
|
+
{ x: 1, y: 40 },
|
|
20017
|
+
{ x: 2, y: 80 },
|
|
20018
|
+
{ x: 3, y: 40 },
|
|
20019
|
+
{ x: 4, y: 100 },
|
|
20020
|
+
{ x: 5, y: 40 },
|
|
20021
|
+
{ x: 6, y: 50 },
|
|
20022
|
+
{ x: 7, y: 10 },
|
|
20023
|
+
{ x: 8, y: 0 },
|
|
20024
|
+
{ x: 9, y: 20 },
|
|
20025
|
+
],
|
|
20026
|
+
color: LineChartColors.GREEN,
|
|
20027
|
+
name: "Line 3",
|
|
20028
|
+
},
|
|
20029
|
+
];
|
|
20030
|
+
const lineChartLabels = [
|
|
20031
|
+
'PRE', 'W1', 'W2', 'W3', 'W4', 'W5', 'W6', 'W7', 'W8', 'W9'
|
|
20032
|
+
];
|
|
20033
|
+
const BarTooltip = ({ yAxisName, xLineName, value }) => (
|
|
20034
|
+
<div className="font-weight-bold">{xLineName} <br /> {yAxisName}: {value}</div>
|
|
20035
|
+
);
|
|
20036
|
+
|
|
20037
|
+
return (
|
|
20038
|
+
<SpsLineChart
|
|
20039
|
+
barTooltip={ BarTooltip }
|
|
20040
|
+
grid={{ rows: false }}
|
|
20041
|
+
labels={ lineChartLabels }
|
|
20042
|
+
lines={lines}
|
|
20043
|
+
xScale={{ type: 'linear' }}
|
|
20044
|
+
yScale={{ type: 'linear' }}
|
|
20045
|
+
/>
|
|
20046
|
+
)
|
|
20047
|
+
}
|
|
20048
|
+
`
|
|
20055
20049
|
}
|
|
20056
20050
|
}
|
|
20057
20051
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import type { ScaleConfig } from "@visx/scale";
|
|
3
|
+
import type { CommonProps, AxisScale } from "@visx/axis/lib/types";
|
|
4
|
+
import type { AxisScaleOutput } from "@visx/axis";
|
|
5
|
+
import type { GridProps } from "@visx/xychart/lib/components/grid/Grid";
|
|
2
6
|
import type { LineChartColors } from "@spscommerce/ds-shared";
|
|
3
7
|
import * as PropTypes from "../prop-types";
|
|
4
8
|
export interface LinesChartProps {
|
|
@@ -7,22 +11,19 @@ export interface LinesChartProps {
|
|
|
7
11
|
color: LineChartColors;
|
|
8
12
|
strokeDashArray?: boolean;
|
|
9
13
|
}
|
|
10
|
-
export interface AxisType {
|
|
11
|
-
gridLines: boolean;
|
|
12
|
-
labels: string[];
|
|
13
|
-
}
|
|
14
14
|
export interface LineChartData {
|
|
15
15
|
x: number;
|
|
16
16
|
y: number;
|
|
17
17
|
}
|
|
18
18
|
declare const propTypes: {
|
|
19
|
-
lines: PropTypes.Requireable<LinesChartProps[]>;
|
|
20
|
-
curveType: string;
|
|
21
|
-
yAxis: PropTypes.Requireable<AxisType>;
|
|
22
|
-
xAxis: PropTypes.Requireable<AxisType>;
|
|
23
|
-
hideTicksX: PropTypes.Requireable<boolean>;
|
|
24
|
-
hideTicksY: PropTypes.Requireable<boolean>;
|
|
25
19
|
barTooltip: PropTypes.Requireable<(props: LineTooltipProps) => JSX.Element>;
|
|
20
|
+
grid: PropTypes.Requireable<GridProps>;
|
|
21
|
+
labels: PropTypes.Validator<string[]>;
|
|
22
|
+
lines: PropTypes.Requireable<LinesChartProps[]>;
|
|
23
|
+
xAxis: PropTypes.Requireable<CommonProps<AxisScale<AxisScaleOutput>>>;
|
|
24
|
+
xScale: PropTypes.Validator<ScaleConfig<AxisScaleOutput, any, any>>;
|
|
25
|
+
yAxis: PropTypes.Requireable<CommonProps<AxisScale<AxisScaleOutput>>>;
|
|
26
|
+
yScale: PropTypes.Validator<ScaleConfig<AxisScaleOutput, any, any>>;
|
|
26
27
|
};
|
|
27
28
|
export interface LineTooltipProps {
|
|
28
29
|
yAxisName?: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spscommerce/ds-react-charts",
|
|
3
3
|
"description": "SPS Design System React Chart components",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.14.1",
|
|
5
5
|
"author": "SPS Commerce",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"repository": "https://github.com/spscommerce/design-system/tree/main/packages/@spscommerce/ds-react-charts",
|
|
@@ -27,17 +27,17 @@
|
|
|
27
27
|
"react-spring": "^8.0.27"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@spscommerce/ds-colors": "5.
|
|
31
|
-
"@spscommerce/ds-shared": "5.
|
|
32
|
-
"@spscommerce/ds-react": "5.
|
|
33
|
-
"@spscommerce/utils": "5.
|
|
30
|
+
"@spscommerce/ds-colors": "5.14.1",
|
|
31
|
+
"@spscommerce/ds-shared": "5.14.1",
|
|
32
|
+
"@spscommerce/ds-react": "5.14.1",
|
|
33
|
+
"@spscommerce/utils": "5.14.1",
|
|
34
34
|
"react": "^16.9.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@spscommerce/ds-colors": "5.
|
|
38
|
-
"@spscommerce/ds-shared": "5.
|
|
39
|
-
"@spscommerce/ds-react": "5.
|
|
40
|
-
"@spscommerce/utils": "5.
|
|
37
|
+
"@spscommerce/ds-colors": "5.14.1",
|
|
38
|
+
"@spscommerce/ds-shared": "5.14.1",
|
|
39
|
+
"@spscommerce/ds-react": "5.14.1",
|
|
40
|
+
"@spscommerce/utils": "5.14.1",
|
|
41
41
|
"@testing-library/jest-dom": "^4.2.4",
|
|
42
42
|
"@testing-library/react": "^9.3.2",
|
|
43
43
|
"@types/react": "^16.9.0",
|