@redsift/charts 10.1.0-muiv5-alpha.4 → 10.1.0
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/index.d.ts +2 -2
- package/index.js +24 -12
- package/index.js.map +1 -1
- package/package.json +4 -4
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BrushBehavior, ScaleLinear as ScaleLinear$1, ScaleOrdinal, Arc as Arc$1, ScaleTime as ScaleTime$2, ScalePoint as ScalePoint$2, Line as Line$1 } from 'd3';
|
|
1
|
+
import { BrushBehavior, ScaleLinear as ScaleLinear$1, CountableTimeInterval, ScaleOrdinal, Arc as Arc$1, ScaleTime as ScaleTime$2, ScalePoint as ScalePoint$2, Line as Line$1 } from 'd3';
|
|
2
2
|
import * as _redsift_design_system from '@redsift/design-system';
|
|
3
3
|
import { ValueOf, Theme, Comp, ContainerProps } from '@redsift/design-system';
|
|
4
4
|
import { PieArcDatum } from 'd3-shape';
|
|
@@ -263,7 +263,7 @@ interface ScaleTypeToScale<Input, Output> {
|
|
|
263
263
|
type Scale<Input, Output> = ScaleTypeToScale<Input, Output>[keyof ScaleTypeToScale<Input, Output>];
|
|
264
264
|
type AnyScale = Scale<any, any>;
|
|
265
265
|
type ScaleWithBandwidth = ScaleBand<any> | ScalePoint<any>;
|
|
266
|
-
type TicksSpec = number | string | ScaleValue[];
|
|
266
|
+
type TicksSpec = number | string | ScaleValue[] | CountableTimeInterval;
|
|
267
267
|
|
|
268
268
|
type ChartDimensions = {
|
|
269
269
|
width: number;
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { brush, select, scaleOrdinal, zoom, interpolateRound, interpolate, scaleLinear, sum, scaleBand, extent, scaleTime, scalePoint, line, arc, pie, min, descending, scaleSqrt, max } from 'd3';
|
|
2
|
-
import { RedsiftColorPresentationBlueDefault, RedsiftColorPresentationGreyDark,
|
|
2
|
+
import { RedsiftColorPresentationBlueDefault, RedsiftColorPresentationGreyDark, RedsiftColorPresentationAquaDefault, RedsiftColorPresentationPinkDefault, RedsiftColorPresentationGreyDefault, RedsiftColorPresentationYellowDefault, RedsiftColorPresentationPurpleDefault, RedsiftColorPresentationGreenDefault, RedsiftColorPresentationBrownDefault, RedsiftColorPresentationRedDefault, RedsiftColorPresentationOrangeDefault, RedsiftColorPresentationGreenDark, RedsiftColorPresentationPinkDark, RedsiftColorPresentationAquaDark, RedsiftColorPresentationBrownDark, RedsiftColorPresentationRedDark, RedsiftColorPresentationYellowDark, RedsiftColorPresentationPurpleDark, RedsiftColorPresentationOrangeDark, RedsiftColorPresentationBlueDark, RedsiftColorPresentationGreenDarker, RedsiftColorPresentationPinkDarker, RedsiftColorPresentationAquaDarker, RedsiftColorPresentationBrownDarker, RedsiftColorPresentationRedDarker, RedsiftColorPresentationYellowDarker, RedsiftColorPresentationPurpleDarker, RedsiftColorPresentationOrangeDarker, RedsiftColorPresentationBlueDarker, RedsiftColorPresentationGreyDarker, RedsiftColorPresentationGreenDarkerer, RedsiftColorPresentationPinkDarkerer, RedsiftColorPresentationAquaDarkerer, RedsiftColorPresentationBrownDarkerer, RedsiftColorPresentationRedDarkerer, RedsiftColorPresentationYellowDarkerer, RedsiftColorPresentationPurpleDarkerer, RedsiftColorPresentationOrangeDarkerer, RedsiftColorPresentationBlueDarkerer, RedsiftColorPresentationGreyDarkerer, RedsiftColorPresentationGreenLight, RedsiftColorPresentationPinkLight, RedsiftColorPresentationAquaLight, RedsiftColorPresentationBrownLight, RedsiftColorPresentationRedLight, RedsiftColorPresentationYellowLight, RedsiftColorPresentationPurpleLight, RedsiftColorPresentationOrangeLight, RedsiftColorPresentationBlueLight, RedsiftColorPresentationGreyLight, RedsiftColorPresentationGreenLighter, RedsiftColorPresentationPinkLighter, RedsiftColorPresentationAquaLighter, RedsiftColorPresentationBrownLighter, RedsiftColorPresentationRedLighter, RedsiftColorPresentationYellowLighter, RedsiftColorPresentationPurpleLighter, RedsiftColorPresentationOrangeLighter, RedsiftColorPresentationBlueLighter, RedsiftColorPresentationGreyLighter, RedsiftColorPresentationGreenLighterer, RedsiftColorPresentationPinkLighterer, RedsiftColorPresentationAquaLighterer, RedsiftColorPresentationBrownLighterer, RedsiftColorPresentationRedLighterer, RedsiftColorPresentationYellowLighterer, RedsiftColorPresentationPurpleLighterer, RedsiftColorPresentationOrangeLighterer, RedsiftColorPresentationBlueLighterer, RedsiftColorPresentationGreyLighterer, Theme, useId, useTheme, Text, Number as Number$1, baseStyling, baseContainer, focusRing, Flexbox, warnIfNoAccessibleLabelFound, ThemeProvider, Heading, Button } from '@redsift/design-system';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import React__default, { useRef, useEffect, useMemo, useState, useLayoutEffect, forwardRef, useCallback, useContext } from 'react';
|
|
5
5
|
import classNames from 'classnames';
|
|
@@ -54,7 +54,7 @@ const useBrush = _ref => {
|
|
|
54
54
|
const monochrome = RedsiftColorPresentationBlueDefault;
|
|
55
55
|
const empty = RedsiftColorPresentationGreyDark;
|
|
56
56
|
const scheme = {
|
|
57
|
-
default: [
|
|
57
|
+
default: [RedsiftColorPresentationBlueDefault, RedsiftColorPresentationAquaDefault, RedsiftColorPresentationPinkDefault, RedsiftColorPresentationGreyDefault, RedsiftColorPresentationYellowDefault, RedsiftColorPresentationPurpleDefault, RedsiftColorPresentationGreenDefault, RedsiftColorPresentationBrownDefault, RedsiftColorPresentationRedDefault, RedsiftColorPresentationOrangeDefault],
|
|
58
58
|
dark: [RedsiftColorPresentationGreenDark, RedsiftColorPresentationPinkDark, RedsiftColorPresentationAquaDark, RedsiftColorPresentationBrownDark, RedsiftColorPresentationRedDark, RedsiftColorPresentationYellowDark, RedsiftColorPresentationPurpleDark, RedsiftColorPresentationOrangeDark, RedsiftColorPresentationBlueDark, RedsiftColorPresentationGreyDark],
|
|
59
59
|
darker: [RedsiftColorPresentationGreenDarker, RedsiftColorPresentationPinkDarker, RedsiftColorPresentationAquaDarker, RedsiftColorPresentationBrownDarker, RedsiftColorPresentationRedDarker, RedsiftColorPresentationYellowDarker, RedsiftColorPresentationPurpleDarker, RedsiftColorPresentationOrangeDarker, RedsiftColorPresentationBlueDarker, RedsiftColorPresentationGreyDarker],
|
|
60
60
|
darkerer: [RedsiftColorPresentationGreenDarkerer, RedsiftColorPresentationPinkDarkerer, RedsiftColorPresentationAquaDarkerer, RedsiftColorPresentationBrownDarkerer, RedsiftColorPresentationRedDarkerer, RedsiftColorPresentationYellowDarkerer, RedsiftColorPresentationPurpleDarkerer, RedsiftColorPresentationOrangeDarkerer, RedsiftColorPresentationBlueDarkerer, RedsiftColorPresentationGreyDarkerer],
|
|
@@ -221,7 +221,7 @@ const getSortingMethod = sortingMethod => {
|
|
|
221
221
|
return sortingMethod.indexOf(a.key) === sortingMethod.indexOf(b.key) ? a.key > b.key ? 1 : -1 : sortingMethod.indexOf(a.key) < sortingMethod.indexOf(b.key) ? -1 : 1;
|
|
222
222
|
};
|
|
223
223
|
}
|
|
224
|
-
return () =>
|
|
224
|
+
return () => 1;
|
|
225
225
|
};
|
|
226
226
|
const isValidDate = value => {
|
|
227
227
|
const date = new Date(value);
|
|
@@ -714,7 +714,7 @@ const getScaleTicks = (scale, spec) => {
|
|
|
714
714
|
return scale.ticks(spec);
|
|
715
715
|
}
|
|
716
716
|
if (typeof spec === 'function') {
|
|
717
|
-
return scale.ticks(
|
|
717
|
+
return scale.ticks();
|
|
718
718
|
}
|
|
719
719
|
}
|
|
720
720
|
|
|
@@ -1833,6 +1833,18 @@ Legend.displayName = COMPONENT_NAME$6;
|
|
|
1833
1833
|
|
|
1834
1834
|
const _excluded$f = ["barProps", "className", "data", "id", "isBarSelected", "labelDecorator", "legendDecorator", "legendVariant", "legendProps", "margins", "onBarClick", "size", "sortingMethod", "barRole", "colorTheme", "tooltipVariant", "xAxisVariant", "xAxisPlacement", "xAxisTickFormat", "xAxisTickPadding", "xAxisTickRotation", "xAxisTickSize", "xAxisTickValues", "xAxisMinValue", "xAxisMaxValue", "xAxisTickRemodelling", "yAxisVariant", "yAxisPlacement", "yAxisTickFormat", "yAxisTickPadding", "yAxisTickRotation", "yAxisTickSize", "yAxisTickValues", "yAxisMinValue", "yAxisMaxValue", "yAxisTickRemodelling", "dateParser"];
|
|
1835
1835
|
const getKey = datum => Array.isArray(datum.key) ? datum.key[0] : datum.key;
|
|
1836
|
+
const filterData = (hasCategory, data, filterFn) => {
|
|
1837
|
+
if (hasCategory) {
|
|
1838
|
+
return data.filter(filterFn);
|
|
1839
|
+
}
|
|
1840
|
+
return data.filter(filterFn);
|
|
1841
|
+
};
|
|
1842
|
+
const reduceData = (hasCategory, data, reduceFn, initialValue) => {
|
|
1843
|
+
if (hasCategory) {
|
|
1844
|
+
return data.reduce(reduceFn, initialValue);
|
|
1845
|
+
}
|
|
1846
|
+
return data.reduce(reduceFn, initialValue);
|
|
1847
|
+
};
|
|
1836
1848
|
const isSameKey = (key, previousKey, xScaleType) => xScaleType === 'Date' || xScaleType === 'dateString' ? key.getTime() === previousKey.getTime() : key === previousKey;
|
|
1837
1849
|
const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1838
1850
|
const {
|
|
@@ -1877,8 +1889,9 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1877
1889
|
forwardedProps = _objectWithoutProperties(props, _excluded$f);
|
|
1878
1890
|
const cache = useRef();
|
|
1879
1891
|
const theme = useTheme();
|
|
1892
|
+
const hasCategory = propsData[0] && Array.isArray(propsData[0].key) && propsData[0].key.length >= 2 && propsData[0].key[1] !== null && propsData[0].key[1] !== undefined;
|
|
1880
1893
|
const xScaleType = getKey(propsData[0]) instanceof Date ? 'Date' : typeof getKey(propsData[0]) === 'number' ? 'number' : typeof getKey(propsData[0]) === 'string' && isValidDate(getKey(propsData[0])) ? 'dateString' : undefined;
|
|
1881
|
-
const data = xScaleType === 'number' ? propsData
|
|
1894
|
+
const data = xScaleType === 'number' ? filterData(hasCategory, propsData, datum => typeof getKey(datum) === 'number' && !Number.isNaN(getKey(datum))) : xScaleType === 'dateString' ? filterData(hasCategory, propsData, datum => isValidDate(getKey(datum))) : xScaleType === 'Date' ? filterData(hasCategory, propsData, datum => getKey(datum) instanceof Date) : propsData;
|
|
1882
1895
|
useEffect(() => {
|
|
1883
1896
|
cache.current = data;
|
|
1884
1897
|
});
|
|
@@ -1896,7 +1909,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1896
1909
|
}, propsMargins);
|
|
1897
1910
|
const chartHeight = height - margins.top - margins.bottom;
|
|
1898
1911
|
const chartWidth = width - margins.left - margins.right;
|
|
1899
|
-
const numberOfRows = data
|
|
1912
|
+
const numberOfRows = filterData(hasCategory, data, datum => datum.value).length;
|
|
1900
1913
|
const gap = 5;
|
|
1901
1914
|
let barWidth = chartWidth / (numberOfRows * 2) - gap;
|
|
1902
1915
|
const scaleX = (() => {
|
|
@@ -1914,8 +1927,8 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1914
1927
|
const domain = xScaleType === 'dateString' ? extent(data, d => Date.parse(getKey(d))) : extent(data, d => getKey(d).valueOf());
|
|
1915
1928
|
domain[0] = (_ref3 = xAxisMinValue) !== null && _ref3 !== void 0 ? _ref3 : domain[0];
|
|
1916
1929
|
domain[1] = (_ref4 = xAxisMaxValue) !== null && _ref4 !== void 0 ? _ref4 : domain[1];
|
|
1917
|
-
const startDate = xAxisTickValues && typeof xAxisTickValues.offset === 'function' ? xAxisTickValues.offset(new Date(domain[0]), -1) : new Date(domain[0]);
|
|
1918
|
-
const endDate = xAxisTickValues && typeof xAxisTickValues.offset === 'function' ? xAxisTickValues.offset(new Date(domain[1]), 0) : new Date(domain[1]);
|
|
1930
|
+
const startDate = xAxisTickValues && typeof xAxisTickValues === 'function' && typeof xAxisTickValues.offset === 'function' ? xAxisTickValues.offset(new Date(domain[0]), -1) : new Date(domain[0]);
|
|
1931
|
+
const endDate = xAxisTickValues && typeof xAxisTickValues === 'function' && typeof xAxisTickValues.offset === 'function' ? xAxisTickValues.offset(new Date(domain[1]), 0) : new Date(domain[1]);
|
|
1919
1932
|
return scaleTime().domain([startDate, endDate]).range([0, chartWidth]).nice();
|
|
1920
1933
|
} else {
|
|
1921
1934
|
var _ref5, _ref6;
|
|
@@ -1926,7 +1939,6 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1926
1939
|
}
|
|
1927
1940
|
})();
|
|
1928
1941
|
const xAxisTickFormat = propsXAxisTickFormat !== null && propsXAxisTickFormat !== void 0 ? propsXAxisTickFormat : xScaleType === 'Date' || xScaleType === 'dateString' ? scaleX.tickFormat() : undefined;
|
|
1929
|
-
const hasCategory = data[0] && Array.isArray(data[0].key) && data[0].key.length >= 2 && data[0].key[1] !== null && data[0].key[1] !== undefined;
|
|
1930
1942
|
const statsByCategory = statsBy$1(data, sortingMethod);
|
|
1931
1943
|
const colorScale = useColor({
|
|
1932
1944
|
data: statsByCategory,
|
|
@@ -1934,7 +1946,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1934
1946
|
category: d => d.key,
|
|
1935
1947
|
theme
|
|
1936
1948
|
});
|
|
1937
|
-
const bars = data.sort((a, b) => {
|
|
1949
|
+
const bars = reduceData(hasCategory, filterData(hasCategory, data.sort((a, b) => {
|
|
1938
1950
|
const currentKeyA = hasCategory ? a.key[0] : a.key;
|
|
1939
1951
|
const currentKeyB = hasCategory ? b.key[0] : b.key;
|
|
1940
1952
|
if (xScaleType === 'number') {
|
|
@@ -1955,7 +1967,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1955
1967
|
return hasCategory ? a.key[1] < b.key[1] ? 1 : -1 : 0;
|
|
1956
1968
|
}
|
|
1957
1969
|
return hasCategory ? a.key[1] < b.key[1] ? 1 : -1 : 0;
|
|
1958
|
-
})
|
|
1970
|
+
}), d => d.value !== null), (previousValue, currentValue, currentIndex) => {
|
|
1959
1971
|
var _key$;
|
|
1960
1972
|
const currentKeyD = hasCategory ? currentValue.key[0] : currentValue.key;
|
|
1961
1973
|
const formattedKeyD = xScaleType === 'dateString' ? dateParser ? dateParser(currentKeyD) : new Date(Date.parse(currentKeyD)) : currentKeyD;
|
|
@@ -1982,7 +1994,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1982
1994
|
})();
|
|
1983
1995
|
if (xScaleType) {
|
|
1984
1996
|
const minimalGap = Math.min(...bars.map((bar, i) => i > 0 ? Math.abs(bar.key - bars[i - 1].key) : undefined).filter(k => k)) * 0.9;
|
|
1985
|
-
barWidth = Math.min(barWidth, chartWidth / ((scaleX.domain()[1] - scaleX.domain()[0]) / minimalGap), chartWidth / (xAxisTickValues ? typeof xAxisTickValues === 'number' ? xAxisTickValues : xAxisTickValues.range(scaleX.domain()[0], scaleX.domain()[1]).length : 1));
|
|
1997
|
+
barWidth = Math.min(barWidth, chartWidth / ((scaleX.domain()[1] - scaleX.domain()[0]) / minimalGap), chartWidth / (xAxisTickValues && typeof xAxisTickValues !== 'string' ? typeof xAxisTickValues === 'number' ? xAxisTickValues : Array.isArray(xAxisTickValues) ? xAxisTickValues.length : xAxisTickValues.range(scaleX.domain()[0], scaleX.domain()[1]).length : 1));
|
|
1986
1998
|
}
|
|
1987
1999
|
return /*#__PURE__*/React__default.createElement(StyledBarChart, _extends({}, forwardedProps, {
|
|
1988
2000
|
id: id,
|