@redsift/charts 11.0.2 → 11.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 +7 -1
- package/index.js +13 -9
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -521,6 +521,8 @@ interface BarProps extends DataPointProps<BarDatum> {
|
|
|
521
521
|
scalePosition: ScaleLinear$1<number, number, never> | ScaleTime$2<number, number, never> | ScalePoint$2<string>;
|
|
522
522
|
/** Width of the bar in vertical orientation. */
|
|
523
523
|
width?: number;
|
|
524
|
+
/** Min width of the bar in vertical orientation. */
|
|
525
|
+
minWidth?: number;
|
|
524
526
|
}
|
|
525
527
|
type StyledBarProps = StyledDataPointProps & Omit<BarProps, 'scale' | 'scalePosition'> & {
|
|
526
528
|
$theme: Theme;
|
|
@@ -677,7 +679,9 @@ interface BarChartProps extends ChartContainerProps, ChartAxesProps {
|
|
|
677
679
|
/** @deprecated: Use xAxisTickRotation instead. Whether the x axis labels are rotated or not. */
|
|
678
680
|
areXLabelsRotated?: boolean;
|
|
679
681
|
/** Native HTML props to forward to each bar. */
|
|
680
|
-
barProps?: Omit<ComponentProps<'g'>, 'onClick' | 'orientation' | 'ref' | 'scale'
|
|
682
|
+
barProps?: Omit<ComponentProps<'g'>, 'onClick' | 'orientation' | 'ref' | 'scale'> & {
|
|
683
|
+
minWidth?: number;
|
|
684
|
+
};
|
|
681
685
|
/** Bar role. If an onClick is provided, the bars will have the role `button`. For a navigation link, please use `getBarAnchorProps` instead. */
|
|
682
686
|
barRole?: BarProps['role'];
|
|
683
687
|
/** Number of categories to use, the rest being put into a new category called "Others". */
|
|
@@ -748,6 +752,8 @@ interface BarChartProps extends ChartContainerProps, ChartAxesProps {
|
|
|
748
752
|
* For reference, the line of code using it is: xAxisTickValues.offset(new Date(domain[1]), xAxisEndDateOffset)
|
|
749
753
|
*/
|
|
750
754
|
xAxisEndDateOffset?: number;
|
|
755
|
+
/** If set, the Y axis will use a logarithmic scale using this base. Set this value to 10 to use a default logarithmic scale. */
|
|
756
|
+
yScaleLogBase?: number;
|
|
751
757
|
}
|
|
752
758
|
type StyledBarChartProps = BarChartProps & {};
|
|
753
759
|
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { brush, select, scaleOrdinal, zoom, interpolateRound, interpolate, scaleLinear, sum, scaleBand, extent, scaleUtc, scalePoint, utcParse, scaleTime, line, arc, pie, min, descending, scaleSqrt, max } from 'd3';
|
|
1
|
+
import { brush, select, scaleOrdinal, zoom, interpolateRound, interpolate, scaleLinear, sum, scaleBand, extent, scaleUtc, scalePoint, scaleLog, utcParse, scaleTime, line, arc, pie, min, descending, scaleSqrt, max } from 'd3';
|
|
2
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, useMessageFormatter, 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';
|
|
@@ -449,7 +449,8 @@ const DataPoint = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
449
449
|
if (showTooltip) {
|
|
450
450
|
return /*#__PURE__*/React__default.createElement(Tooltip, {
|
|
451
451
|
placement: "right",
|
|
452
|
-
theme: theme
|
|
452
|
+
theme: theme,
|
|
453
|
+
delay: 50
|
|
453
454
|
}, /*#__PURE__*/React__default.createElement(Tooltip.Trigger, null, href !== undefined ? /*#__PURE__*/React__default.createElement(as || 'a', _objectSpread2({
|
|
454
455
|
href
|
|
455
456
|
}, anchorProps), DataPointComponent) : DataPointComponent), /*#__PURE__*/React__default.createElement(Tooltip.Content, null, isTooltipCustom ? tooltipDecorator(data, {
|
|
@@ -1059,7 +1060,7 @@ const StyledBar = styled(DataPoint)`
|
|
|
1059
1060
|
}}}
|
|
1060
1061
|
`;
|
|
1061
1062
|
|
|
1062
|
-
const _excluded$m = ["className", "disableAnimations", "gap", "height", "maxHeight", "orientation", "previousData", "scale", "scalePosition", "width"];
|
|
1063
|
+
const _excluded$m = ["className", "disableAnimations", "gap", "height", "maxHeight", "orientation", "previousData", "scale", "scalePosition", "width", "minWidth"];
|
|
1063
1064
|
const COMPONENT_NAME$9 = 'Bar';
|
|
1064
1065
|
const CLASSNAME$9 = 'redsift-bar';
|
|
1065
1066
|
const Bar = /*#__PURE__*/forwardRef((props, ref) => {
|
|
@@ -1087,7 +1088,8 @@ const Bar = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1087
1088
|
},
|
|
1088
1089
|
scale,
|
|
1089
1090
|
scalePosition,
|
|
1090
|
-
width = 40
|
|
1091
|
+
width = 40,
|
|
1092
|
+
minWidth
|
|
1091
1093
|
} = props,
|
|
1092
1094
|
forwardedProps = _objectWithoutProperties(props, _excluded$m);
|
|
1093
1095
|
const theme = useTheme();
|
|
@@ -1112,10 +1114,11 @@ const Bar = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1112
1114
|
t: 0
|
|
1113
1115
|
}
|
|
1114
1116
|
}));
|
|
1117
|
+
const computedWidth = minWidth ? Math.max(minWidth, width) : width;
|
|
1115
1118
|
return /*#__PURE__*/React__default.createElement(StyledBar, _extends({}, forwardedProps, {
|
|
1116
1119
|
ref: ref,
|
|
1117
1120
|
className: classNames(Bar.className, className),
|
|
1118
|
-
transform: isHorizontal ? `translate(0, ${scalePosition(data.data.key) + gap / 2})` : `translate(${scalePosition(data.data.key) + (isOrdinal ?
|
|
1121
|
+
transform: isHorizontal ? `translate(0, ${scalePosition(data.data.key) + gap / 2})` : `translate(${scalePosition(data.data.key) + (isOrdinal ? computedWidth + gap / 2 : computedWidth / 2)}, ${maxHeight}), rotate(180)`,
|
|
1119
1122
|
$clickable: Boolean(onClick),
|
|
1120
1123
|
$theme: theme
|
|
1121
1124
|
}), isHorizontal ? /*#__PURE__*/React__default.createElement(it.rect, {
|
|
@@ -1125,7 +1128,7 @@ const Bar = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1125
1128
|
}) : /*#__PURE__*/React__default.createElement(it.rect, {
|
|
1126
1129
|
height: config.immediate || disableAnimations ? maxHeight - scale(getValue(data.data)) : animatedProps.t.to(t => Math.max(0, maxHeight - scale(interpolator(t)))),
|
|
1127
1130
|
fill: isDeselected ? 'var(--redsift-color-neutral-light-grey)' : color,
|
|
1128
|
-
width:
|
|
1131
|
+
width: computedWidth
|
|
1129
1132
|
}), isHorizontal ? /*#__PURE__*/React__default.createElement("text", {
|
|
1130
1133
|
x: "10",
|
|
1131
1134
|
y: height / 2,
|
|
@@ -1991,7 +1994,7 @@ const Legend = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1991
1994
|
Legend.className = CLASSNAME$6;
|
|
1992
1995
|
Legend.displayName = COMPONENT_NAME$6;
|
|
1993
1996
|
|
|
1994
|
-
const _excluded$f = ["barProps", "className", "data", "disableAnimations", "id", "getBarAnchorProps", "isBarSelected", "labelDecorator", "legendDecorator", "legendVariant", "legendProps", "margins", "onBarClick", "size", "sortingMethod", "barRole", "colorTheme", "tooltipVariant", "xAxisVariant", "xAxisPlacement", "xAxisTickFormat", "xAxisTickPadding", "xAxisTickRotation", "xAxisTickSize", "xAxisTickValues", "xAxisMinValue", "xAxisMaxValue", "xAxisTickRemodelling", "xAxisStartDateOffset", "xAxisEndDateOffset", "yAxisVariant", "yAxisPlacement", "yAxisTickFormat", "yAxisTickPadding", "yAxisTickRotation", "yAxisTickSize", "yAxisTickValues", "yAxisMinValue", "yAxisMaxValue", "yAxisTickRemodelling", "xScaleType", "dateParser"],
|
|
1997
|
+
const _excluded$f = ["barProps", "className", "data", "disableAnimations", "id", "getBarAnchorProps", "isBarSelected", "labelDecorator", "legendDecorator", "legendVariant", "legendProps", "margins", "onBarClick", "size", "sortingMethod", "barRole", "colorTheme", "tooltipVariant", "xAxisVariant", "xAxisPlacement", "xAxisTickFormat", "xAxisTickPadding", "xAxisTickRotation", "xAxisTickSize", "xAxisTickValues", "xAxisMinValue", "xAxisMaxValue", "xAxisTickRemodelling", "xAxisStartDateOffset", "xAxisEndDateOffset", "yAxisVariant", "yAxisPlacement", "yAxisTickFormat", "yAxisTickPadding", "yAxisTickRotation", "yAxisTickSize", "yAxisTickValues", "yAxisMinValue", "yAxisMaxValue", "yAxisTickRemodelling", "xScaleType", "yScaleLogBase", "dateParser"],
|
|
1995
1998
|
_excluded2$3 = ["extraLegendItems"];
|
|
1996
1999
|
const getKey = datum => Array.isArray(datum.key) ? datum.key[0] : datum.key;
|
|
1997
2000
|
const filterData = (hasCategory, data, filterFn) => {
|
|
@@ -2051,6 +2054,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
2051
2054
|
yAxisMaxValue,
|
|
2052
2055
|
yAxisTickRemodelling,
|
|
2053
2056
|
xScaleType: propsXScaleType,
|
|
2057
|
+
yScaleLogBase,
|
|
2054
2058
|
dateParser
|
|
2055
2059
|
} = props,
|
|
2056
2060
|
forwardedProps = _objectWithoutProperties(props, _excluded$f);
|
|
@@ -2151,7 +2155,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
2151
2155
|
previousValue[currentIndex].cumulativeValue = previousValue[currentIndex].cumulativeValue + previousValue[currentIndex - 1].cumulativeValue;
|
|
2152
2156
|
}
|
|
2153
2157
|
return previousValue;
|
|
2154
|
-
}, []);
|
|
2158
|
+
}, []).filter(bar => yScaleLogBase === undefined || bar.cumulativeValue !== 0);
|
|
2155
2159
|
const scaleY = (() => {
|
|
2156
2160
|
var _ref7, _ref8;
|
|
2157
2161
|
const domain = extent(bars, d => d.cumulativeValue);
|
|
@@ -2160,7 +2164,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
2160
2164
|
if (domain[1] === 0 && domain[0] === 0) {
|
|
2161
2165
|
domain[1] = 1;
|
|
2162
2166
|
}
|
|
2163
|
-
return scaleLinear().domain(domain).range([chartHeight, 0]).nice();
|
|
2167
|
+
return (yScaleLogBase ? scaleLog().clamp(true).base(yScaleLogBase) : scaleLinear()).domain(domain).range([chartHeight, 0]).nice();
|
|
2164
2168
|
})();
|
|
2165
2169
|
if (xScaleType) {
|
|
2166
2170
|
const minimalGap = Math.min(...bars.map((bar, i) => i > 0 ? Math.abs(bar.key - bars[i - 1].key) : undefined).filter(k => k)) * 0.9;
|