@lobehub/charts 1.1.0 → 1.3.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/BarChart/index.js +0 -1
- package/es/DataBars/CategoryBar.d.ts +13 -0
- package/es/DataBars/CategoryBar.js +191 -0
- package/es/DataBars/DeltaBar.d.ts +13 -0
- package/es/DataBars/DeltaBar.js +115 -0
- package/es/DataBars/MarkerBar.d.ts +16 -0
- package/es/DataBars/MarkerBar.js +91 -0
- package/es/DataBars/ProgressBar.d.ts +12 -0
- package/es/DataBars/ProgressBar.js +68 -0
- package/es/DataBars/index.d.ts +4 -0
- package/es/DataBars/index.js +4 -0
- package/es/DataBars/styles.d.ts +7 -0
- package/es/DataBars/styles.js +14 -0
- 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/{components/Legend → Legend}/index.js +1 -1
- package/es/common/ChartLegend.js +1 -1
- 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 +3 -1
- package/es/index.js +3 -1
- package/es/types.d.ts +30 -0
- package/es/types.js +8 -1
- package/es/utils/calendar.d.ts +29 -0
- package/es/utils/calendar.js +194 -0
- package/es/utils/index.d.ts +2 -0
- package/es/utils/index.js +26 -0
- package/es/utils/theme.d.ts +2 -0
- package/es/utils/theme.js +49 -0
- package/package.json +7 -4
- /package/es/{components/Legend → Legend}/LegendItem.d.ts +0 -0
- /package/es/{components/Legend → Legend}/LegendItem.js +0 -0
- /package/es/{components/Legend → Legend}/ScrollButton.d.ts +0 -0
- /package/es/{components/Legend → Legend}/ScrollButton.js +0 -0
- /package/es/{components/Legend → Legend}/index.d.ts +0 -0
package/README.md
CHANGED
|
@@ -156,6 +156,7 @@ Every bit counts and your one-time donation sparkles in our galaxy of support! Y
|
|
|
156
156
|
|
|
157
157
|
- **recharts** - <https://github.com/recharts/recharts>
|
|
158
158
|
- **tremor** - <https://github.com/tremorlabs/tremor>
|
|
159
|
+
- **react-activity-calendar** - <https://github.com/grubersjoe/react-activity-calendar>
|
|
159
160
|
|
|
160
161
|
<div align="right">
|
|
161
162
|
|
package/es/BarChart/index.js
CHANGED
|
@@ -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,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
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import type { Activity, Labels, Week } from "../types";
|
|
3
|
+
interface CalendarProps {
|
|
4
|
+
blockMargin: number;
|
|
5
|
+
blockRadius: number;
|
|
6
|
+
blockSize: number;
|
|
7
|
+
colorScale: string[];
|
|
8
|
+
customTooltip?: (activity: Activity) => ReactNode;
|
|
9
|
+
enableAnimation: boolean;
|
|
10
|
+
labelHeight: number;
|
|
11
|
+
labels: Labels;
|
|
12
|
+
maxLevel: number;
|
|
13
|
+
onValueChange?: (value: Activity) => void;
|
|
14
|
+
showTooltip: boolean;
|
|
15
|
+
weeks: Week[];
|
|
16
|
+
}
|
|
17
|
+
declare const Calendar: import("react").NamedExoticComponent<CalendarProps>;
|
|
18
|
+
export default Calendar;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
3
|
+
var _templateObject;
|
|
4
|
+
import { Tooltip } from '@lobehub/ui';
|
|
5
|
+
import { keyframes } from 'antd-style';
|
|
6
|
+
import { Fragment, memo } from 'react';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
9
|
+
var Calendar = /*#__PURE__*/memo(function (_ref) {
|
|
10
|
+
var weeks = _ref.weeks,
|
|
11
|
+
maxLevel = _ref.maxLevel,
|
|
12
|
+
enableAnimation = _ref.enableAnimation,
|
|
13
|
+
colorScale = _ref.colorScale,
|
|
14
|
+
blockSize = _ref.blockSize,
|
|
15
|
+
blockRadius = _ref.blockRadius,
|
|
16
|
+
blockMargin = _ref.blockMargin,
|
|
17
|
+
labelHeight = _ref.labelHeight,
|
|
18
|
+
showTooltip = _ref.showTooltip,
|
|
19
|
+
customTooltip = _ref.customTooltip,
|
|
20
|
+
labels = _ref.labels,
|
|
21
|
+
onValueChange = _ref.onValueChange;
|
|
22
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
23
|
+
children: weeks.map(function (week, weekIndex) {
|
|
24
|
+
return week.map(function (activity, dayIndex) {
|
|
25
|
+
if (!activity) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
if (activity.level < 0 || activity.level > maxLevel) {
|
|
29
|
+
throw new RangeError("Provided activity level ".concat(activity.level, " for ").concat(activity.date, " is out of range. It must be between 0 and ").concat(maxLevel, "."));
|
|
30
|
+
}
|
|
31
|
+
var style = enableAnimation ? {
|
|
32
|
+
animation: "".concat(keyframes(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n 0% {\n fill: var(--lobe-heatmaps-loading);\n }\n 50% {\n fill: var(--lobe-heatmaps-loading-active);\n }\n 100% {\n fill: var(--lobe-heatmaps-loading);\n }\n "]))), " 1.75s ease-in-out infinite"),
|
|
33
|
+
animationDelay: "".concat(weekIndex * 20 + dayIndex * 20, "ms")
|
|
34
|
+
} : undefined;
|
|
35
|
+
var block = /*#__PURE__*/_jsx("rect", {
|
|
36
|
+
"data-date": activity.date,
|
|
37
|
+
"data-level": activity.level,
|
|
38
|
+
fill: colorScale[activity.level],
|
|
39
|
+
height: blockSize,
|
|
40
|
+
onClick: function onClick() {
|
|
41
|
+
return onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(activity);
|
|
42
|
+
},
|
|
43
|
+
rx: blockRadius,
|
|
44
|
+
ry: blockRadius,
|
|
45
|
+
style: _objectSpread({
|
|
46
|
+
cursor: onValueChange ? 'pointer' : undefined
|
|
47
|
+
}, style),
|
|
48
|
+
width: blockSize,
|
|
49
|
+
x: 0,
|
|
50
|
+
y: labelHeight + (blockSize + blockMargin) * dayIndex
|
|
51
|
+
});
|
|
52
|
+
return /*#__PURE__*/_jsx(Fragment, {
|
|
53
|
+
children: showTooltip ? /*#__PURE__*/_jsx(Tooltip, {
|
|
54
|
+
title: customTooltip ? customTooltip(activity) : labels.tooltip ? labels.tooltip.replace('{{count}}', String(activity.count)).replace('{{date}}', String(activity.date)) : "".concat(activity.count, " activities on ").concat(activity.date),
|
|
55
|
+
children: block
|
|
56
|
+
}) : block
|
|
57
|
+
}, activity.date);
|
|
58
|
+
});
|
|
59
|
+
}).map(function (week, x) {
|
|
60
|
+
return /*#__PURE__*/_jsx("g", {
|
|
61
|
+
transform: "translate(".concat((blockSize + blockMargin) * x, ", 0)"),
|
|
62
|
+
children: week
|
|
63
|
+
}, x);
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
export default Calendar;
|