@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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { Labels, Week } from "../types";
|
|
3
|
+
interface ChartLabelsProps {
|
|
4
|
+
blockMargin: number;
|
|
5
|
+
blockSize: number;
|
|
6
|
+
hideMonthLabels: boolean;
|
|
7
|
+
labelHeight: number;
|
|
8
|
+
labelMargin: number;
|
|
9
|
+
labels: Labels;
|
|
10
|
+
showWeekdayLabels: boolean;
|
|
11
|
+
weekStart: number;
|
|
12
|
+
weeks: Week[];
|
|
13
|
+
}
|
|
14
|
+
declare const ChartLabels: import("react").NamedExoticComponent<ChartLabelsProps>;
|
|
15
|
+
export default ChartLabels;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import { getMonthLabels } from "../utils/calendar";
|
|
3
|
+
import { useStyles } from "./styles";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
6
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
var ChartLabels = /*#__PURE__*/memo(function (_ref) {
|
|
8
|
+
var labels = _ref.labels,
|
|
9
|
+
blockSize = _ref.blockSize,
|
|
10
|
+
labelHeight = _ref.labelHeight,
|
|
11
|
+
blockMargin = _ref.blockMargin,
|
|
12
|
+
labelMargin = _ref.labelMargin,
|
|
13
|
+
showWeekdayLabels = _ref.showWeekdayLabels,
|
|
14
|
+
hideMonthLabels = _ref.hideMonthLabels,
|
|
15
|
+
weeks = _ref.weeks,
|
|
16
|
+
weekStart = _ref.weekStart;
|
|
17
|
+
var _useStyles = useStyles(),
|
|
18
|
+
cx = _useStyles.cx;
|
|
19
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
20
|
+
children: [showWeekdayLabels && weeks[0] && /*#__PURE__*/_jsx("g", {
|
|
21
|
+
className: cx('legend-weekday'),
|
|
22
|
+
children: weeks[0].map(function (_, index) {
|
|
23
|
+
var _labels$weekdays;
|
|
24
|
+
if (index % 2 === 0) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
var dayIndex = (index + weekStart) % 7;
|
|
28
|
+
return /*#__PURE__*/_jsx("text", {
|
|
29
|
+
dominantBaseline: "middle",
|
|
30
|
+
textAnchor: "end",
|
|
31
|
+
x: -labelMargin,
|
|
32
|
+
y: labelHeight + (blockSize + blockMargin) * index + blockSize / 2,
|
|
33
|
+
children: labels === null || labels === void 0 || (_labels$weekdays = labels.weekdays) === null || _labels$weekdays === void 0 ? void 0 : _labels$weekdays[dayIndex]
|
|
34
|
+
}, index);
|
|
35
|
+
})
|
|
36
|
+
}), !hideMonthLabels && /*#__PURE__*/_jsx("g", {
|
|
37
|
+
className: cx('legend-month'),
|
|
38
|
+
children: getMonthLabels(weeks, labels.months).map(function (_ref2) {
|
|
39
|
+
var label = _ref2.label,
|
|
40
|
+
weekIndex = _ref2.weekIndex;
|
|
41
|
+
return /*#__PURE__*/_jsx("text", {
|
|
42
|
+
dominantBaseline: "hanging",
|
|
43
|
+
x: (blockSize + blockMargin) * weekIndex,
|
|
44
|
+
children: label
|
|
45
|
+
}, weekIndex);
|
|
46
|
+
})
|
|
47
|
+
})]
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
export default ChartLabels;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface FooterProps {
|
|
3
|
+
blockRadius: number;
|
|
4
|
+
blockSize: number;
|
|
5
|
+
colorScale: string[];
|
|
6
|
+
hideColorLegend?: boolean;
|
|
7
|
+
hideTotalCount?: boolean;
|
|
8
|
+
labels: {
|
|
9
|
+
legend: {
|
|
10
|
+
less: string;
|
|
11
|
+
more: string;
|
|
12
|
+
};
|
|
13
|
+
totalCount?: string;
|
|
14
|
+
};
|
|
15
|
+
loading: boolean;
|
|
16
|
+
maxLevel: number;
|
|
17
|
+
totalCount: number;
|
|
18
|
+
weekdayLabelOffset?: number;
|
|
19
|
+
year: number;
|
|
20
|
+
}
|
|
21
|
+
declare const Footer: import("react").NamedExoticComponent<FooterProps>;
|
|
22
|
+
export default Footer;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import { useStyles } from "./styles";
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
var Footer = /*#__PURE__*/memo(function (_ref) {
|
|
6
|
+
var hideTotalCount = _ref.hideTotalCount,
|
|
7
|
+
hideColorLegend = _ref.hideColorLegend,
|
|
8
|
+
weekdayLabelOffset = _ref.weekdayLabelOffset,
|
|
9
|
+
loading = _ref.loading,
|
|
10
|
+
labels = _ref.labels,
|
|
11
|
+
year = _ref.year,
|
|
12
|
+
maxLevel = _ref.maxLevel,
|
|
13
|
+
blockSize = _ref.blockSize,
|
|
14
|
+
colorScale = _ref.colorScale,
|
|
15
|
+
blockRadius = _ref.blockRadius,
|
|
16
|
+
totalCount = _ref.totalCount;
|
|
17
|
+
var _useStyles = useStyles(),
|
|
18
|
+
cx = _useStyles.cx,
|
|
19
|
+
styles = _useStyles.styles;
|
|
20
|
+
return /*#__PURE__*/_jsxs("footer", {
|
|
21
|
+
className: cx('footer', styles.footer),
|
|
22
|
+
style: {
|
|
23
|
+
marginLeft: weekdayLabelOffset
|
|
24
|
+
},
|
|
25
|
+
children: [loading && /*#__PURE__*/_jsx("div", {
|
|
26
|
+
children: "\xA0"
|
|
27
|
+
}), !loading && !hideTotalCount && /*#__PURE__*/_jsx("div", {
|
|
28
|
+
className: cx('count'),
|
|
29
|
+
children: labels.totalCount ? labels.totalCount.replace('{{count}}', String(totalCount)).replace('{{year}}', String(year)) : "".concat(totalCount, " activities in ").concat(year)
|
|
30
|
+
}), !loading && !hideColorLegend && /*#__PURE__*/_jsxs("div", {
|
|
31
|
+
className: cx('legend-colors', styles.legendColors),
|
|
32
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
33
|
+
style: {
|
|
34
|
+
marginRight: '0.4em'
|
|
35
|
+
},
|
|
36
|
+
children: labels.legend.less
|
|
37
|
+
}), Array.from({
|
|
38
|
+
length: maxLevel + 1
|
|
39
|
+
}).fill(null).map(function (_, level) {
|
|
40
|
+
return /*#__PURE__*/_jsx("svg", {
|
|
41
|
+
height: blockSize,
|
|
42
|
+
width: blockSize,
|
|
43
|
+
children: /*#__PURE__*/_jsx("rect", {
|
|
44
|
+
fill: colorScale[level],
|
|
45
|
+
height: blockSize,
|
|
46
|
+
rx: blockRadius,
|
|
47
|
+
ry: blockRadius,
|
|
48
|
+
width: blockSize
|
|
49
|
+
})
|
|
50
|
+
}, level);
|
|
51
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
52
|
+
style: {
|
|
53
|
+
marginLeft: '0.4em'
|
|
54
|
+
},
|
|
55
|
+
children: labels.legend.more
|
|
56
|
+
})]
|
|
57
|
+
})]
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
export default Footer;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Day as WeekDay } from 'date-fns';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { FlexboxProps } from 'react-layout-kit';
|
|
4
|
+
import { NoDataProps } from "../common/NoData";
|
|
5
|
+
import type { Activity, Labels } from "../types";
|
|
6
|
+
export interface HeatmapsProps extends FlexboxProps {
|
|
7
|
+
blockMargin?: number;
|
|
8
|
+
blockRadius?: number;
|
|
9
|
+
blockSize?: number;
|
|
10
|
+
colors?: string[];
|
|
11
|
+
customTooltip?: (activity: Activity) => ReactNode;
|
|
12
|
+
data: Array<Activity>;
|
|
13
|
+
fontSize?: number;
|
|
14
|
+
hideColorLegend?: boolean;
|
|
15
|
+
hideMonthLabels?: boolean;
|
|
16
|
+
hideTotalCount?: boolean;
|
|
17
|
+
labels?: Labels;
|
|
18
|
+
loading?: boolean;
|
|
19
|
+
maxLevel?: number;
|
|
20
|
+
noDataText?: NoDataProps['noDataText'];
|
|
21
|
+
onValueChange?: (value: Activity) => void;
|
|
22
|
+
showTooltip?: boolean;
|
|
23
|
+
showWeekdayLabels?: boolean;
|
|
24
|
+
totalCount?: number;
|
|
25
|
+
weekStart?: WeekDay;
|
|
26
|
+
}
|
|
27
|
+
declare const Heatmaps: import("react").ForwardRefExoticComponent<HeatmapsProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
28
|
+
export default Heatmaps;
|
|
@@ -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
|
+
});
|
|
@@ -8,7 +8,7 @@ import { createStyles } from 'antd-style';
|
|
|
8
8
|
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
9
9
|
import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
|
|
10
10
|
import { Flexbox } from 'react-layout-kit';
|
|
11
|
-
import { useThemeColorRange } from "
|
|
11
|
+
import { useThemeColorRange } from "../hooks/useThemeColorRange";
|
|
12
12
|
import LegendItem from "./LegendItem";
|
|
13
13
|
import ScrollButton from "./ScrollButton";
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
package/es/common/ChartLegend.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
2
|
import { Flexbox } from 'react-layout-kit';
|
|
3
|
-
import Legend from "../
|
|
3
|
+
import Legend from "../Legend";
|
|
4
4
|
import { useOnWindowResize } from "../hooks/useOnWindowResize";
|
|
5
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
6
|
var calculateHeight = function calculateHeight(height) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
+
import { isOnSeverSide } from "../utils";
|
|
2
3
|
export var useOnWindowResize = function useOnWindowResize(handler) {
|
|
3
4
|
useEffect(function () {
|
|
4
|
-
if (
|
|
5
|
+
if (isOnSeverSide) return;
|
|
5
6
|
var handleResize = function handleResize() {
|
|
6
7
|
handler();
|
|
7
8
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const usePrefersReducedMotion: () => boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { isOnSeverSide } from "../utils";
|
|
4
|
+
var query = '(prefers-reduced-motion: reduce)';
|
|
5
|
+
export var usePrefersReducedMotion = function usePrefersReducedMotion() {
|
|
6
|
+
var _useState = useState(true),
|
|
7
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
8
|
+
prefersReducedMotion = _useState2[0],
|
|
9
|
+
setPrefersReducedMotion = _useState2[1];
|
|
10
|
+
useEffect(function () {
|
|
11
|
+
if (isOnSeverSide) return;
|
|
12
|
+
var mediaQuery = window.matchMedia(query);
|
|
13
|
+
setPrefersReducedMotion(mediaQuery.matches);
|
|
14
|
+
var onChange = function onChange(event) {
|
|
15
|
+
setPrefersReducedMotion(event.matches);
|
|
16
|
+
};
|
|
17
|
+
mediaQuery.addEventListener('change', onChange);
|
|
18
|
+
return function () {
|
|
19
|
+
mediaQuery.removeEventListener('change', onChange);
|
|
20
|
+
};
|
|
21
|
+
}, []);
|
|
22
|
+
return prefersReducedMotion;
|
|
23
|
+
};
|
package/es/index.d.ts
CHANGED
|
@@ -2,8 +2,10 @@ export { default as AreaChart, type AreaChartProps } from './AreaChart';
|
|
|
2
2
|
export { default as BarChart, type BarChartProps } from './BarChart';
|
|
3
3
|
export { type Bar, default as BarList, type BarListProps } from './BarList';
|
|
4
4
|
export { default as ChartTooltipFrame } from './common/ChartTooltip/ChartTooltipFrame';
|
|
5
|
-
export
|
|
5
|
+
export * from './DataBars';
|
|
6
6
|
export { default as DonutChart, type DonutChartProps } from './DonutChart';
|
|
7
|
+
export { default as Heatmaps, type HeatmapsProps } from './Heatmaps';
|
|
8
|
+
export { default as Legend, type LegendProps } from './Legend';
|
|
7
9
|
export { default as LineChart, type LineChartProps } from './LineChart';
|
|
8
10
|
export { default as ScatterChart, type ScatterChartProps } from './ScatterChart';
|
|
9
11
|
export * from './SparkChart';
|
package/es/index.js
CHANGED
|
@@ -2,8 +2,10 @@ export { default as AreaChart } from "./AreaChart";
|
|
|
2
2
|
export { default as BarChart } from "./BarChart";
|
|
3
3
|
export { default as BarList } from "./BarList";
|
|
4
4
|
export { default as ChartTooltipFrame } from "./common/ChartTooltip/ChartTooltipFrame";
|
|
5
|
-
export
|
|
5
|
+
export * from "./DataBars";
|
|
6
6
|
export { default as DonutChart } from "./DonutChart";
|
|
7
|
+
export { default as Heatmaps } from "./Heatmaps";
|
|
8
|
+
export { default as Legend } from "./Legend";
|
|
7
9
|
export { default as LineChart } from "./LineChart";
|
|
8
10
|
export { default as ScatterChart } from "./ScatterChart";
|
|
9
11
|
export * from "./SparkChart";
|
package/es/types.d.ts
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
import type { AnimationEvent, ClipboardEvent, CompositionEvent, DOMAttributes, DragEvent, FocusEvent, FormEvent, HTMLAttributes, JSXElementConstructor, KeyboardEvent, MouseEvent, PointerEvent, ReactElement, SVGAttributes, SyntheticEvent, TouchEvent, TransitionEvent, UIEvent, WheelEvent } from 'react';
|
|
2
|
+
export interface Activity {
|
|
3
|
+
count: number;
|
|
4
|
+
date: string;
|
|
5
|
+
level: number;
|
|
6
|
+
}
|
|
7
|
+
export type Week = Array<Activity | undefined>;
|
|
8
|
+
export type Labels = Partial<{
|
|
9
|
+
legend: Partial<{
|
|
10
|
+
less: string;
|
|
11
|
+
more: string;
|
|
12
|
+
}>;
|
|
13
|
+
months: Array<string>;
|
|
14
|
+
tooltip: string;
|
|
15
|
+
totalCount: string;
|
|
16
|
+
weekdays: Array<string>;
|
|
17
|
+
}>;
|
|
18
|
+
interface BlockAttributes extends SVGAttributes<SVGRectElement>, HTMLAttributes<SVGRectElement> {
|
|
19
|
+
}
|
|
20
|
+
export type BlockElement = ReactElement<BlockAttributes, JSXElementConstructor<SVGRectElement>>;
|
|
21
|
+
export type SVGRectEventHandler = Omit<DOMAttributes<SVGRectElement>, 'css' | 'children' | 'dangerouslySetInnerHTML'>;
|
|
22
|
+
export type EventHandlerMap = {
|
|
23
|
+
[key in keyof SVGRectEventHandler]: (...event: Parameters<NonNullable<SVGRectEventHandler[keyof SVGRectEventHandler]>>) => (activity: Activity) => void;
|
|
24
|
+
};
|
|
25
|
+
export type ReactEvent<E extends Element> = AnimationEvent<E> & ClipboardEvent<E> & CompositionEvent<E> & DragEvent<E> & FocusEvent<E> & FormEvent<E> & KeyboardEvent<E> & MouseEvent<E> & PointerEvent<E> & SyntheticEvent<E> & TouchEvent<E> & TransitionEvent<E> & UIEvent<E> & WheelEvent<E>;
|
|
1
26
|
type FixedProps = {
|
|
2
27
|
categoryClicked: string;
|
|
3
28
|
eventType: 'dot' | 'category' | 'bar' | 'slice' | 'bubble';
|
|
@@ -17,4 +42,9 @@ export type ScatterChartValueFormatter = {
|
|
|
17
42
|
x?: ValueFormatter;
|
|
18
43
|
y?: ValueFormatter;
|
|
19
44
|
};
|
|
45
|
+
declare const deltaTypeValues: readonly ["increase", "moderateIncrease", "decrease", "moderateDecrease", "unchanged"];
|
|
46
|
+
export type DeltaType = (typeof deltaTypeValues)[number];
|
|
47
|
+
export declare const DeltaTypes: {
|
|
48
|
+
[key: string]: DeltaType;
|
|
49
|
+
};
|
|
20
50
|
export {};
|
package/es/types.js
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
var deltaTypeValues = ['increase', 'moderateIncrease', 'decrease', 'moderateDecrease', 'unchanged'];
|
|
2
|
+
export var DeltaTypes = {
|
|
3
|
+
Decrease: 'decrease',
|
|
4
|
+
Increase: 'increase',
|
|
5
|
+
ModerateDecrease: 'moderateDecrease',
|
|
6
|
+
ModerateIncrease: 'moderateIncrease',
|
|
7
|
+
Unchanged: 'unchanged'
|
|
8
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Day as WeekDay } from 'date-fns';
|
|
2
|
+
import type { Activity, Week } from "../types";
|
|
3
|
+
export declare const DEFAULT_MONTH_LABELS: string[];
|
|
4
|
+
export declare const DEFAULT_LABELS: {
|
|
5
|
+
legend: {
|
|
6
|
+
less: string;
|
|
7
|
+
more: string;
|
|
8
|
+
};
|
|
9
|
+
months: string[];
|
|
10
|
+
tooltip: string;
|
|
11
|
+
totalCount: string;
|
|
12
|
+
weekdays: string[];
|
|
13
|
+
};
|
|
14
|
+
interface MonthLabel {
|
|
15
|
+
label: string;
|
|
16
|
+
weekIndex: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const groupByWeeks: (activities: Array<Activity>, weekStart?: WeekDay) => Array<Week>;
|
|
19
|
+
export declare const getMonthLabels: (weeks: Array<Week>, monthNames?: Array<string>) => Array<MonthLabel>;
|
|
20
|
+
export declare const generateEmptyData: () => Array<Activity>;
|
|
21
|
+
export declare const generateTestData: (args: {
|
|
22
|
+
interval?: {
|
|
23
|
+
end: Date;
|
|
24
|
+
start: Date;
|
|
25
|
+
} | undefined;
|
|
26
|
+
maxLevel?: number | undefined;
|
|
27
|
+
}) => Array<Activity>;
|
|
28
|
+
export declare const maxWeekdayLabelLength: (firstWeek: Week, weekStart: number, labels: string[], fontSize: number) => number;
|
|
29
|
+
export {};
|