@lobehub/charts 1.2.0 → 1.4.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.
@@ -329,7 +329,6 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
329
329
  verticalAlign: "top"
330
330
  }) : undefined, categories.map(function (category) {
331
331
  var _categoryColors$get2;
332
- console.log(categoryColors.get(category));
333
332
  return /*#__PURE__*/_jsx(Bar, {
334
333
  animationDuration: animationDuration,
335
334
  className: cx(css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n fill: ", ";\n "])), (_categoryColors$get2 = categoryColors.get(category)) !== null && _categoryColors$get2 !== void 0 ? _categoryColors$get2 : theme.colorPrimary)),
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ import { FlexboxProps } from 'react-layout-kit';
3
+ export interface CategoryBarProps extends FlexboxProps {
4
+ colors?: string[];
5
+ markerValue?: number;
6
+ showAnimation?: boolean;
7
+ showLabels?: boolean;
8
+ size?: number;
9
+ tooltip?: string;
10
+ values: number[];
11
+ }
12
+ declare const CategoryBar: import("react").ForwardRefExoticComponent<CategoryBarProps & import("react").RefAttributes<HTMLDivElement>>;
13
+ export default CategoryBar;
@@ -0,0 +1,191 @@
1
+ 'use client';
2
+
3
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
7
+ var _excluded = ["values", "colors", "markerValue", "showLabels", "tooltip", "showAnimation", "className", "width", "size", "style"];
8
+ import { Tooltip } from '@lobehub/ui';
9
+ import chroma from 'chroma-js';
10
+ import { forwardRef, memo, useMemo } from 'react';
11
+ import { Flexbox } from 'react-layout-kit';
12
+ import { sumNumericArray } from "../utils";
13
+ import { useStyles } from "./styles";
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ import { jsxs as _jsxs } from "react/jsx-runtime";
16
+ var getMarkerBgColor = function getMarkerBgColor(markerValue, values, colors) {
17
+ if (markerValue === undefined) return '';
18
+ var prefixSum = 0;
19
+ var _iterator = _createForOfIteratorHelper(values.entries()),
20
+ _step;
21
+ try {
22
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
23
+ var _step$value = _slicedToArray(_step.value, 2),
24
+ i = _step$value[0],
25
+ currentWidthPercentage = _step$value[1];
26
+ var currentBgColor = colors[i];
27
+ prefixSum += currentWidthPercentage;
28
+ if (prefixSum >= markerValue) return currentBgColor;
29
+ }
30
+ } catch (err) {
31
+ _iterator.e(err);
32
+ } finally {
33
+ _iterator.f();
34
+ }
35
+ return '';
36
+ };
37
+ var getPositionLeft = function getPositionLeft(value, maxValue) {
38
+ return value ? value / maxValue * 100 : 0;
39
+ };
40
+ var BarLabels = /*#__PURE__*/memo(function (_ref) {
41
+ var values = _ref.values;
42
+ var _useStyles = useStyles(),
43
+ cx = _useStyles.cx,
44
+ styles = _useStyles.styles;
45
+ var sumValues = useMemo(function () {
46
+ return sumNumericArray(values);
47
+ }, [values]);
48
+ var prefixSum = 0;
49
+ var sumConsecutiveHiddenLabels = 0;
50
+ return /*#__PURE__*/_jsxs(Flexbox, {
51
+ className: cx(styles.label, styles.emphasis),
52
+ horizontal: true,
53
+ style: {
54
+ position: 'relative'
55
+ },
56
+ children: [values.slice(0, values.length).map(function (widthPercentage, idx) {
57
+ prefixSum += widthPercentage;
58
+ var showLabel = (widthPercentage >= 0.1 * sumValues || sumConsecutiveHiddenLabels >= 0.09 * sumValues) && sumValues - prefixSum >= 0.15 * sumValues && prefixSum >= 0.1 * sumValues;
59
+ sumConsecutiveHiddenLabels = showLabel ? 0 : sumConsecutiveHiddenLabels += widthPercentage;
60
+ var widthPositionLeft = getPositionLeft(widthPercentage, sumValues);
61
+ if (prefixSum === sumValues) return null;
62
+ return /*#__PURE__*/_jsx(Flexbox, {
63
+ align: 'center',
64
+ horizontal: true,
65
+ justify: 'flex-end',
66
+ style: {
67
+ width: "".concat(widthPositionLeft, "%")
68
+ },
69
+ children: /*#__PURE__*/_jsx("span", {
70
+ style: {
71
+ display: showLabel ? 'block' : 'hidden',
72
+ left: '50%',
73
+ transform: 'translateX(50%)'
74
+ },
75
+ children: prefixSum
76
+ })
77
+ }, "item-".concat(idx));
78
+ }), /*#__PURE__*/_jsx(Flexbox, {
79
+ align: 'center',
80
+ horizontal: true,
81
+ style: {
82
+ bottom: 0,
83
+ left: 0,
84
+ position: 'absolute'
85
+ },
86
+ children: "0"
87
+ }), /*#__PURE__*/_jsx(Flexbox, {
88
+ align: 'center',
89
+ horizontal: true,
90
+ style: {
91
+ bottom: 0,
92
+ position: 'absolute',
93
+ right: 0
94
+ },
95
+ children: sumValues
96
+ })]
97
+ });
98
+ });
99
+ var CategoryBar = /*#__PURE__*/forwardRef(function (props, ref) {
100
+ var _useStyles2 = useStyles(),
101
+ cx = _useStyles2.cx,
102
+ styles = _useStyles2.styles,
103
+ theme = _useStyles2.theme;
104
+ var _props$values = props.values,
105
+ values = _props$values === void 0 ? [] : _props$values,
106
+ _props$colors = props.colors,
107
+ colors = _props$colors === void 0 ? [theme.colorSuccess, theme.colorWarning, theme.colorError] : _props$colors,
108
+ markerValue = props.markerValue,
109
+ _props$showLabels = props.showLabels,
110
+ showLabels = _props$showLabels === void 0 ? true : _props$showLabels,
111
+ tooltip = props.tooltip,
112
+ _props$showAnimation = props.showAnimation,
113
+ showAnimation = _props$showAnimation === void 0 ? false : _props$showAnimation,
114
+ className = props.className,
115
+ _props$width = props.width,
116
+ width = _props$width === void 0 ? '100%' : _props$width,
117
+ _props$size = props.size,
118
+ size = _props$size === void 0 ? 8 : _props$size,
119
+ style = props.style,
120
+ rest = _objectWithoutProperties(props, _excluded);
121
+ var colorGroup = colors.length === values.length ? colors : chroma.scale(colors).mode('lch').colors(values.length);
122
+ var markerBgColor = useMemo(function () {
123
+ return getMarkerBgColor(markerValue, values, colorGroup);
124
+ }, [markerValue, values, colorGroup]);
125
+ var maxValue = useMemo(function () {
126
+ return sumNumericArray(values);
127
+ }, [values]);
128
+ var markerPositionLeft = useMemo(function () {
129
+ return getPositionLeft(markerValue, maxValue);
130
+ }, [markerValue, maxValue]);
131
+ return /*#__PURE__*/_jsx(Tooltip, {
132
+ title: tooltip,
133
+ children: /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
134
+ className: className,
135
+ gap: 8,
136
+ ref: ref,
137
+ style: _objectSpread({
138
+ position: 'relative'
139
+ }, style),
140
+ width: width
141
+ }, rest), {}, {
142
+ children: [showLabels && /*#__PURE__*/_jsx(BarLabels, {
143
+ values: values
144
+ }), /*#__PURE__*/_jsxs(Flexbox, {
145
+ align: 'center',
146
+ className: cx('relative w-full flex items-center h-2'),
147
+ height: size,
148
+ horizontal: true,
149
+ style: {
150
+ position: 'relative'
151
+ },
152
+ children: [/*#__PURE__*/_jsx(Flexbox, {
153
+ align: 'center',
154
+ height: '100%',
155
+ horizontal: true,
156
+ style: {
157
+ borderRadius: size / 2,
158
+ overflow: 'hidden'
159
+ },
160
+ width: '100%',
161
+ children: values.map(function (value, idx) {
162
+ var _colorGroup$idx;
163
+ var baseColor = (_colorGroup$idx = colorGroup[idx]) !== null && _colorGroup$idx !== void 0 ? _colorGroup$idx : theme.colorPrimary;
164
+ var percentage = value / maxValue * 100;
165
+ return /*#__PURE__*/_jsx(Flexbox, {
166
+ height: '100%',
167
+ style: {
168
+ background: baseColor,
169
+ width: "".concat(percentage, "%")
170
+ }
171
+ }, "item-".concat(idx));
172
+ })
173
+ }), markerValue === undefined ? undefined : /*#__PURE__*/_jsx("div", {
174
+ className: cx(styles.markerWrapper, showAnimation && styles.showAnimation),
175
+ style: {
176
+ left: "".concat(markerPositionLeft, "%")
177
+ },
178
+ children: /*#__PURE__*/_jsx("div", {
179
+ className: styles.marker,
180
+ style: {
181
+ background: markerBgColor || theme.colorPrimary,
182
+ height: size + 8
183
+ }
184
+ })
185
+ })]
186
+ })]
187
+ }))
188
+ });
189
+ });
190
+ CategoryBar.displayName = 'CategoryBar';
191
+ export default CategoryBar;
@@ -0,0 +1,13 @@
1
+ import { ReactNode } from 'react';
2
+ import { FlexboxProps } from 'react-layout-kit';
3
+ export interface DeltaBarProps extends FlexboxProps {
4
+ bgColors?: string;
5
+ color?: string;
6
+ isIncreasePositive?: boolean;
7
+ showAnimation?: boolean;
8
+ size?: number;
9
+ tooltip?: ReactNode;
10
+ value: number;
11
+ }
12
+ declare const DeltaBar: import("react").ForwardRefExoticComponent<DeltaBarProps & import("react").RefAttributes<HTMLDivElement>>;
13
+ export default DeltaBar;
@@ -0,0 +1,115 @@
1
+ 'use client';
2
+
3
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
6
+ var _excluded = ["value", "bgColors", "color", "isIncreasePositive", "showAnimation", "className", "tooltip", "width", "size", "style"];
7
+ import { Tooltip } from '@lobehub/ui';
8
+ import { forwardRef } from 'react';
9
+ import { Flexbox } from 'react-layout-kit';
10
+ import { DeltaTypes } from "../types";
11
+ import { mapInputsToDeltaType } from "../utils";
12
+ import { useStyles } from "./styles";
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { jsxs as _jsxs } from "react/jsx-runtime";
15
+ var getDeltaType = function getDeltaType(value) {
16
+ return value >= 0 ? DeltaTypes.Increase : DeltaTypes.Decrease;
17
+ };
18
+ var DeltaBar = /*#__PURE__*/forwardRef(function (props, ref) {
19
+ var _useStyles = useStyles(),
20
+ cx = _useStyles.cx,
21
+ styles = _useStyles.styles,
22
+ theme = _useStyles.theme;
23
+ var value = props.value,
24
+ bgColors = props.bgColors,
25
+ color = props.color,
26
+ _props$isIncreasePosi = props.isIncreasePositive,
27
+ isIncreasePositive = _props$isIncreasePosi === void 0 ? true : _props$isIncreasePosi,
28
+ _props$showAnimation = props.showAnimation,
29
+ showAnimation = _props$showAnimation === void 0 ? false : _props$showAnimation,
30
+ className = props.className,
31
+ tooltip = props.tooltip,
32
+ _props$width = props.width,
33
+ width = _props$width === void 0 ? '100%' : _props$width,
34
+ _props$size = props.size,
35
+ size = _props$size === void 0 ? 8 : _props$size,
36
+ style = props.style,
37
+ rest = _objectWithoutProperties(props, _excluded);
38
+ var deltaType = mapInputsToDeltaType(getDeltaType(value), isIncreasePositive);
39
+ var colors = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, DeltaTypes.Increase, theme.colorSuccess), DeltaTypes.ModerateIncrease, theme.colorSuccess), DeltaTypes.Decrease, theme.colorError), DeltaTypes.ModerateDecrease, theme.colorError), DeltaTypes.Unchanged, theme.colorWarning);
40
+ return /*#__PURE__*/_jsx(Tooltip, {
41
+ title: tooltip,
42
+ children: /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
43
+ align: 'center',
44
+ className: className,
45
+ height: size,
46
+ horizontal: true,
47
+ ref: ref,
48
+ style: _objectSpread({
49
+ position: 'relative'
50
+ }, style),
51
+ width: width
52
+ }, rest), {}, {
53
+ children: [/*#__PURE__*/_jsx(Flexbox, {
54
+ height: '100%',
55
+ style: {
56
+ background: bgColors || theme.colorFillTertiary,
57
+ borderRadius: size / 2,
58
+ inset: 0,
59
+ opacity: bgColors ? 0.2 : 1,
60
+ position: 'absolute',
61
+ zIndex: 0
62
+ },
63
+ width: '100%'
64
+ }), /*#__PURE__*/_jsx(Flexbox, {
65
+ align: 'center',
66
+ flex: 1,
67
+ height: '100%',
68
+ horizontal: true,
69
+ justify: 'flex-end',
70
+ style: {
71
+ position: 'relative'
72
+ },
73
+ children: value < 0 ? /*#__PURE__*/_jsx("div", {
74
+ className: cx(showAnimation && styles.showAnimation),
75
+ style: {
76
+ background: colors[deltaType],
77
+ borderBottomLeftRadius: size / 2,
78
+ borderTopLeftRadius: size / 2,
79
+ height: '100%',
80
+ width: "".concat(Math.abs(value), "%")
81
+ }
82
+ }) : undefined
83
+ }), /*#__PURE__*/_jsx(Flexbox, {
84
+ className: styles.marker,
85
+ flex: 'none',
86
+ style: {
87
+ background: color || theme.colorPrimary,
88
+ height: size + 8,
89
+ zIndex: 2
90
+ }
91
+ }), /*#__PURE__*/_jsx(Flexbox, {
92
+ align: 'center',
93
+ flex: 1,
94
+ height: '100%',
95
+ horizontal: true,
96
+ justify: 'flex-start',
97
+ style: {
98
+ position: 'relative'
99
+ },
100
+ children: value >= 0 ? /*#__PURE__*/_jsx("div", {
101
+ className: cx(showAnimation && styles.showAnimation),
102
+ style: {
103
+ background: colors[deltaType],
104
+ borderBottomRightRadius: size / 2,
105
+ borderTopRightRadius: size / 2,
106
+ height: '100%',
107
+ width: "".concat(Math.abs(value), "%")
108
+ }
109
+ }) : undefined
110
+ })]
111
+ }))
112
+ });
113
+ });
114
+ DeltaBar.displayName = 'DeltaBar';
115
+ export default DeltaBar;
@@ -0,0 +1,16 @@
1
+ import { ReactNode } from 'react';
2
+ import { FlexboxProps } from 'react-layout-kit';
3
+ export interface MarkerBarProps extends FlexboxProps {
4
+ bgColors?: string;
5
+ color?: string;
6
+ markerTooltip?: ReactNode;
7
+ maxValue?: number;
8
+ minValue?: number;
9
+ rangeColors?: string;
10
+ rangeTooltip?: ReactNode;
11
+ showAnimation?: boolean;
12
+ size?: number;
13
+ value: number;
14
+ }
15
+ declare const MarkerBar: import("react").ForwardRefExoticComponent<MarkerBarProps & import("react").RefAttributes<HTMLDivElement>>;
16
+ export default MarkerBar;
@@ -0,0 +1,91 @@
1
+ 'use client';
2
+
3
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
+ var _excluded = ["value", "minValue", "maxValue", "markerTooltip", "rangeTooltip", "showAnimation", "color", "bgColors", "rangeColors", "className", "width", "style", "size"];
6
+ import { Tooltip } from '@lobehub/ui';
7
+ import { forwardRef } from 'react';
8
+ import { Flexbox } from 'react-layout-kit';
9
+ import { useStyles } from "./styles";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { jsxs as _jsxs } from "react/jsx-runtime";
12
+ var MarkerBar = /*#__PURE__*/forwardRef(function (props, ref) {
13
+ var value = props.value,
14
+ minValue = props.minValue,
15
+ maxValue = props.maxValue,
16
+ markerTooltip = props.markerTooltip,
17
+ rangeTooltip = props.rangeTooltip,
18
+ _props$showAnimation = props.showAnimation,
19
+ showAnimation = _props$showAnimation === void 0 ? false : _props$showAnimation,
20
+ color = props.color,
21
+ bgColors = props.bgColors,
22
+ rangeColors = props.rangeColors,
23
+ className = props.className,
24
+ _props$width = props.width,
25
+ width = _props$width === void 0 ? '100%' : _props$width,
26
+ style = props.style,
27
+ _props$size = props.size,
28
+ size = _props$size === void 0 ? 8 : _props$size,
29
+ rest = _objectWithoutProperties(props, _excluded);
30
+ var _useStyles = useStyles(),
31
+ cx = _useStyles.cx,
32
+ styles = _useStyles.styles,
33
+ theme = _useStyles.theme;
34
+ return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
35
+ align: 'center',
36
+ className: className,
37
+ height: size,
38
+ horizontal: true,
39
+ ref: ref,
40
+ style: _objectSpread({
41
+ position: 'relative'
42
+ }, style),
43
+ width: width
44
+ }, rest), {}, {
45
+ children: [/*#__PURE__*/_jsx(Flexbox, {
46
+ height: '100%',
47
+ style: {
48
+ background: bgColors || theme.colorFillTertiary,
49
+ borderRadius: size / 2,
50
+ inset: 0,
51
+ opacity: bgColors ? 0.2 : 1,
52
+ position: 'absolute',
53
+ zIndex: 0
54
+ },
55
+ width: '100%'
56
+ }), minValue !== undefined && maxValue !== undefined ? /*#__PURE__*/_jsx(Tooltip, {
57
+ title: rangeTooltip,
58
+ children: /*#__PURE__*/_jsx(Flexbox, {
59
+ className: cx(showAnimation && styles.showAnimation),
60
+ height: '100%',
61
+ style: {
62
+ background: rangeColors || theme.colorFill,
63
+ borderRadius: size / 2,
64
+ inset: 0,
65
+ left: "".concat(minValue, "%"),
66
+ opacity: rangeColors ? 0.2 : 1,
67
+ position: 'absolute',
68
+ zIndex: 0
69
+ },
70
+ width: "".concat(maxValue - minValue, "%")
71
+ })
72
+ }) : null, /*#__PURE__*/_jsx(Tooltip, {
73
+ title: markerTooltip,
74
+ children: /*#__PURE__*/_jsx("div", {
75
+ className: cx(styles.markerWrapper, showAnimation && styles.showAnimation),
76
+ style: {
77
+ left: "".concat(value, "%")
78
+ },
79
+ children: /*#__PURE__*/_jsx("div", {
80
+ className: styles.marker,
81
+ style: {
82
+ background: color || theme.colorPrimary,
83
+ height: size + 8
84
+ }
85
+ })
86
+ })
87
+ })]
88
+ }));
89
+ });
90
+ MarkerBar.displayName = 'MarkerBar';
91
+ export default MarkerBar;
@@ -0,0 +1,12 @@
1
+ import { ReactNode } from 'react';
2
+ import { FlexboxProps } from 'react-layout-kit';
3
+ export interface ProgressBarProps extends FlexboxProps {
4
+ bgColors?: string;
5
+ color?: string;
6
+ showAnimation?: boolean;
7
+ size?: number;
8
+ tooltip?: ReactNode;
9
+ value: number;
10
+ }
11
+ declare const ProgressBar: import("react").ForwardRefExoticComponent<ProgressBarProps & import("react").RefAttributes<HTMLDivElement>>;
12
+ export default ProgressBar;
@@ -0,0 +1,68 @@
1
+ 'use client';
2
+
3
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
+ var _excluded = ["value", "color", "bgColors", "tooltip", "showAnimation", "className", "width", "size", "style"];
6
+ import { Tooltip } from '@lobehub/ui';
7
+ import { forwardRef } from 'react';
8
+ import { Flexbox } from 'react-layout-kit';
9
+ import { useStyles } from "./styles";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { jsxs as _jsxs } from "react/jsx-runtime";
12
+ var ProgressBar = /*#__PURE__*/forwardRef(function (props, ref) {
13
+ var _useStyles = useStyles(),
14
+ cx = _useStyles.cx,
15
+ styles = _useStyles.styles,
16
+ theme = _useStyles.theme;
17
+ var value = props.value,
18
+ color = props.color,
19
+ bgColors = props.bgColors,
20
+ tooltip = props.tooltip,
21
+ _props$showAnimation = props.showAnimation,
22
+ showAnimation = _props$showAnimation === void 0 ? false : _props$showAnimation,
23
+ className = props.className,
24
+ _props$width = props.width,
25
+ width = _props$width === void 0 ? '100%' : _props$width,
26
+ _props$size = props.size,
27
+ size = _props$size === void 0 ? 8 : _props$size,
28
+ style = props.style,
29
+ rest = _objectWithoutProperties(props, _excluded);
30
+ return /*#__PURE__*/_jsx(Tooltip, {
31
+ title: tooltip,
32
+ children: /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
33
+ align: 'center',
34
+ className: className,
35
+ height: size,
36
+ horizontal: true,
37
+ ref: ref,
38
+ style: _objectSpread({
39
+ position: 'relative'
40
+ }, style),
41
+ width: width
42
+ }, rest), {}, {
43
+ children: [/*#__PURE__*/_jsx(Flexbox, {
44
+ height: '100%',
45
+ style: {
46
+ background: bgColors || theme.colorFillTertiary,
47
+ borderRadius: size / 2,
48
+ inset: 0,
49
+ opacity: bgColors ? 0.2 : 1,
50
+ position: 'absolute',
51
+ zIndex: 0
52
+ },
53
+ width: '100%'
54
+ }), /*#__PURE__*/_jsx(Flexbox, {
55
+ className: cx(showAnimation && styles.showAnimation),
56
+ height: '100%',
57
+ style: {
58
+ background: color || theme.colorPrimary,
59
+ borderRadius: size / 2,
60
+ zIndex: 1
61
+ },
62
+ width: "".concat(value, "%")
63
+ })]
64
+ }))
65
+ });
66
+ });
67
+ ProgressBar.displayName = 'ProgressBar';
68
+ export default ProgressBar;
@@ -0,0 +1,4 @@
1
+ export { default as CategoryBar, type CategoryBarProps } from './CategoryBar';
2
+ export { default as DeltaBar, type DeltaBarProps } from './DeltaBar';
3
+ export { default as MarkerBar, type MarkerBarProps } from './MarkerBar';
4
+ export { default as ProgressBar, type ProgressBarProps } from './ProgressBar';
@@ -0,0 +1,4 @@
1
+ export { default as CategoryBar } from "./CategoryBar";
2
+ export { default as DeltaBar } from "./DeltaBar";
3
+ export { default as MarkerBar } from "./MarkerBar";
4
+ export { default as ProgressBar } from "./ProgressBar";
@@ -0,0 +1,7 @@
1
+ export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
2
+ emphasis: import("antd-style").SerializedStyles;
3
+ label: import("antd-style").SerializedStyles;
4
+ marker: import("antd-style").SerializedStyles;
5
+ markerWrapper: import("antd-style").SerializedStyles;
6
+ showAnimation: import("antd-style").SerializedStyles;
7
+ }>;
@@ -0,0 +1,14 @@
1
+ import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
2
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
3
+ import { createStyles } from 'antd-style';
4
+ export var useStyles = createStyles(function (_ref) {
5
+ var css = _ref.css,
6
+ token = _ref.token;
7
+ return {
8
+ emphasis: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n "]))),
9
+ label: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n font-size: 14px;\n line-height: 16px;\n fill: ", ";\n "])), token.colorTextDescription),
10
+ marker: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n width: 4px;\n border-radius: 4px;\n box-shadow: 0 0 0 3px ", ";\n "])), token.colorBgContainer),
11
+ markerWrapper: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: absolute;\n right: 50%;\n width: 1.25rem;\n "]))),
12
+ showAnimation: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n transition: all 0.25s ", ";\n "])), token.motionEaseInOut)
13
+ };
14
+ });
@@ -8,7 +8,7 @@ import { createStyles } from 'antd-style';
8
8
  import { ChevronLeft, ChevronRight } from 'lucide-react';
