@lobehub/charts 1.0.0 → 1.2.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/README.md +1 -0
- package/es/AreaChart/index.js +9 -5
- package/es/BarChart/index.js +5 -1
- package/es/BarList/index.d.ts +24 -0
- package/es/BarList/index.js +149 -0
- package/es/BarList/styles.d.ts +10 -0
- package/es/BarList/styles.js +17 -0
- package/es/DonutChart/index.d.ts +2 -1
- package/es/DonutChart/index.js +7 -3
- package/es/Heatmaps/Calendar.d.ts +18 -0
- package/es/Heatmaps/Calendar.js +67 -0
- package/es/Heatmaps/ChartLabels.d.ts +15 -0
- package/es/Heatmaps/ChartLabels.js +50 -0
- package/es/Heatmaps/Footer.d.ts +22 -0
- package/es/Heatmaps/Footer.js +60 -0
- package/es/Heatmaps/index.d.ts +28 -0
- package/es/Heatmaps/index.js +181 -0
- package/es/Heatmaps/styles.d.ts +7 -0
- package/es/Heatmaps/styles.js +14 -0
- package/es/LineChart/index.js +10 -6
- package/es/ScatterChart/index.js +10 -6
- package/es/SparkChart/SparkAreaChart.d.ts +11 -0
- package/es/SparkChart/SparkAreaChart.js +140 -0
- package/es/SparkChart/SparkBarChart.d.ts +8 -0
- package/es/SparkChart/SparkBarChart.js +98 -0
- package/es/SparkChart/SparkLineChart.d.ts +9 -0
- package/es/SparkChart/SparkLineChart.js +102 -0
- package/es/SparkChart/index.d.ts +3 -0
- package/es/SparkChart/index.js +3 -0
- package/es/Tracker/TrackerBlock.d.ts +8 -0
- package/es/Tracker/TrackerBlock.js +62 -0
- package/es/Tracker/index.d.ts +18 -0
- package/es/Tracker/index.js +98 -0
- package/es/Tracker/styles.d.ts +5 -0
- package/es/Tracker/styles.js +12 -0
- package/es/common/BaseSparkChartProps.d.ts +13 -0
- package/es/common/BaseSparkChartProps.js +1 -0
- package/es/common/utils.d.ts +2 -2
- package/es/common/utils.js +4 -4
- package/es/hooks/useOnWindowResize.js +2 -1
- package/es/hooks/usePrefersReducedMotion.d.ts +1 -0
- package/es/hooks/usePrefersReducedMotion.js +23 -0
- package/es/index.d.ts +4 -0
- package/es/index.js +5 -1
- package/es/types.d.ts +25 -0
- package/es/utils/calendar.d.ts +29 -0
- package/es/utils/calendar.js +194 -0
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +2 -1
- package/es/utils/theme.d.ts +2 -0
- package/es/utils/theme.js +49 -0
- package/package.json +7 -3
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
5
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
6
|
+
var _excluded = ["data", "blockMargin", "blockRadius", "blockSize", "onValueChange", "fontSize", "hideColorLegend", "hideMonthLabels", "hideTotalCount", "labels", "maxLevel", "loading", "showTooltip", "customTooltip", "showWeekdayLabels", "style", "colors", "totalCount", "weekStart", "className", "noDataText"];
|
|
7
|
+
import { useThemeMode } from 'antd-style';
|
|
8
|
+
import { getYear, parseISO } from 'date-fns';
|
|
9
|
+
import { forwardRef, useMemo } from 'react';
|
|
10
|
+
import { Flexbox } from 'react-layout-kit';
|
|
11
|
+
import NoData from "../common/NoData";
|
|
12
|
+
import { usePrefersReducedMotion } from "../hooks/usePrefersReducedMotion";
|
|
13
|
+
import { isOnSeverSide } from "../utils";
|
|
14
|
+
import { DEFAULT_LABELS, generateEmptyData, groupByWeeks, maxWeekdayLabelLength } from "../utils/calendar";
|
|
15
|
+
import { createTheme } from "../utils/theme";
|
|
16
|
+
import Calendar from "./Calendar";
|
|
17
|
+
import ChartLabels from "./ChartLabels";
|
|
18
|
+
import Footer from "./Footer";
|
|
19
|
+
import { useStyles } from "./styles";
|
|
20
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
var LABEL_MARGIN = 8;
|
|
23
|
+
var Heatmaps = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
24
|
+
var data = props.data,
|
|
25
|
+
_props$blockMargin = props.blockMargin,
|
|
26
|
+
blockMargin = _props$blockMargin === void 0 ? 4 : _props$blockMargin,
|
|
27
|
+
_props$blockRadius = props.blockRadius,
|
|
28
|
+
blockRadius = _props$blockRadius === void 0 ? 2 : _props$blockRadius,
|
|
29
|
+
_props$blockSize = props.blockSize,
|
|
30
|
+
blockSize = _props$blockSize === void 0 ? 12 : _props$blockSize,
|
|
31
|
+
onValueChange = props.onValueChange,
|
|
32
|
+
_props$fontSize = props.fontSize,
|
|
33
|
+
fontSize = _props$fontSize === void 0 ? 14 : _props$fontSize,
|
|
34
|
+
_props$hideColorLegen = props.hideColorLegend,
|
|
35
|
+
hideColorLegend = _props$hideColorLegen === void 0 ? false : _props$hideColorLegen,
|
|
36
|
+
_props$hideMonthLabel = props.hideMonthLabels,
|
|
37
|
+
hideMonthLabels = _props$hideMonthLabel === void 0 ? false : _props$hideMonthLabel,
|
|
38
|
+
_props$hideTotalCount = props.hideTotalCount,
|
|
39
|
+
hideTotalCount = _props$hideTotalCount === void 0 ? false : _props$hideTotalCount,
|
|
40
|
+
labelsProp = props.labels,
|
|
41
|
+
_props$maxLevel = props.maxLevel,
|
|
42
|
+
maxLevel = _props$maxLevel === void 0 ? Math.max(1, props.maxLevel || 4) : _props$maxLevel,
|
|
43
|
+
_props$loading = props.loading,
|
|
44
|
+
loading = _props$loading === void 0 ? false : _props$loading,
|
|
45
|
+
_props$showTooltip = props.showTooltip,
|
|
46
|
+
showTooltip = _props$showTooltip === void 0 ? true : _props$showTooltip,
|
|
47
|
+
customTooltip = props.customTooltip,
|
|
48
|
+
_props$showWeekdayLab = props.showWeekdayLabels,
|
|
49
|
+
showWeekdayLabels = _props$showWeekdayLab === void 0 ? false : _props$showWeekdayLab,
|
|
50
|
+
_props$style = props.style,
|
|
51
|
+
style = _props$style === void 0 ? {} : _props$style,
|
|
52
|
+
colors = props.colors,
|
|
53
|
+
totalCountProp = props.totalCount,
|
|
54
|
+
_props$weekStart = props.weekStart,
|
|
55
|
+
weekStart = _props$weekStart === void 0 ? 0 : _props$weekStart,
|
|
56
|
+
className = props.className,
|
|
57
|
+
noDataText = props.noDataText,
|
|
58
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
59
|
+
var activities = useMemo(function () {
|
|
60
|
+
if (loading) return generateEmptyData();
|
|
61
|
+
return data.map(function (item) {
|
|
62
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
63
|
+
level: item.level > maxLevel ? maxLevel : item.level
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}, [data, maxLevel, loading]);
|
|
67
|
+
var _useThemeMode = useThemeMode(),
|
|
68
|
+
isDarkMode = _useThemeMode.isDarkMode;
|
|
69
|
+
var _useStyles = useStyles(),
|
|
70
|
+
cx = _useStyles.cx,
|
|
71
|
+
styles = _useStyles.styles,
|
|
72
|
+
theme = _useStyles.theme;
|
|
73
|
+
var defaultColors = useMemo(function () {
|
|
74
|
+
switch (maxLevel) {
|
|
75
|
+
case 1:
|
|
76
|
+
{
|
|
77
|
+
return [theme.colorFillSecondary, isDarkMode ? theme.lime8 : theme.green8];
|
|
78
|
+
}
|
|
79
|
+
case 2:
|
|
80
|
+
{
|
|
81
|
+
return [theme.colorFillSecondary, isDarkMode ? theme.lime4 : theme.green4, isDarkMode ? theme.lime8 : theme.green8];
|
|
82
|
+
}
|
|
83
|
+
case 3:
|
|
84
|
+
{
|
|
85
|
+
return [theme.colorFillSecondary, isDarkMode ? theme.lime3 : theme.green3, isDarkMode ? theme.lime6 : theme.green6, isDarkMode ? theme.lime9 : theme.green9];
|
|
86
|
+
}
|
|
87
|
+
case 4:
|
|
88
|
+
{
|
|
89
|
+
return [theme.colorFillSecondary, isDarkMode ? theme.lime4 : theme.green4, isDarkMode ? theme.lime6 : theme.green6, isDarkMode ? theme.lime8 : theme.green8, isDarkMode ? theme.lime10 : theme.green10];
|
|
90
|
+
}
|
|
91
|
+
default:
|
|
92
|
+
{
|
|
93
|
+
return [theme.colorFillSecondary, theme.colorSuccess];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}, [theme, isDarkMode, maxLevel]);
|
|
97
|
+
var useAnimation = !usePrefersReducedMotion();
|
|
98
|
+
if (activities.length === 0) return /*#__PURE__*/_jsx(NoData, {
|
|
99
|
+
noDataText: noDataText
|
|
100
|
+
});
|
|
101
|
+
if (showWeekdayLabels && isOnSeverSide) return null;
|
|
102
|
+
var colorScale = createTheme(colors || defaultColors, maxLevel + 1);
|
|
103
|
+
var firstActivity = activities[0];
|
|
104
|
+
var year = getYear(parseISO(firstActivity.date));
|
|
105
|
+
var weeks = groupByWeeks(activities, weekStart);
|
|
106
|
+
var firstWeek = weeks[0];
|
|
107
|
+
var labels = Object.assign({}, DEFAULT_LABELS, labelsProp);
|
|
108
|
+
var labelHeight = hideMonthLabels ? 0 : fontSize + LABEL_MARGIN;
|
|
109
|
+
var weekdayLabelOffset = showWeekdayLabels ? maxWeekdayLabelLength(firstWeek, weekStart, labels.weekdays, fontSize) + LABEL_MARGIN : undefined;
|
|
110
|
+
var getDimensions = function getDimensions() {
|
|
111
|
+
return {
|
|
112
|
+
height: labelHeight + (blockSize + blockMargin) * 7 - blockMargin,
|
|
113
|
+
width: weeks.length * (blockSize + blockMargin) - blockMargin
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
var _getDimensions = getDimensions(),
|
|
117
|
+
width = _getDimensions.width,
|
|
118
|
+
height = _getDimensions.height;
|
|
119
|
+
var zeroColor = colorScale[0];
|
|
120
|
+
var containerStyles = _objectSpread({
|
|
121
|
+
fontSize: fontSize
|
|
122
|
+
}, useAnimation && _defineProperty(_defineProperty({}, "--lobe-heatmaps-loading", zeroColor), "--lobe-heatmaps-loading-active", theme.colorFill));
|
|
123
|
+
return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
|
|
124
|
+
className: cx(styles.container, className),
|
|
125
|
+
ref: ref,
|
|
126
|
+
style: _objectSpread(_objectSpread({}, style), containerStyles)
|
|
127
|
+
}, rest), {}, {
|
|
128
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
129
|
+
className: styles.scrollContainer,
|
|
130
|
+
children: /*#__PURE__*/_jsxs("svg", {
|
|
131
|
+
className: styles.calendar,
|
|
132
|
+
height: height,
|
|
133
|
+
style: {
|
|
134
|
+
marginLeft: weekdayLabelOffset
|
|
135
|
+
},
|
|
136
|
+
viewBox: "0 0 ".concat(width, " ").concat(height),
|
|
137
|
+
width: width,
|
|
138
|
+
children: [!loading && !showWeekdayLabels && hideMonthLabels ? undefined : /*#__PURE__*/_jsx(ChartLabels, {
|
|
139
|
+
blockMargin: blockMargin,
|
|
140
|
+
blockSize: blockSize,
|
|
141
|
+
hideMonthLabels: hideMonthLabels,
|
|
142
|
+
labelHeight: labelHeight,
|
|
143
|
+
labelMargin: LABEL_MARGIN,
|
|
144
|
+
labels: labels,
|
|
145
|
+
showWeekdayLabels: showWeekdayLabels,
|
|
146
|
+
weekStart: weekStart,
|
|
147
|
+
weeks: weeks
|
|
148
|
+
}), /*#__PURE__*/_jsx(Calendar, {
|
|
149
|
+
blockMargin: blockMargin,
|
|
150
|
+
blockRadius: blockRadius,
|
|
151
|
+
blockSize: blockSize,
|
|
152
|
+
colorScale: colorScale,
|
|
153
|
+
customTooltip: customTooltip,
|
|
154
|
+
enableAnimation: loading && useAnimation,
|
|
155
|
+
labelHeight: labelHeight,
|
|
156
|
+
labels: labels,
|
|
157
|
+
maxLevel: maxLevel,
|
|
158
|
+
onValueChange: onValueChange,
|
|
159
|
+
showTooltip: showTooltip,
|
|
160
|
+
weeks: weeks
|
|
161
|
+
})]
|
|
162
|
+
})
|
|
163
|
+
}), hideTotalCount && hideColorLegend ? undefined : /*#__PURE__*/_jsx(Footer, {
|
|
164
|
+
blockRadius: blockRadius,
|
|
165
|
+
blockSize: blockSize,
|
|
166
|
+
colorScale: colorScale,
|
|
167
|
+
hideColorLegend: hideColorLegend,
|
|
168
|
+
hideTotalCount: hideTotalCount,
|
|
169
|
+
labels: labels,
|
|
170
|
+
loading: loading,
|
|
171
|
+
maxLevel: maxLevel,
|
|
172
|
+
totalCount: typeof totalCountProp === 'number' ? totalCountProp : activities.reduce(function (sum, activity) {
|
|
173
|
+
return sum + activity.count;
|
|
174
|
+
}, 0),
|
|
175
|
+
weekdayLabelOffset: weekdayLabelOffset,
|
|
176
|
+
year: year
|
|
177
|
+
})]
|
|
178
|
+
}));
|
|
179
|
+
});
|
|
180
|
+
Heatmaps.displayName = 'Heatmaps';
|
|
181
|
+
export default Heatmaps;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
|
|
2
|
+
calendar: import("antd-style").SerializedStyles;
|
|
3
|
+
container: import("antd-style").SerializedStyles;
|
|
4
|
+
footer: import("antd-style").SerializedStyles;
|
|
5
|
+
legendColors: import("antd-style").SerializedStyles;
|
|
6
|
+
scrollContainer: 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
|
+
calendar: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n overflow: visible;\n display: block;\n\n text {\n fill: currentcolor;\n }\n "]))),
|
|
9
|
+
container: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n gap: 8px;\n\n width: max-content;\n max-width: 100%;\n\n rect {\n stroke: ", ";\n stroke-width: 1px;\n shape-rendering: geometricprecision;\n }\n "])), token.colorFillTertiary),
|
|
10
|
+
footer: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: wrap;\n gap: 4px 16px;\n white-space: nowrap;\n "]))),
|
|
11
|
+
legendColors: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n display: flex;\n gap: 3px;\n align-items: center;\n margin-left: auto;\n "]))),
|
|
12
|
+
scrollContainer: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n overflow: auto hidden;\n max-width: 100%;\n "])))
|
|
13
|
+
};
|
|
14
|
+
});
|
package/es/LineChart/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
5
5
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
6
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
7
7
|
var _templateObject, _templateObject2, _templateObject3;
|
|
8
|
-
var _excluded = ["data", "categories", "index", "colors", "valueFormatter", "startEndOnly", "showXAxis", "showYAxis", "yAxisWidth", "intervalType", "animationDuration", "showAnimation", "showTooltip", "showLegend", "showGridLines", "autoMinValue", "curveType", "minValue", "maxValue", "connectNulls", "allowDecimals", "noDataText", "className", "onValueChange", "enableLegendSlider", "customTooltip", "rotateLabelX", "tickGap", "xAxisLabel", "yAxisLabel", "width", "height"];
|
|
8
|
+
var _excluded = ["data", "categories", "index", "colors", "valueFormatter", "startEndOnly", "showXAxis", "showYAxis", "yAxisWidth", "intervalType", "animationDuration", "showAnimation", "showTooltip", "showLegend", "showGridLines", "autoMinValue", "curveType", "minValue", "maxValue", "connectNulls", "allowDecimals", "noDataText", "className", "onValueChange", "enableLegendSlider", "customTooltip", "rotateLabelX", "tickGap", "xAxisLabel", "yAxisLabel", "width", "height", "style"];
|
|
9
9
|
import { css } from 'antd-style';
|
|
10
10
|
import { Fragment, forwardRef, useState } from 'react';
|
|
11
11
|
import { Flexbox } from 'react-layout-kit';
|
|
@@ -79,6 +79,7 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
79
79
|
width = _props$width === void 0 ? '100%' : _props$width,
|
|
80
80
|
_props$height = props.height,
|
|
81
81
|
height = _props$height === void 0 ? '20rem' : _props$height,
|
|
82
|
+
style = props.style,
|
|
82
83
|
rest = _objectWithoutProperties(props, _excluded);
|
|
83
84
|
var CustomTooltip = customTooltip;
|
|
84
85
|
var paddingValue = !showXAxis && !showYAxis ? 0 : 20;
|
|
@@ -97,7 +98,7 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
97
98
|
var categoryColors = constructCategoryColors(categories, colors);
|
|
98
99
|
var yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
|
|
99
100
|
var hasOnValueChange = !!onValueChange;
|
|
100
|
-
function onDotClick(itemData, event) {
|
|
101
|
+
var onDotClick = function onDotClick(itemData, event) {
|
|
101
102
|
event.stopPropagation();
|
|
102
103
|
if (!hasOnValueChange) return;
|
|
103
104
|
if (itemData.index === (activeDot === null || activeDot === void 0 ? void 0 : activeDot.index) && itemData.dataKey === (activeDot === null || activeDot === void 0 ? void 0 : activeDot.dataKey) || hasOnlyOneValueForThisKey(data, itemData.dataKey) && activeLegend && activeLegend === itemData.dataKey) {
|
|
@@ -115,8 +116,8 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
115
116
|
eventType: 'dot'
|
|
116
117
|
}, itemData.payload));
|
|
117
118
|
}
|
|
118
|
-
}
|
|
119
|
-
function onCategoryClick(dataKey) {
|
|
119
|
+
};
|
|
120
|
+
var onCategoryClick = function onCategoryClick(dataKey) {
|
|
120
121
|
if (!hasOnValueChange) return;
|
|
121
122
|
if (dataKey === activeLegend && !activeDot || hasOnlyOneValueForThisKey(data, dataKey) && activeDot && activeDot.dataKey === dataKey) {
|
|
122
123
|
setActiveLegend(undefined);
|
|
@@ -129,11 +130,14 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
129
130
|
});
|
|
130
131
|
}
|
|
131
132
|
setActiveDot(undefined);
|
|
132
|
-
}
|
|
133
|
+
};
|
|
133
134
|
return /*#__PURE__*/_jsx(Flexbox, _objectSpread(_objectSpread({
|
|
134
135
|
className: className,
|
|
135
136
|
height: height,
|
|
136
137
|
ref: ref,
|
|
138
|
+
style: _objectSpread({
|
|
139
|
+
position: 'relative'
|
|
140
|
+
}, style),
|
|
137
141
|
width: width
|
|
138
142
|
}, rest), {}, {
|
|
139
143
|
children: /*#__PURE__*/_jsx(ResponsiveContainer, {
|
|
@@ -229,7 +233,7 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
229
233
|
});
|
|
230
234
|
} : undefined,
|
|
231
235
|
cursor: {
|
|
232
|
-
stroke:
|
|
236
|
+
stroke: theme.colorTextSecondary,
|
|
233
237
|
strokeWidth: 1
|
|
234
238
|
},
|
|
235
239
|
isAnimationActive: false,
|
package/es/ScatterChart/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
5
5
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
6
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
7
7
|
var _templateObject, _templateObject2;
|
|
8
|
-
var _excluded = ["data", "x", "y", "size", "category", "colors", "showOpacity", "sizeRange", "valueFormatter", "startEndOnly", "showXAxis", "showYAxis", "yAxisWidth", "intervalType", "animationDuration", "showAnimation", "showTooltip", "showLegend", "showGridLines", "autoMinXValue", "minXValue", "maxXValue", "autoMinYValue", "minYValue", "maxYValue", "allowDecimals", "noDataText", "onValueChange", "customTooltip", "rotateLabelX", "className", "enableLegendSlider", "tickGap", "xAxisLabel", "yAxisLabel", "width", "height"];
|
|
8
|
+
var _excluded = ["data", "x", "y", "size", "category", "colors", "showOpacity", "sizeRange", "valueFormatter", "startEndOnly", "showXAxis", "showYAxis", "yAxisWidth", "intervalType", "animationDuration", "showAnimation", "showTooltip", "showLegend", "showGridLines", "autoMinXValue", "minXValue", "maxXValue", "autoMinYValue", "minYValue", "maxYValue", "allowDecimals", "noDataText", "onValueChange", "customTooltip", "rotateLabelX", "className", "enableLegendSlider", "tickGap", "xAxisLabel", "yAxisLabel", "width", "height", "style"];
|
|
9
9
|
import { css } from 'antd-style';
|
|
10
10
|
import { forwardRef, useState } from 'react';
|
|
11
11
|
import { Flexbox } from 'react-layout-kit';
|
|
@@ -89,6 +89,7 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
89
89
|
width = _props$width === void 0 ? '100%' : _props$width,
|
|
90
90
|
_props$height = props.height,
|
|
91
91
|
height = _props$height === void 0 ? '20rem' : _props$height,
|
|
92
|
+
style = props.style,
|
|
92
93
|
rest = _objectWithoutProperties(props, _excluded);
|
|
93
94
|
var CustomTooltip = customTooltip;
|
|
94
95
|
var _useState = useState(60),
|
|
@@ -104,7 +105,7 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
104
105
|
activeLegend = _useState6[0],
|
|
105
106
|
setActiveLegend = _useState6[1];
|
|
106
107
|
var hasOnValueChange = !!onValueChange;
|
|
107
|
-
function onNodeClick(data, index, event) {
|
|
108
|
+
var onNodeClick = function onNodeClick(data, index, event) {
|
|
108
109
|
event.stopPropagation();
|
|
109
110
|
if (!hasOnValueChange) return;
|
|
110
111
|
if (deepEqual(activeNode, data.node)) {
|
|
@@ -119,8 +120,8 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
119
120
|
eventType: 'bubble'
|
|
120
121
|
}, data.payload));
|
|
121
122
|
}
|
|
122
|
-
}
|
|
123
|
-
function onCategoryClick(dataKey) {
|
|
123
|
+
};
|
|
124
|
+
var onCategoryClick = function onCategoryClick(dataKey) {
|
|
124
125
|
if (!hasOnValueChange) return;
|
|
125
126
|
if (dataKey === activeLegend && !activeNode) {
|
|
126
127
|
setActiveLegend(undefined);
|
|
@@ -133,7 +134,7 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
133
134
|
});
|
|
134
135
|
}
|
|
135
136
|
setActiveNode(undefined);
|
|
136
|
-
}
|
|
137
|
+
};
|
|
137
138
|
var categories = constructCategories(data, category);
|
|
138
139
|
var categoryColors = constructCategoryColors(categories, colors);
|
|
139
140
|
|
|
@@ -144,6 +145,9 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
144
145
|
className: className,
|
|
145
146
|
height: height,
|
|
146
147
|
ref: ref,
|
|
148
|
+
style: _objectSpread({
|
|
149
|
+
position: 'relative'
|
|
150
|
+
}, style),
|
|
147
151
|
width: width
|
|
148
152
|
}, rest), {}, {
|
|
149
153
|
children: /*#__PURE__*/_jsx(ResponsiveContainer, {
|
|
@@ -250,7 +254,7 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
250
254
|
});
|
|
251
255
|
} : undefined,
|
|
252
256
|
cursor: {
|
|
253
|
-
stroke:
|
|
257
|
+
stroke: theme.colorTextSecondary,
|
|
254
258
|
strokeWidth: 1
|
|
255
259
|
},
|
|
256
260
|
isAnimationActive: false,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import BaseSparkChartProps from "../common/BaseSparkChartProps";
|
|
3
|
+
import { CurveType } from "../types";
|
|
4
|
+
export interface SparkAreaChartProps extends BaseSparkChartProps {
|
|
5
|
+
connectNulls?: boolean;
|
|
6
|
+
curveType?: CurveType;
|
|
7
|
+
showGradient?: boolean;
|
|
8
|
+
stack?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const SparkAreaChart: import("react").ForwardRefExoticComponent<SparkAreaChartProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
11
|
+
export default SparkAreaChart;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
4
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
5
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
6
|
+
var _templateObject, _templateObject2, _templateObject3;
|
|
7
|
+
var _excluded = ["data", "categories", "index", "stack", "colors", "showAnimation", "animationDuration", "showGradient", "curveType", "connectNulls", "noDataText", "autoMinValue", "minValue", "maxValue", "className", "width", "height", "style"];
|
|
8
|
+
import { css } from 'antd-style';
|
|
9
|
+
import { forwardRef } from 'react';
|
|
10
|
+
import { Flexbox } from 'react-layout-kit';
|
|
11
|
+
import { Area, AreaChart as ReChartsAreaChart, ResponsiveContainer, XAxis, YAxis } from 'recharts';
|
|
12
|
+
import { useStyles } from "../AreaChart/styles";
|
|
13
|
+
import NoData from "../common/NoData";
|
|
14
|
+
import { constructCategoryColors, getYAxisDomain } from "../common/utils";
|
|
15
|
+
import { useThemeColorRange } from "../hooks/useThemeColorRange";
|
|
16
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
|
+
var SparkAreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
19
|
+
var _useStyles = useStyles(),
|
|
20
|
+
cx = _useStyles.cx,
|
|
21
|
+
theme = _useStyles.theme;
|
|
22
|
+
var themeColorRange = useThemeColorRange();
|
|
23
|
+
var _props$data = props.data,
|
|
24
|
+
data = _props$data === void 0 ? [] : _props$data,
|
|
25
|
+
_props$categories = props.categories,
|
|
26
|
+
categories = _props$categories === void 0 ? [] : _props$categories,
|
|
27
|
+
index = props.index,
|
|
28
|
+
_props$stack = props.stack,
|
|
29
|
+
stack = _props$stack === void 0 ? false : _props$stack,
|
|
30
|
+
_props$colors = props.colors,
|
|
31
|
+
colors = _props$colors === void 0 ? themeColorRange : _props$colors,
|
|
32
|
+
_props$showAnimation = props.showAnimation,
|
|
33
|
+
showAnimation = _props$showAnimation === void 0 ? false : _props$showAnimation,
|
|
34
|
+
_props$animationDurat = props.animationDuration,
|
|
35
|
+
animationDuration = _props$animationDurat === void 0 ? 900 : _props$animationDurat,
|
|
36
|
+
_props$showGradient = props.showGradient,
|
|
37
|
+
showGradient = _props$showGradient === void 0 ? true : _props$showGradient,
|
|
38
|
+
_props$curveType = props.curveType,
|
|
39
|
+
curveType = _props$curveType === void 0 ? 'linear' : _props$curveType,
|
|
40
|
+
_props$connectNulls = props.connectNulls,
|
|
41
|
+
connectNulls = _props$connectNulls === void 0 ? false : _props$connectNulls,
|
|
42
|
+
_props$noDataText = props.noDataText,
|
|
43
|
+
noDataText = _props$noDataText === void 0 ? /*#__PURE__*/_jsx("div", {}) : _props$noDataText,
|
|
44
|
+
_props$autoMinValue = props.autoMinValue,
|
|
45
|
+
autoMinValue = _props$autoMinValue === void 0 ? false : _props$autoMinValue,
|
|
46
|
+
minValue = props.minValue,
|
|
47
|
+
maxValue = props.maxValue,
|
|
48
|
+
className = props.className,
|
|
49
|
+
_props$width = props.width,
|
|
50
|
+
width = _props$width === void 0 ? 112 : _props$width,
|
|
51
|
+
_props$height = props.height,
|
|
52
|
+
height = _props$height === void 0 ? 48 : _props$height,
|
|
53
|
+
style = props.style,
|
|
54
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
55
|
+
var categoryColors = constructCategoryColors(categories, colors);
|
|
56
|
+
var yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
|
|
57
|
+
return /*#__PURE__*/_jsx(Flexbox, _objectSpread(_objectSpread({
|
|
58
|
+
className: className,
|
|
59
|
+
height: height,
|
|
60
|
+
ref: ref,
|
|
61
|
+
style: _objectSpread({
|
|
62
|
+
position: 'relative'
|
|
63
|
+
}, style),
|
|
64
|
+
width: width
|
|
65
|
+
}, rest), {}, {
|
|
66
|
+
children: /*#__PURE__*/_jsx(ResponsiveContainer, {
|
|
67
|
+
children: data !== null && data !== void 0 && data.length ? /*#__PURE__*/_jsxs(ReChartsAreaChart, {
|
|
68
|
+
data: data,
|
|
69
|
+
margin: {
|
|
70
|
+
bottom: 1,
|
|
71
|
+
left: 1,
|
|
72
|
+
right: 1,
|
|
73
|
+
top: 1
|
|
74
|
+
},
|
|
75
|
+
children: [/*#__PURE__*/_jsx(YAxis, {
|
|
76
|
+
domain: yAxisDomain,
|
|
77
|
+
hide: true
|
|
78
|
+
}), /*#__PURE__*/_jsx(XAxis, {
|
|
79
|
+
dataKey: index,
|
|
80
|
+
hide: true
|
|
81
|
+
}), categories.map(function (category) {
|
|
82
|
+
var _categoryColors$get, _categoryColors$get2;
|
|
83
|
+
return /*#__PURE__*/_jsx("defs", {
|
|
84
|
+
children: showGradient ? /*#__PURE__*/_jsxs("linearGradient", {
|
|
85
|
+
className: cx(css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n color: ", ";\n "])), (_categoryColors$get = categoryColors.get(category)) !== null && _categoryColors$get !== void 0 ? _categoryColors$get : theme.colorPrimary)),
|
|
86
|
+
id: categoryColors.get(category),
|
|
87
|
+
x1: "0",
|
|
88
|
+
x2: "0",
|
|
89
|
+
y1: "0",
|
|
90
|
+
y2: "1",
|
|
91
|
+
children: [/*#__PURE__*/_jsx("stop", {
|
|
92
|
+
offset: "5%",
|
|
93
|
+
stopColor: "currentColor",
|
|
94
|
+
stopOpacity: 0.4
|
|
95
|
+
}), /*#__PURE__*/_jsx("stop", {
|
|
96
|
+
offset: "95%",
|
|
97
|
+
stopColor: "currentColor",
|
|
98
|
+
stopOpacity: 0
|
|
99
|
+
})]
|
|
100
|
+
}) : /*#__PURE__*/_jsx("linearGradient", {
|
|
101
|
+
className: cx(css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n color: ", ";\n "])), (_categoryColors$get2 = categoryColors.get(category)) !== null && _categoryColors$get2 !== void 0 ? _categoryColors$get2 : theme.colorPrimary)),
|
|
102
|
+
id: categoryColors.get(category),
|
|
103
|
+
x1: "0",
|
|
104
|
+
x2: "0",
|
|
105
|
+
y1: "0",
|
|
106
|
+
y2: "1",
|
|
107
|
+
children: /*#__PURE__*/_jsx("stop", {
|
|
108
|
+
stopColor: "currentColor",
|
|
109
|
+
stopOpacity: 0.3
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
}, category);
|
|
113
|
+
}), categories.map(function (category) {
|
|
114
|
+
var _categoryColors$get3;
|
|
115
|
+
return /*#__PURE__*/_jsx(Area, {
|
|
116
|
+
animationDuration: animationDuration,
|
|
117
|
+
className: cx(css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n stroke: ", ";\n "])), (_categoryColors$get3 = categoryColors.get(category)) !== null && _categoryColors$get3 !== void 0 ? _categoryColors$get3 : theme.colorPrimary)),
|
|
118
|
+
connectNulls: connectNulls,
|
|
119
|
+
dataKey: category,
|
|
120
|
+
dot: false,
|
|
121
|
+
fill: "url(#".concat(categoryColors.get(category), ")"),
|
|
122
|
+
isAnimationActive: showAnimation,
|
|
123
|
+
name: category,
|
|
124
|
+
stackId: stack ? 'a' : undefined,
|
|
125
|
+
stroke: "",
|
|
126
|
+
strokeLinecap: "round",
|
|
127
|
+
strokeLinejoin: "round",
|
|
128
|
+
strokeOpacity: 1,
|
|
129
|
+
strokeWidth: 2,
|
|
130
|
+
type: curveType
|
|
131
|
+
}, category);
|
|
132
|
+
})]
|
|
133
|
+
}) : /*#__PURE__*/_jsx(NoData, {
|
|
134
|
+
noDataText: noDataText
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
}));
|
|
138
|
+
});
|
|
139
|
+
SparkAreaChart.displayName = 'AreaChart';
|
|
140
|
+
export default SparkAreaChart;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import BaseSparkChartProps from "../common/BaseSparkChartProps";
|
|
3
|
+
export interface SparkBarChartProps extends BaseSparkChartProps {
|
|
4
|
+
relative?: boolean;
|
|
5
|
+
stack?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare const SparkBarChart: import("react").ForwardRefExoticComponent<SparkBarChartProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
8
|
+
export default SparkBarChart;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
4
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
5
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
6
|
+
var _templateObject;
|
|
7
|
+
var _excluded = ["data", "categories", "index", "colors", "stack", "relative", "animationDuration", "showAnimation", "noDataText", "autoMinValue", "minValue", "maxValue", "className", "width", "height", "style"];
|
|
8
|
+
import { css } from 'antd-style';
|
|
9
|
+
import { forwardRef } from 'react';
|
|
10
|
+
import { Flexbox } from 'react-layout-kit';
|
|
11
|
+
import { Bar, BarChart as ReChartsBarChart, ResponsiveContainer, XAxis, YAxis } from 'recharts';
|
|
12
|
+
import { useStyles } from "../BarChart/styles";
|
|
13
|
+
import NoData from "../common/NoData";
|
|
14
|
+
import { constructCategoryColors, getYAxisDomain } from "../common/utils";
|
|
15
|
+
import { useThemeColorRange } from "../hooks/useThemeColorRange";
|
|
16
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
|
+
var SparkBarChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
19
|
+
var _useStyles = useStyles(),
|
|
20
|
+
cx = _useStyles.cx,
|
|
21
|
+
theme = _useStyles.theme;
|
|
22
|
+
var themeColorRange = useThemeColorRange();
|
|
23
|
+
var _props$data = props.data,
|
|
24
|
+
data = _props$data === void 0 ? [] : _props$data,
|
|
25
|
+
_props$categories = props.categories,
|
|
26
|
+
categories = _props$categories === void 0 ? [] : _props$categories,
|
|
27
|
+
index = props.index,
|
|
28
|
+
_props$colors = props.colors,
|
|
29
|
+
colors = _props$colors === void 0 ? themeColorRange : _props$colors,
|
|
30
|
+
_props$stack = props.stack,
|
|
31
|
+
stack = _props$stack === void 0 ? false : _props$stack,
|
|
32
|
+
_props$relative = props.relative,
|
|
33
|
+
relative = _props$relative === void 0 ? false : _props$relative,
|
|
34
|
+
_props$animationDurat = props.animationDuration,
|
|
35
|
+
animationDuration = _props$animationDurat === void 0 ? 900 : _props$animationDurat,
|
|
36
|
+
_props$showAnimation = props.showAnimation,
|
|
37
|
+
showAnimation = _props$showAnimation === void 0 ? false : _props$showAnimation,
|
|
38
|
+
_props$noDataText = props.noDataText,
|
|
39
|
+
noDataText = _props$noDataText === void 0 ? /*#__PURE__*/_jsx("div", {}) : _props$noDataText,
|
|
40
|
+
_props$autoMinValue = props.autoMinValue,
|
|
41
|
+
autoMinValue = _props$autoMinValue === void 0 ? false : _props$autoMinValue,
|
|
42
|
+
minValue = props.minValue,
|
|
43
|
+
maxValue = props.maxValue,
|
|
44
|
+
className = props.className,
|
|
45
|
+
_props$width = props.width,
|
|
46
|
+
width = _props$width === void 0 ? 112 : _props$width,
|
|
47
|
+
_props$height = props.height,
|
|
48
|
+
height = _props$height === void 0 ? 48 : _props$height,
|
|
49
|
+
style = props.style,
|
|
50
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
51
|
+
var categoryColors = constructCategoryColors(categories, colors);
|
|
52
|
+
var yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
|
|
53
|
+
return /*#__PURE__*/_jsx(Flexbox, _objectSpread(_objectSpread({
|
|
54
|
+
className: className,
|
|
55
|
+
height: height,
|
|
56
|
+
ref: ref,
|
|
57
|
+
style: _objectSpread({
|
|
58
|
+
position: 'relative'
|
|
59
|
+
}, style),
|
|
60
|
+
width: width
|
|
61
|
+
}, rest), {}, {
|
|
62
|
+
children: /*#__PURE__*/_jsx(ResponsiveContainer, {
|
|
63
|
+
children: data !== null && data !== void 0 && data.length ? /*#__PURE__*/_jsxs(ReChartsBarChart, {
|
|
64
|
+
data: data,
|
|
65
|
+
margin: {
|
|
66
|
+
bottom: 0,
|
|
67
|
+
left: -1.5,
|
|
68
|
+
right: -1.5,
|
|
69
|
+
top: 0
|
|
70
|
+
},
|
|
71
|
+
stackOffset: relative ? 'expand' : 'none',
|
|
72
|
+
children: [/*#__PURE__*/_jsx(YAxis, {
|
|
73
|
+
domain: yAxisDomain,
|
|
74
|
+
hide: true
|
|
75
|
+
}), /*#__PURE__*/_jsx(XAxis, {
|
|
76
|
+
dataKey: index,
|
|
77
|
+
hide: true
|
|
78
|
+
}), categories.map(function (category) {
|
|
79
|
+
var _categoryColors$get;
|
|
80
|
+
return /*#__PURE__*/_jsx(Bar, {
|
|
81
|
+
animationDuration: animationDuration,
|
|
82
|
+
className: cx(css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n fill: ", ";\n "])), (_categoryColors$get = categoryColors.get(category)) !== null && _categoryColors$get !== void 0 ? _categoryColors$get : theme.colorPrimary)),
|
|
83
|
+
dataKey: category,
|
|
84
|
+
fill: "",
|
|
85
|
+
isAnimationActive: showAnimation,
|
|
86
|
+
name: category,
|
|
87
|
+
stackId: stack || relative ? 'a' : undefined,
|
|
88
|
+
type: "linear"
|
|
89
|
+
}, category);
|
|
90
|
+
})]
|
|
91
|
+
}) : /*#__PURE__*/_jsx(NoData, {
|
|
92
|
+
noDataText: noDataText
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
}));
|
|
96
|
+
});
|
|
97
|
+
SparkBarChart.displayName = 'SparkBarChart';
|
|
98
|
+
export default SparkBarChart;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import BaseSparkChartProps from "../common/BaseSparkChartProps";
|
|
3
|
+
import { CurveType } from "../types";
|
|
4
|
+
export interface SparkLineChartProps extends BaseSparkChartProps {
|
|
5
|
+
connectNulls?: boolean;
|
|
6
|
+
curveType?: CurveType;
|
|
7
|
+
}
|
|
8
|
+
declare const SparkLineChart: import("react").ForwardRefExoticComponent<SparkLineChartProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
9
|
+
export default SparkLineChart;
|