@lobehub/charts 1.8.0 → 1.9.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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { FlexboxProps } from 'react-layout-kit';
|
|
3
|
+
import { ValueFormatter } from "../types";
|
|
3
4
|
export interface CategoryBarProps extends FlexboxProps {
|
|
4
5
|
colors?: string[];
|
|
5
6
|
markerValue?: number;
|
|
@@ -7,6 +8,7 @@ export interface CategoryBarProps extends FlexboxProps {
|
|
|
7
8
|
showLabels?: boolean;
|
|
8
9
|
size?: number;
|
|
9
10
|
tooltip?: string;
|
|
11
|
+
valueFormatter?: ValueFormatter;
|
|
10
12
|
values: number[];
|
|
11
13
|
}
|
|
12
14
|
declare const CategoryBar: import("react").ForwardRefExoticComponent<CategoryBarProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -4,12 +4,12 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
5
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
6
|
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
7
|
-
var _excluded = ["values", "colors", "markerValue", "showLabels", "tooltip", "showAnimation", "className", "width", "size", "style"];
|
|
7
|
+
var _excluded = ["values", "colors", "valueFormatter", "markerValue", "showLabels", "tooltip", "showAnimation", "className", "width", "size", "style"];
|
|
8
8
|
import { Tooltip } from '@lobehub/ui';
|
|
9
|
-
import chroma from 'chroma-js';
|
|
10
9
|
import { forwardRef, memo, useMemo } from 'react';
|
|
11
10
|
import { Flexbox } from 'react-layout-kit';
|
|
12
|
-
import {
|
|
11
|
+
import { useThemeColorRange } from "../hooks/useThemeColorRange";
|
|
12
|
+
import { defaultValueFormatter, sumNumericArray } from "../utils";
|
|
13
13
|
import { useStyles } from "./styles";
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
15
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -38,7 +38,8 @@ var getPositionLeft = function getPositionLeft(value, maxValue) {
|
|
|
38
38
|
return value ? value / maxValue * 100 : 0;
|
|
39
39
|
};
|
|
40
40
|
var BarLabels = /*#__PURE__*/memo(function (_ref) {
|
|
41
|
-
var values = _ref.values
|
|
41
|
+
var values = _ref.values,
|
|
42
|
+
valueFormatter = _ref.valueFormatter;
|
|
42
43
|
var _useStyles = useStyles(),
|
|
43
44
|
cx = _useStyles.cx,
|
|
44
45
|
styles = _useStyles.styles;
|
|
@@ -72,7 +73,7 @@ var BarLabels = /*#__PURE__*/memo(function (_ref) {
|
|
|
72
73
|
left: '50%',
|
|
73
74
|
transform: 'translateX(50%)'
|
|
74
75
|
},
|
|
75
|
-
children: prefixSum
|
|
76
|
+
children: valueFormatter ? valueFormatter(prefixSum) : prefixSum
|
|
76
77
|
})
|
|
77
78
|
}, "item-".concat(idx));
|
|
78
79
|
}), /*#__PURE__*/_jsx(Flexbox, {
|
|
@@ -83,7 +84,7 @@ var BarLabels = /*#__PURE__*/memo(function (_ref) {
|
|
|
83
84
|
left: 0,
|
|
84
85
|
position: 'absolute'
|
|
85
86
|
},
|
|
86
|
-
children:
|
|
87
|
+
children: valueFormatter ? valueFormatter(0) : 0
|
|
87
88
|
}), /*#__PURE__*/_jsx(Flexbox, {
|
|
88
89
|
align: 'center',
|
|
89
90
|
horizontal: true,
|
|
@@ -92,7 +93,7 @@ var BarLabels = /*#__PURE__*/memo(function (_ref) {
|
|
|
92
93
|
position: 'absolute',
|
|
93
94
|
right: 0
|
|
94
95
|
},
|
|
95
|
-
children: sumValues
|
|
96
|
+
children: valueFormatter ? valueFormatter(sumValues) : sumValues
|
|
96
97
|
})]
|
|
97
98
|
});
|
|
98
99
|
});
|
|
@@ -101,10 +102,13 @@ var CategoryBar = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
101
102
|
cx = _useStyles2.cx,
|
|
102
103
|
styles = _useStyles2.styles,
|
|
103
104
|
theme = _useStyles2.theme;
|
|
105
|
+
var themeColorRange = useThemeColorRange();
|
|
104
106
|
var _props$values = props.values,
|
|
105
107
|
values = _props$values === void 0 ? [] : _props$values,
|
|
106
108
|
_props$colors = props.colors,
|
|
107
|
-
colors = _props$colors === void 0 ?
|
|
109
|
+
colors = _props$colors === void 0 ? themeColorRange : _props$colors,
|
|
110
|
+
_props$valueFormatter = props.valueFormatter,
|
|
111
|
+
valueFormatter = _props$valueFormatter === void 0 ? defaultValueFormatter : _props$valueFormatter,
|
|
108
112
|
markerValue = props.markerValue,
|
|
109
113
|
_props$showLabels = props.showLabels,
|
|
110
114
|
showLabels = _props$showLabels === void 0 ? true : _props$showLabels,
|
|
@@ -118,7 +122,7 @@ var CategoryBar = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
118
122
|
size = _props$size === void 0 ? 8 : _props$size,
|
|
119
123
|
style = props.style,
|
|
120
124
|
rest = _objectWithoutProperties(props, _excluded);
|
|
121
|
-
var colorGroup = colors.
|
|
125
|
+
var colorGroup = colors.concat(themeColorRange);
|
|
122
126
|
var markerBgColor = useMemo(function () {
|
|
123
127
|
return getMarkerBgColor(markerValue, values, colorGroup);
|
|
124
128
|
}, [markerValue, values, colorGroup]);
|
|
@@ -140,6 +144,7 @@ var CategoryBar = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
140
144
|
width: width
|
|
141
145
|
}, rest), {}, {
|
|
142
146
|
children: [showLabels && /*#__PURE__*/_jsx(BarLabels, {
|
|
147
|
+
valueFormatter: valueFormatter,
|
|
143
148
|
values: values
|
|
144
149
|
}), /*#__PURE__*/_jsxs(Flexbox, {
|
|
145
150
|
align: 'center',
|