@lobehub/charts 1.0.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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +218 -0
  3. package/es/AreaChart/index.d.ts +11 -0
  4. package/es/AreaChart/index.js +388 -0
  5. package/es/AreaChart/styles.d.ts +6 -0
  6. package/es/AreaChart/styles.js +13 -0
  7. package/es/BarChart/index.d.ts +10 -0
  8. package/es/BarChart/index.js +354 -0
  9. package/es/BarChart/renderShape.d.ts +1 -0
  10. package/es/BarChart/renderShape.js +29 -0
  11. package/es/BarChart/styles.d.ts +6 -0
  12. package/es/BarChart/styles.js +13 -0
  13. package/es/DonutChart/DonutChartTooltip.d.ts +7 -0
  14. package/es/DonutChart/DonutChartTooltip.js +25 -0
  15. package/es/DonutChart/index.d.ts +25 -0
  16. package/es/DonutChart/index.js +186 -0
  17. package/es/DonutChart/inputParser.d.ts +2 -0
  18. package/es/DonutChart/inputParser.js +9 -0
  19. package/es/DonutChart/renderInactiveShape.d.ts +1 -0
  20. package/es/DonutChart/renderInactiveShape.js +27 -0
  21. package/es/DonutChart/styles.d.ts +6 -0
  22. package/es/DonutChart/styles.js +13 -0
  23. package/es/LineChart/index.d.ts +9 -0
  24. package/es/LineChart/index.js +347 -0
  25. package/es/LineChart/styles.d.ts +6 -0
  26. package/es/LineChart/styles.js +13 -0
  27. package/es/ScatterChart/ScatterChartTooltip.d.ts +13 -0
  28. package/es/ScatterChart/ScatterChartTooltip.js +83 -0
  29. package/es/ScatterChart/ScatterChartTooltipRow.d.ts +7 -0
  30. package/es/ScatterChart/ScatterChartTooltipRow.js +43 -0
  31. package/es/ScatterChart/index.d.ts +51 -0
  32. package/es/ScatterChart/index.js +304 -0
  33. package/es/ScatterChart/renderShape.d.ts +1 -0
  34. package/es/ScatterChart/renderShape.js +18 -0
  35. package/es/ScatterChart/styles.d.ts +6 -0
  36. package/es/ScatterChart/styles.js +13 -0
  37. package/es/common/BaseAnimationTimingProps.d.ts +7 -0
  38. package/es/common/BaseAnimationTimingProps.js +1 -0
  39. package/es/common/BaseChartProps.d.ts +47 -0
  40. package/es/common/BaseChartProps.js +1 -0
  41. package/es/common/ChartLegend.d.ts +3 -0
  42. package/es/common/ChartLegend.js +39 -0
  43. package/es/common/ChartTooltip/ChartTooltipFrame.d.ts +7 -0
  44. package/es/common/ChartTooltip/ChartTooltipFrame.js +28 -0
  45. package/es/common/ChartTooltip/ChartTooltipRow.d.ts +8 -0
  46. package/es/common/ChartTooltip/ChartTooltipRow.js +58 -0
  47. package/es/common/ChartTooltip/index.d.ts +10 -0
  48. package/es/common/ChartTooltip/index.js +65 -0
  49. package/es/common/CustomTooltipProps.d.ts +6 -0
  50. package/es/common/CustomTooltipProps.js +1 -0
  51. package/es/common/NoData.d.ts +10 -0
  52. package/es/common/NoData.js +43 -0
  53. package/es/common/utils.d.ts +5 -0
  54. package/es/common/utils.js +77 -0
  55. package/es/components/Legend/LegendItem.d.ts +9 -0
  56. package/es/components/Legend/LegendItem.js +65 -0
  57. package/es/components/Legend/ScrollButton.d.ts +9 -0
  58. package/es/components/Legend/ScrollButton.js +58 -0
  59. package/es/components/Legend/index.d.ts +11 -0
  60. package/es/components/Legend/index.js +173 -0
  61. package/es/hooks/useOnWindowResize.d.ts +3 -0
  62. package/es/hooks/useOnWindowResize.js +14 -0
  63. package/es/hooks/useThemeColorRange.d.ts +1 -0
  64. package/es/hooks/useThemeColorRange.js +5 -0
  65. package/es/index.d.ts +8 -0
  66. package/es/index.js +7 -0
  67. package/es/types.d.ts +20 -0
  68. package/es/types.js +1 -0
  69. package/es/utils/index.d.ts +3 -0
  70. package/es/utils/index.js +8 -0
  71. package/package.json +119 -0