9
9
  import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
10
10
  import { Flexbox } from 'react-layout-kit';
11
- import { useThemeColorRange } from "../../hooks/useThemeColorRange";
11
+ import { useThemeColorRange } from "../hooks/useThemeColorRange";
12
12
  import LegendItem from "./LegendItem";
13
13
  import ScrollButton from "./ScrollButton";
14
14
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -22,7 +22,6 @@ var useStyles = createStyles(function (_ref) {
22
22
  };
23
23
  });
24
24
  var Legend = /*#__PURE__*/forwardRef(function (props, ref) {
25
- var _hasScroll$left, _hasScroll$right;
26
25
  var _useStyles = useStyles(),
27
26
  cx = _useStyles.cx,
28
27
  styles = _useStyles.styles;
@@ -117,6 +116,8 @@ var Legend = /*#__PURE__*/forwardRef(function (props, ref) {
117
116
  scrollable === null || scrollable === void 0 || scrollable.removeEventListener('keyup', keyUp);
118
117
  };
119
118
  }, [checkScroll, enableLegendSlider]);
119
+
120
+ // @ts-ignore
120
121
  return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
121
122
  className: cx(styles.container, className),
122
123
  gap: 8,
@@ -152,14 +153,14 @@ var Legend = /*#__PURE__*/forwardRef(function (props, ref) {
152
153
  justify: 'center',
153
154
  ref: scrollButtonsRef,
154
155
  children: [/*#__PURE__*/_jsx(ScrollButton, {
155
- disabled: (_hasScroll$left = !(hasScroll !== null && hasScroll !== void 0 && hasScroll.left)) !== null && _hasScroll$left !== void 0 ? _hasScroll$left : true,
156
+ disabled: !(hasScroll !== null && hasScroll !== void 0 && hasScroll.left),
156
157
  icon: ChevronLeft,
157
158
  onClick: function onClick() {
158
159
  setIsKeyDowned(null);
159
160
  scrollToTest('left');
160
161
  }
161
162
  }), /*#__PURE__*/_jsx(ScrollButton, {
162
- disabled: (_hasScroll$right = !(hasScroll !== null && hasScroll !== void 0 && hasScroll.right)) !== null && _hasScroll$right !== void 0 ? _hasScroll$right : true,
163
+ disabled: !(hasScroll !== null && hasScroll !== void 0 && hasScroll.right),
163
164
  icon: ChevronRight,
164
165
  onClick: function onClick() {
165
166
  setIsKeyDowned(null);
@@ -1,6 +1,6 @@
1
1
  import { useRef } from 'react';
2
2
  import { Flexbox } from 'react-layout-kit';
3
- import Legend from "../components/Legend";
3
+ import Legend from "../Legend";
4
4
  import { useOnWindowResize } from "../hooks/useOnWindowResize";
5
5
  import { jsx as _jsx } from "react/jsx-runtime";
6
6
  var calculateHeight = function calculateHeight(height) {
package/es/index.d.ts CHANGED
@@ -2,9 +2,10 @@ export { default as AreaChart, type AreaChartProps } from './AreaChart';
2
2
  export { default as BarChart, type BarChartProps } from './BarChart';
3
3
  export { type Bar, default as BarList, type BarListProps } from './BarList';
4
4
  export { default as ChartTooltipFrame } from './common/ChartTooltip/ChartTooltipFrame';
5
- export { default as Legend, type LegendProps } from './components/Legend';
5
+ export * from './DataBars';
6
6
  export { default as DonutChart, type DonutChartProps } from './DonutChart';
7
7
  export { default as Heatmaps, type HeatmapsProps } from './Heatmaps';
8
+ export { default as Legend, type LegendProps } from './Legend';
8
9
  export { default as LineChart, type LineChartProps } from './LineChart';
9
10
  export { default as ScatterChart, type ScatterChartProps } from './ScatterChart';
10
11
  export * from './SparkChart';
package/es/index.js CHANGED
@@ -2,9 +2,10 @@ export { default as AreaChart } from "./AreaChart";
2
2
  export { default as BarChart } from "./BarChart";
3
3
  export { default as BarList } from "./BarList";
4
4
  export { default as ChartTooltipFrame } from "./common/ChartTooltip/ChartTooltipFrame";
5
- export { default as Legend } from "./components/Legend";
5
+ export * from "./DataBars";
6
6
  export { default as DonutChart } from "./DonutChart";
7
7
  export { default as Heatmaps } from "./Heatmaps";
8
+ export { default as Legend } from "./Legend";
8
9
  export { default as LineChart } from "./LineChart";
9
10
  export { default as ScatterChart } from "./ScatterChart";
10
11
  export * from "./SparkChart";
package/es/types.d.ts CHANGED
@@ -42,4 +42,9 @@ export type ScatterChartValueFormatter = {
42
42
  x?: ValueFormatter;
43
43
  y?: ValueFormatter;
44
44
  };
45
+ declare const deltaTypeValues: readonly ["increase", "moderateIncrease", "decrease", "moderateDecrease", "unchanged"];
46
+ export type DeltaType = (typeof deltaTypeValues)[number];
47
+ export declare const DeltaTypes: {
48
+ [key: string]: DeltaType;
49
+ };
45
50
  export {};
package/es/types.js CHANGED
@@ -1 +1,8 @@
1
- export {};
1
+ var deltaTypeValues = ['increase', 'moderateIncrease', 'decrease', 'moderateDecrease', 'unchanged'];
2
+ export var DeltaTypes = {
3
+ Decrease: 'decrease',
4
+ Increase: 'increase',
5
+ ModerateDecrease: 'moderateDecrease',
6
+ ModerateIncrease: 'moderateIncrease',
7
+ Unchanged: 'unchanged'
8
+ };
@@ -2,3 +2,4 @@ import { ValueFormatter } from "../types";
2
2
  export declare const defaultValueFormatter: ValueFormatter;
3
3
  export declare const sumNumericArray: (arr: number[]) => number;
4
4
  export declare const isOnSeverSide: boolean;
5
+ export declare const mapInputsToDeltaType: (deltaType: string, isIncreasePositive: boolean) => string;
package/es/utils/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { DeltaTypes } from "../types";
1
2
  export var defaultValueFormatter = function defaultValueFormatter(value) {
2
3
  return value.toString();
3
4
  };
@@ -6,4 +7,28 @@ export var sumNumericArray = function sumNumericArray(arr) {
6
7
  return prefixSum + num;
7
8
  }, 0);
8
9
  };
9
- export var isOnSeverSide = typeof document === 'undefined' || typeof window === 'undefined';
10
+ export var isOnSeverSide = typeof document === 'undefined' || typeof window === 'undefined';
11
+ export var mapInputsToDeltaType = function mapInputsToDeltaType(deltaType, isIncreasePositive) {
12
+ if (isIncreasePositive || deltaType === DeltaTypes.Unchanged) {
13
+ return deltaType;
14
+ }
15
+ switch (deltaType) {
16
+ case DeltaTypes.Increase:
17
+ {
18
+ return DeltaTypes.Decrease;
19
+ }
20
+ case DeltaTypes.ModerateIncrease:
21
+ {
22
+ return DeltaTypes.ModerateDecrease;
23
+ }
24
+ case DeltaTypes.Decrease:
25
+ {
26
+ return DeltaTypes.Increase;
27
+ }
28
+ case DeltaTypes.ModerateDecrease:
29
+ {
30
+ return DeltaTypes.ModerateIncrease;
31
+ }
32
+ }
33
+ return '';
34
+ };
package/es/utils/theme.js CHANGED
@@ -14,12 +14,12 @@ var createstringScale = function createstringScale(colors, size) {
14
14
  };
15
15
  var validateTheme = function validateTheme(input, size) {
16
16
  if (_typeof(input) !== 'object' || input === undefined) {
17
- throw new Error("The theme object must contain at least one of the fields \"light\" and \"dark\" with exactly 2 or ".concat(size, " colors respectively."));
17
+ throw new Error("The theme object must contain at least 2 or ".concat(size, " colors respectively."));
18
18
  }
19
19
  if (input) {
20
20
  var length = input.length;
21
21
  if (length !== 2 && length !== size) {
22
- throw new Error("theme.light must contain exactly 2 or ".concat(size, " colors, ").concat(length, " passed."));
22
+ throw new Error("theme must contain exactly 2 or ".concat(size, " colors, ").concat(length, " passed."));
23
23
  }
24
24
  }
25
25
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/charts",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "React modern charts components built on recharts",
5
5
  "keywords": [
6
6
  "lobehub",
@@ -92,7 +92,7 @@
92
92
  "dumi-theme-lobehub": "^1.8.1",
93
93
  "eslint": "^8.57.0",
94
94
  "father": "4.3.1",
95
- "husky": "^9.0.11",
95
+ "husky": "9.0.11",
96
96
  "jsdom": "^23.2.0",
97
97
  "lint-staged": "^15.2.7",
98
98
  "prettier": "^3.3.3",
File without changes
File without changes