@@ -0,0 +1,43 @@
1
+ import { Empty } from 'antd';
2
+ import { useTheme } from 'antd-style';
3
+ import { isValidElement, memo } from 'react';
4
+ import { Center, Flexbox } from 'react-layout-kit';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ import { jsxs as _jsxs } from "react/jsx-runtime";
7
+ var NoData = /*#__PURE__*/memo(function (_ref) {
8
+ var _ref$noDataText = _ref.noDataText,
9
+ noDataText = _ref$noDataText === void 0 ? {
10
+ desc: "There's no data available for your selection.",
11
+ title: 'No Data'
12
+ } : _ref$noDataText,
13
+ className = _ref.className;
14
+ var theme = useTheme();
15
+ var isReactNodeText = /*#__PURE__*/isValidElement(noDataText);
16
+ return /*#__PURE__*/_jsx(Center, {
17
+ height: '100%',
18
+ width: '100%',
19
+ children: /*#__PURE__*/_jsx(Empty, {
20
+ className: className,
21
+ description: isReactNodeText ? noDataText : /*#__PURE__*/_jsxs(Flexbox, {
22
+ gap: 4,
23
+ padding: 8,
24
+ children: [/*#__PURE__*/_jsx("div", {
25
+ style: {
26
+ color: theme.colorText,
27
+ fontSize: 14,
28
+ fontWeight: 'bold'
29
+ },
30
+ children: noDataText === null || noDataText === void 0 ? void 0 : noDataText.title
31
+ }), /*#__PURE__*/_jsx("div", {
32
+ style: {
33
+ color: theme.colorTextDescription,
34
+ fontSize: 14
35
+ },
36
+ children: noDataText === null || noDataText === void 0 ? void 0 : noDataText.desc
37
+ })]
38
+ }),
39
+ image: Empty.PRESENTED_IMAGE_SIMPLE
40
+ })
41
+ });
42
+ });
43
+ export default NoData;
@@ -0,0 +1,5 @@
1
+ export declare const constructCategoryColors: (categories: string[], colors: string[]) => Map<string, string>;
2
+ export declare const getYAxisDomain: (autoMinValue: boolean, minValue: number | undefined, maxValue: number | undefined) => (string | number)[];
3
+ export declare const constructCategories: (data: any[], color?: string) => string[];
4
+ export declare function deepEqual(obj1: any, obj2: any): boolean;
5
+ export declare function hasOnlyOneValueForThisKey(array: any[], keyToCheck: string): boolean;
@@ -0,0 +1,77 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
5
+ export var constructCategoryColors = function constructCategoryColors(categories, colors) {
6
+ var categoryColors = new Map();
7
+ var _iterator = _createForOfIteratorHelper(categories.entries()),
8
+ _step;
9
+ try {
10
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
11
+ var _step$value = _slicedToArray(_step.value, 2),
12
+ idx = _step$value[0],
13
+ category = _step$value[1];
14
+ categoryColors.set(category, colors[idx % colors.length]);
15
+ }
16
+ } catch (err) {
17
+ _iterator.e(err);
18
+ } finally {
19
+ _iterator.f();
20
+ }
21
+ return categoryColors;
22
+ };
23
+ export var getYAxisDomain = function getYAxisDomain(autoMinValue, minValue, maxValue) {
24
+ return [autoMinValue ? 'auto' : minValue !== null && minValue !== void 0 ? minValue : 0, maxValue !== null && maxValue !== void 0 ? maxValue : 'auto'];
25
+ };
26
+ export var constructCategories = function constructCategories(data, color) {
27
+ if (!color) {
28
+ return [];
29
+ }
30
+ var categories = new Set();
31
+ var _iterator2 = _createForOfIteratorHelper(data),
32
+ _step2;
33
+ try {
34
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
35
+ var datum = _step2.value;
36
+ categories.add(datum[color]);
37
+ }
38
+ } catch (err) {
39
+ _iterator2.e(err);
40
+ } finally {
41
+ _iterator2.f();
42
+ }
43
+ return _toConsumableArray(categories);
44
+ };
45
+ export function deepEqual(obj1, obj2) {
46
+ if (obj1 === obj2) return true;
47
+ if (_typeof(obj1) !== 'object' || _typeof(obj2) !== 'object' || obj1 === null || obj2 === null) return false;
48
+ var keys1 = Object.keys(obj1);
49
+ var keys2 = Object.keys(obj2);
50
+ if (keys1.length !== keys2.length) return false;
51
+ for (var _i = 0, _keys = keys1; _i < _keys.length; _i++) {
52
+ var key = _keys[_i];
53
+ if (!keys2.includes(key) || !deepEqual(obj1[key], obj2[key])) return false;
54
+ }
55
+ return true;
56
+ }
57
+ export function hasOnlyOneValueForThisKey(array, keyToCheck) {
58
+ var val = [];
59
+ var _iterator3 = _createForOfIteratorHelper(array),
60
+ _step3;
61
+ try {
62
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
63
+ var obj = _step3.value;
64
+ if (Object.prototype.hasOwnProperty.call(obj, keyToCheck)) {
65
+ val.push(obj[keyToCheck]);
66
+ if (val.length > 1) {
67
+ return false;
68
+ }
69
+ }
70
+ }
71
+ } catch (err) {
72
+ _iterator3.e(err);
73
+ } finally {
74
+ _iterator3.f();
75
+ }
76
+ return true;
77
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ export interface LegendItemProps {
3
+ activeLegend?: string;
4
+ color: string;
5
+ name: string;
6
+ onClick?: (name: string, color: string) => void;
7
+ }
8
+ declare const LegendItem: import("react").NamedExoticComponent<LegendItemProps>;
9
+ export default LegendItem;
@@ -0,0 +1,65 @@
1
+ import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
2
+ var _templateObject, _templateObject2, _templateObject3;
3
+ import { Icon } from '@lobehub/ui';
4
+ import { Typography } from 'antd';
5
+ import { createStyles } from 'antd-style';
6
+ import { Circle } from 'lucide-react';
7
+ import { memo } from 'react';
8
+ import { Flexbox } from 'react-layout-kit';
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ import { jsxs as _jsxs } from "react/jsx-runtime";
11
+ var useStyles = createStyles(function (_ref) {
12
+ var css = _ref.css,
13
+ token = _ref.token;
14
+ return {
15
+ container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: inline-flex;\n align-items: center;\n\n color: ", ";\n white-space: nowrap;\n\n border-radius: ", "px;\n "])), token.colorTextDescription, token.borderRadius),
16
+ hasOnValueChange: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n transition: all 0.25s ", ";\n\n &:hover {\n color: ", ";\n background: ", ";\n }\n "])), token.motionEaseInOut, token.colorTextSecondary, token.colorFillTertiary),
17
+ itemContent: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n font-size: 14px;\n color: inherit;\n "])))
18
+ };
19
+ });
20
+ var LegendItem = /*#__PURE__*/memo(function (_ref2) {
21
+ var name = _ref2.name,
22
+ color = _ref2.color,
23
+ _onClick = _ref2.onClick,
24
+ activeLegend = _ref2.activeLegend;
25
+ var _useStyles = useStyles(),
26
+ cx = _useStyles.cx,
27
+ styles = _useStyles.styles,
28
+ theme = _useStyles.theme;
29
+ var hasOnValueChange = !!_onClick;
30
+ return /*#__PURE__*/_jsxs(Flexbox, {
31
+ className: cx(styles.container, hasOnValueChange && styles.hasOnValueChange),
32
+ gap: 8,
33
+ horizontal: true,
34
+ onClick: function onClick(e) {
35
+ e.stopPropagation();
36
+ _onClick === null || _onClick === void 0 || _onClick(name, color);
37
+ },
38
+ paddingBlock: 2,
39
+ paddingInline: 8,
40
+ style: {
41
+ cursor: hasOnValueChange ? 'pointer' : 'default'
42
+ },
43
+ children: [/*#__PURE__*/_jsx(Icon, {
44
+ color: color,
45
+ fill: color,
46
+ icon: Circle,
47
+ size: {
48
+ fontSize: 10
49
+ },
50
+ style: {
51
+ opacity: activeLegend && activeLegend !== name ? 0.4 : 1
52
+ }
53
+ }), /*#__PURE__*/_jsx(Typography.Paragraph, {
54
+ className: styles.itemContent,
55
+ ellipsis: true,
56
+ style: {
57
+ color: activeLegend && activeLegend === name ? theme.colorTextSecondary : undefined,
58
+ margin: 0,
59
+ opacity: activeLegend && activeLegend !== name ? 0.4 : 1
60
+ },
61
+ children: name
62
+ })]
63
+ });
64
+ });
65
+ export default LegendItem;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { LucideIcon } from 'lucide-react';
3
+ export interface ScrollButtonProps {
4
+ disabled?: boolean;
5
+ icon: LucideIcon;
6
+ onClick?: () => void;
7
+ }
8
+ declare const ScrollButton: import("react").NamedExoticComponent<ScrollButtonProps>;
9
+ export default ScrollButton;
@@ -0,0 +1,58 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { Icon } from '@lobehub/ui';
3
+ import { Button } from 'antd';
4
+ import { memo, useEffect, useRef, useState } from 'react';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ var ScrollButton = /*#__PURE__*/memo(function (_ref) {
7
+ var icon = _ref.icon,
8
+ _onClick = _ref.onClick,
9
+ disabled = _ref.disabled;
10
+ var _useState = useState(false),
11
+ _useState2 = _slicedToArray(_useState, 2),
12
+ isPressed = _useState2[0],
13
+ setIsPressed = _useState2[1];
14
+ var intervalRef = useRef(null);
15
+ useEffect(function () {
16
+ if (isPressed) {
17
+ intervalRef.current = setInterval(function () {
18
+ _onClick === null || _onClick === void 0 || _onClick();
19
+ }, 300);
20
+ } else {
21
+ clearInterval(intervalRef.current);
22
+ }
23
+ return function () {
24
+ return clearInterval(intervalRef.current);
25
+ };
26
+ }, [isPressed, _onClick]);
27
+ useEffect(function () {
28
+ if (disabled) {
29
+ clearInterval(intervalRef.current);
30
+ setIsPressed(false);
31
+ }
32
+ }, [disabled]);
33
+ return /*#__PURE__*/_jsx(Button, {
34
+ disabled: disabled,
35
+ icon: /*#__PURE__*/_jsx(Icon, {
36
+ className: 'w-full',
37
+ icon: icon
38
+ }),
39
+ onClick: function onClick(e) {
40
+ e.stopPropagation();
41
+ _onClick === null || _onClick === void 0 || _onClick();
42
+ },
43
+ onMouseDown: function onMouseDown(e) {
44
+ e.stopPropagation();
45
+ setIsPressed(true);
46
+ },
47
+ onMouseUp: function onMouseUp(e) {
48
+ e.stopPropagation();
49
+ setIsPressed(false);
50
+ },
51
+ size: 'small',
52
+ style: {
53
+ height: 24,
54
+ width: 24
55
+ }
56
+ });
57
+ });
58
+ export default ScrollButton;
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { FlexboxProps } from 'react-layout-kit';
3
+ export interface LegendProps extends FlexboxProps {
4
+ activeLegend?: string;
5
+ categories: string[];
6
+ colors?: string[];
7
+ enableLegendSlider?: boolean;
8
+ onClickLegendItem?: (category: string, color: string) => void;
9
+ }
10
+ declare const Legend: import("react").ForwardRefExoticComponent<LegendProps & import("react").RefAttributes<HTMLDivElement>>;
11
+ export default Legend;
@@ -0,0 +1,173 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
+ import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
5
+ var _excluded = ["categories", "colors", "className", "onClickLegendItem", "activeLegend", "enableLegendSlider"];
6
+ var _templateObject, _templateObject2, _templateObject3;
7
+ import { createStyles } from 'antd-style';
8
+ import { ChevronLeft, ChevronRight } from 'lucide-react';
9
+ import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
10
+ import { Flexbox } from 'react-layout-kit';
11
+ import { useThemeColorRange } from "../../hooks/useThemeColorRange";
12
+ import LegendItem from "./LegendItem";
13
+ import ScrollButton from "./ScrollButton";
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ import { jsxs as _jsxs } from "react/jsx-runtime";
16
+ var useStyles = createStyles(function (_ref) {
17
+ var css = _ref.css;
18
+ return {
19
+ container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n "]))),
20
+ enableLegendSlider: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n scrollbar-width: none;\n\n overflow: auto;\n align-items: center;\n\n padding-right: 48px;\n padding-left: 16px;\n "]))),
21
+ scrollButtons: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n top: 0;\n right: 0;\n bottom: 0;\n "])))
22
+ };
23
+ });
24
+ var Legend = /*#__PURE__*/forwardRef(function (props, ref) {
25
+ var _hasScroll$left, _hasScroll$right;
26
+ var _useStyles = useStyles(),
27
+ cx = _useStyles.cx,
28
+ styles = _useStyles.styles;
29
+ var themeColorRange = useThemeColorRange();
30
+ var categories = props.categories,
31
+ _props$colors = props.colors,
32
+ colors = _props$colors === void 0 ? themeColorRange : _props$colors,
33
+ className = props.className,
34
+ onClickLegendItem = props.onClickLegendItem,
35
+ activeLegend = props.activeLegend,
36
+ _props$enableLegendSl = props.enableLegendSlider,
37
+ enableLegendSlider = _props$enableLegendSl === void 0 ? false : _props$enableLegendSl,
38
+ rest = _objectWithoutProperties(props, _excluded);
39
+ var scrollableRef = useRef(null);
40
+ var scrollButtonsRef = useRef(null);
41
+ var _useState = useState(null),
42
+ _useState2 = _slicedToArray(_useState, 2),
43
+ hasScroll = _useState2[0],
44
+ setHasScroll = _useState2[1];
45
+ var _useState3 = useState(null),
46
+ _useState4 = _slicedToArray(_useState3, 2),
47
+ isKeyDowned = _useState4[0],
48
+ setIsKeyDowned = _useState4[1];
49
+ var intervalRef = useRef(null);
50
+ var checkScroll = useCallback(function () {
51
+ var scrollable = scrollableRef === null || scrollableRef === void 0 ? void 0 : scrollableRef.current;
52
+ if (!scrollable) return;
53
+ var hasLeftScroll = scrollable.scrollLeft > 0;
54
+ var hasRightScroll = scrollable.scrollWidth - scrollable.clientWidth > scrollable.scrollLeft;
55
+ setHasScroll({
56
+ left: hasLeftScroll,
57
+ right: hasRightScroll
58
+ });
59
+ }, [setHasScroll]); // dependencies are listed here in the array
60
+
61
+ var scrollToTest = useCallback(function (direction) {
62
+ var _element$clientWidth, _scrollButtons$client;
63
+ var element = scrollableRef === null || scrollableRef === void 0 ? void 0 : scrollableRef.current;
64
+ var scrollButtons = scrollButtonsRef === null || scrollButtonsRef === void 0 ? void 0 : scrollButtonsRef.current;
65
+ var width = (_element$clientWidth = element === null || element === void 0 ? void 0 : element.clientWidth) !== null && _element$clientWidth !== void 0 ? _element$clientWidth : 0;
66
+ var scrollButtonsWith = (_scrollButtons$client = scrollButtons === null || scrollButtons === void 0 ? void 0 : scrollButtons.clientWidth) !== null && _scrollButtons$client !== void 0 ? _scrollButtons$client : 0;
67
+ if (element && enableLegendSlider) {
68
+ element.scrollTo({
69
+ behavior: 'smooth',
70
+ left: direction === 'left' ? element.scrollLeft - width + scrollButtonsWith : element.scrollLeft + width - scrollButtonsWith
71
+ });
72
+ setTimeout(function () {
73
+ checkScroll();
74
+ }, 400);
75
+ }
76
+ }, [enableLegendSlider, checkScroll]);
77
+ useEffect(function () {
78
+ var keyDownHandler = function keyDownHandler(key) {
79
+ if (key === 'ArrowLeft') {
80
+ scrollToTest('left');
81
+ } else if (key === 'ArrowRight') {
82
+ scrollToTest('right');
83
+ }
84
+ };
85
+ if (isKeyDowned) {
86
+ keyDownHandler(isKeyDowned);
87
+ intervalRef.current = setInterval(function () {
88
+ keyDownHandler(isKeyDowned);
89
+ }, 300);
90
+ } else {
91
+ clearInterval(intervalRef.current);
92
+ }
93
+ return function () {
94
+ return clearInterval(intervalRef.current);
95
+ };
96
+ }, [isKeyDowned, scrollToTest]);
97
+ var keyDown = function keyDown(e) {
98
+ e.stopPropagation();
99
+ if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
100
+ e.preventDefault();
101
+ setIsKeyDowned(e.key);
102
+ }
103
+ };
104
+ var keyUp = function keyUp(e) {
105
+ e.stopPropagation();
106
+ setIsKeyDowned(null);
107
+ };
108
+ useEffect(function () {
109
+ var scrollable = scrollableRef === null || scrollableRef === void 0 ? void 0 : scrollableRef.current;
110
+ if (enableLegendSlider) {
111
+ checkScroll();
112
+ scrollable === null || scrollable === void 0 || scrollable.addEventListener('keydown', keyDown);
113
+ scrollable === null || scrollable === void 0 || scrollable.addEventListener('keyup', keyUp);
114
+ }
115
+ return function () {
116
+ scrollable === null || scrollable === void 0 || scrollable.removeEventListener('keydown', keyDown);
117
+ scrollable === null || scrollable === void 0 || scrollable.removeEventListener('keyup', keyUp);
118
+ };
119
+ }, [checkScroll, enableLegendSlider]);
120
+ return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
121
+ className: cx(styles.container, className),
122
+ gap: 8,
123
+ horizontal: true,
124
+ ref: ref
125
+ }, rest), {}, {
126
+ children: [/*#__PURE__*/_jsx(Flexbox, {
127
+ className: cx(enableLegendSlider && ((hasScroll === null || hasScroll === void 0 ? void 0 : hasScroll.right) || (hasScroll === null || hasScroll === void 0 ? void 0 : hasScroll.left)) && styles.enableLegendSlider),
128
+ flex: 1,
129
+ height: '100%',
130
+ horizontal: true,
131
+ ref: scrollableRef,
132
+ style: {
133
+ overflow: 'hidden'
134
+ },
135
+ tabIndex: 0,
136
+ wrap: enableLegendSlider ? 'nowrap' : 'wrap',
137
+ children: categories.map(function (category, idx) {
138
+ return /*#__PURE__*/_jsx(LegendItem, {
139
+ activeLegend: activeLegend,
140
+ color: colors[idx % colors.length],
141
+ name: category,
142
+ onClick: onClickLegendItem
143
+ }, "item-".concat(idx));
144
+ })
145
+ }), enableLegendSlider && (hasScroll !== null && hasScroll !== void 0 && hasScroll.right || hasScroll !== null && hasScroll !== void 0 && hasScroll.left) ? /*#__PURE__*/_jsxs(Flexbox, {
146
+ align: 'center',
147
+ className: styles.scrollButtons,
148
+ flex: 'none',
149
+ gap: 4,
150
+ height: '100%',
151
+ horizontal: true,
152
+ justify: 'center',
153
+ ref: scrollButtonsRef,
154
+ children: [/*#__PURE__*/_jsx(ScrollButton, {
155
+ disabled: (_hasScroll$left = !(hasScroll !== null && hasScroll !== void 0 && hasScroll.left)) !== null && _hasScroll$left !== void 0 ? _hasScroll$left : true,
156
+ icon: ChevronLeft,
157
+ onClick: function onClick() {
158
+ setIsKeyDowned(null);
159
+ scrollToTest('left');
160
+ }
161
+ }), /*#__PURE__*/_jsx(ScrollButton, {
162
+ disabled: (_hasScroll$right = !(hasScroll !== null && hasScroll !== void 0 && hasScroll.right)) !== null && _hasScroll$right !== void 0 ? _hasScroll$right : true,
163
+ icon: ChevronRight,
164
+ onClick: function onClick() {
165
+ setIsKeyDowned(null);
166
+ scrollToTest('right');
167
+ }
168
+ })]
169
+ }) : null]
170
+ }));
171
+ });
172
+ Legend.displayName = 'Legend';
173
+ export default Legend;
@@ -0,0 +1,3 @@
1
+ export declare const useOnWindowResize: (handler: {
2
+ (): void;
3
+ }) => void;
@@ -0,0 +1,14 @@
1
+ import { useEffect } from 'react';
2
+ export var useOnWindowResize = function useOnWindowResize(handler) {
3
+ useEffect(function () {
4
+ if (window === undefined) return;
5
+ var handleResize = function handleResize() {
6
+ handler();
7
+ };
8
+ handleResize();
9
+ window.addEventListener('resize', handleResize);
10
+ return function () {
11
+ return window.removeEventListener('resize', handleResize);
12
+ };
13
+ }, [handler]);
14
+ };
@@ -0,0 +1 @@
1
+ export declare const useThemeColorRange: () => string[];
@@ -0,0 +1,5 @@
1
+ import { useTheme } from 'antd-style';
2
+ export var useThemeColorRange = function useThemeColorRange() {
3
+ var theme = useTheme();
4
+ return [theme.geekblue, theme.gold, theme.lime, theme.volcano, theme.purple, theme.blue, theme.orange, theme.green, theme.red, theme.cyan, theme.yellow, theme.magenta];
5
+ };
package/es/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { default as AreaChart, type AreaChartProps } from './AreaChart';
2
+ export { default as BarChart, type BarChartProps } from './BarChart';
3
+ export { default as ChartTooltipFrame } from './common/ChartTooltip/ChartTooltipFrame';
4
+ export { default as Legend, type LegendProps } from './components/Legend';
5
+ export { default as DonutChart, type DonutChartProps } from './DonutChart';
6
+ export { default as LineChart, type LineChartProps } from './LineChart';
7
+ export { default as ScatterChart, type ScatterChartProps } from './ScatterChart';
8
+ export type * from './types';
package/es/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export { default as AreaChart } from "./AreaChart";
2
+ export { default as BarChart } from "./BarChart";
3
+ export { default as ChartTooltipFrame } from "./common/ChartTooltip/ChartTooltipFrame";
4
+ export { default as Legend } from "./components/Legend";
5
+ export { default as DonutChart } from "./DonutChart";
6
+ export { default as LineChart } from "./LineChart";
7
+ export { default as ScatterChart } from "./ScatterChart";
package/es/types.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ type FixedProps = {
2
+ categoryClicked: string;
3
+ eventType: 'dot' | 'category' | 'bar' | 'slice' | 'bubble';
4
+ };
5
+ type BaseEventProps = FixedProps & {
6
+ [key: string]: number | string;
7
+ };
8
+ export type EventProps = BaseEventProps | null | undefined;
9
+ export type Interval = 'preserveStartEnd' | 'equidistantPreserveStart';
10
+ export type IntervalType = 'preserveStartEnd' | Interval;
11
+ export type CurveType = 'linear' | 'natural' | 'monotone' | 'step';
12
+ export type ValueFormatter = {
13
+ (value: number): string;
14
+ };
15
+ export type ScatterChartValueFormatter = {
16
+ size?: ValueFormatter;
17
+ x?: ValueFormatter;
18
+ y?: ValueFormatter;
19
+ };
20
+ export {};
package/es/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { ValueFormatter } from "../types";
2
+ export declare const defaultValueFormatter: ValueFormatter;
3
+ export declare const sumNumericArray: (arr: number[]) => number;
@@ -0,0 +1,8 @@
1
+ export var defaultValueFormatter = function defaultValueFormatter(value) {
2
+ return value.toString();
3
+ };
4
+ export var sumNumericArray = function sumNumericArray(arr) {
5
+ return arr.reduce(function (prefixSum, num) {
6
+ return prefixSum + num;
7
+ }, 0);
8
+ };
package/package.json ADDED
@@ -0,0 +1,119 @@
1
+ {
2
+ "name": "@lobehub/charts",
3
+ "version": "1.0.0",
4
+ "description": "React modern charts components built on recharts",
5
+ "keywords": [
6
+ "lobehub",
7
+ "charts"
8
+ ],
9
+ "homepage": "https://github.com/lobehub/lobe-charts",
10
+ "bugs": {
11
+ "url": "https://github.com/lobehub/lobe-charts/issues/new"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/lobehub/lobe-charts.git"
16
+ },
17
+ "license": "MIT",
18
+ "author": "LobeHub <i@lobehub.com>",
19
+ "sideEffects": false,
20
+ "main": "es/index.js",
21
+ "module": "es/index.js",
22
+ "types": "es/index.d.ts",
23
+ "files": [
24
+ "es"
25
+ ],
26
+ "scripts": {
27
+ "build": "father build",
28
+ "build:watch": "father dev",
29
+ "ci": "npm run lint && npm run type-check",
30
+ "clean": "rm -r es lib dist coverage .dumi/tmp .eslintcache node_modules/.cache",
31
+ "dev": "dumi dev",
32
+ "docs:build": "dumi build",
33
+ "docs:build-analyze": "ANALYZE=1 dumi build",
34
+ "doctor": "father doctor",
35
+ "lint": "eslint \"{src,tests}/**/*.{js,jsx,ts,tsx}\" --fix",
36
+ "lint:md": "remark . --quiet --frail --output",
37
+ "lint:style": "stylelint \"{src,tests}/**/*.{js,jsx,ts,tsx}\" --fix",
38
+ "prepare": "husky install && npm run setup",
39
+ "prepublishOnly": "npm run build",
40
+ "prettier": "prettier -c --write --no-error-on-unmatched-pattern \"**/**\"",
41
+ "pull": "git pull",
42
+ "release": "semantic-release",
43
+ "setup": "dumi setup",
44
+ "start": "npm run dev",
45
+ "test": "vitest --passWithNoTests",
46
+ "test:coverage": "vitest run --coverage --passWithNoTests",
47
+ "test:update": "vitest -u",
48
+ "type-check": "tsc -p tsconfig-check.json"
49
+ },
50
+ "lint-staged": {
51
+ "*.md": [
52
+ "remark --quiet --output --",
53
+ "prettier --write --no-error-on-unmatched-pattern"
54
+ ],
55
+ "*.json": [
56
+ "prettier --write --no-error-on-unmatched-pattern"
57
+ ],
58
+ "*.{js,jsx}": [
59
+ "prettier --write",
60
+ "stylelint --fix",
61
+ "eslint --fix"
62
+ ],
63
+ "*.{ts,tsx}": [
64
+ "prettier --parser=typescript --write",
65
+ "stylelint --fix",
66
+ "eslint --fix"
67
+ ]
68
+ },
69
+ "dependencies": {
70
+ "@babel/runtime": "^7.24.8",
71
+ "polished": "^4.3.1",
72
+ "react-layout-kit": "^1.9.0",
73
+ "recharts": "^2.12.7"
74
+ },
75
+ "devDependencies": {
76
+ "@commitlint/cli": "^19.3.0",
77
+ "@lobehub/lint": "^1.24.3",
78
+ "@lobehub/ui": "^1.146.8",
79
+ "@testing-library/react": "^14.3.1",
80
+ "@types/pangu": "^4.0.2",
81
+ "@types/query-string": "^6.3.0",
82
+ "@types/react": "18.2.40",
83
+ "@types/react-dom": "^18.3.0",
84
+ "@vitest/coverage-v8": "latest",
85
+ "babel-plugin-antd-style": "latest",
86
+ "commitlint": "^19.3.0",
87
+ "concurrently": "^8.2.2",
88
+ "cross-env": "^7.0.3",
89
+ "dumi": "2.2.17",
90
+ "dumi-theme-lobehub": "^1.8.1",
91
+ "eslint": "^8.57.0",
92
+ "father": "4.3.1",
93
+ "husky": "^9.0.11",
94
+ "jsdom": "^23.2.0",
95
+ "lint-staged": "^15.2.7",
96
+ "prettier": "^3.3.3",
97
+ "react": "^18.3.1",
98
+ "react-dom": "^18.3.1",
99
+ "remark": "^14.0.3",
100
+ "remark-cli": "^11.0.0",
101
+ "semantic-release": "^21.1.2",
102
+ "stylelint": "^15.11.0",
103
+ "typescript": "^5.5.3",
104
+ "vitest": "~1.2.2"
105
+ },
106
+ "peerDependencies": {
107
+ "@lobehub/ui": ">=1",
108
+ "ahooks": ">=3",
109
+ "antd": ">=5.13.0",
110
+ "antd-style": ">=3",
111
+ "lucide-react": ">=0.396.0",
112
+ "react": ">=18",
113
+ "react-dom": ">=18"
114
+ },
115
+ "publishConfig": {
116
+ "access": "public",
117
+ "registry": "https://registry.npmjs.org"
118
+ }
119
+ }