bento-charts 2.6.8 → 2.7.1
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/dist/Components/Charts/BaseBarChart.d.ts +4 -0
- package/dist/Components/Charts/BaseBarChart.js +62 -0
- package/dist/Components/Charts/BaseBarChart.js.map +1 -0
- package/dist/Components/Charts/BentoBarChart.d.ts +3 -2
- package/dist/Components/Charts/BentoBarChart.js +6 -48
- package/dist/Components/Charts/BentoBarChart.js.map +1 -1
- package/dist/Components/Charts/BentoHistogram.d.ts +4 -0
- package/dist/Components/Charts/BentoHistogram.js +32 -0
- package/dist/Components/Charts/BentoHistogram.js.map +1 -0
- package/dist/constants/chartConstants.d.ts +1 -0
- package/dist/constants/chartConstants.js +15 -0
- package/dist/constants/chartConstants.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/types/chartTypes.d.ts +10 -2
- package/package.json +1 -1
- package/src/Components/Charts/BaseBarChart.tsx +137 -0
- package/src/Components/Charts/BentoBarChart.tsx +7 -123
- package/src/Components/Charts/BentoHistogram.tsx +13 -0
- package/src/constants/chartConstants.ts +16 -0
- package/src/index.ts +1 -0
- package/src/types/chartTypes.ts +13 -3
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useCallback } from 'react';
|
|
14
|
+
import { Bar, BarChart, CartesianGrid, Cell, Label, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts';
|
|
15
|
+
import { TOOLTIP_STYLE, COUNT_STYLE, LABEL_STYLE, MAX_TICK_LABEL_CHARS, TITLE_STYLE, TICKS_SHOW_ALL_LABELS_BELOW, UNITS_LABEL_OFFSET, TICK_MARGIN, COUNT_KEY, } from '../../constants/chartConstants';
|
|
16
|
+
import { useChartTranslation } from '../../ChartConfigProvider';
|
|
17
|
+
import NoData from '../NoData';
|
|
18
|
+
import { useTransformedChartData } from '../../util/chartUtils';
|
|
19
|
+
import ChartWrapper from './ChartWrapper';
|
|
20
|
+
var tickFormatter = function (tickLabel) {
|
|
21
|
+
if (tickLabel.length <= MAX_TICK_LABEL_CHARS) {
|
|
22
|
+
return tickLabel;
|
|
23
|
+
}
|
|
24
|
+
return "".concat(tickLabel.substring(0, MAX_TICK_LABEL_CHARS), "...");
|
|
25
|
+
};
|
|
26
|
+
var BAR_CHART_MARGINS = { top: 10, bottom: 100, right: 20 };
|
|
27
|
+
var BaseBarChart = function (_a) {
|
|
28
|
+
var height = _a.height, width = _a.width, units = _a.units, title = _a.title, onClick = _a.onClick, chartFill = _a.chartFill, otherFill = _a.otherFill, params = __rest(_a, ["height", "width", "units", "title", "onClick", "chartFill", "otherFill"]);
|
|
29
|
+
var t = useChartTranslation();
|
|
30
|
+
var fill = function (entry, index) {
|
|
31
|
+
return entry.x === 'missing' ? otherFill : chartFill[index % chartFill.length];
|
|
32
|
+
};
|
|
33
|
+
var data = useTransformedChartData(params, true);
|
|
34
|
+
var totalCount = data.reduce(function (sum, e) { return sum + e.y; }, 0);
|
|
35
|
+
var onHover = useCallback(function (_data, _index, e) {
|
|
36
|
+
var target = e.target;
|
|
37
|
+
if (onClick && target)
|
|
38
|
+
target.style.cursor = 'pointer';
|
|
39
|
+
}, [onClick]);
|
|
40
|
+
if (data.length === 0) {
|
|
41
|
+
return _jsx(NoData, { height: height });
|
|
42
|
+
}
|
|
43
|
+
// Regarding XAxis.ticks below:
|
|
44
|
+
// The weird conditional is added from https://github.com/recharts/recharts/issues/2593#issuecomment-1311678397
|
|
45
|
+
// Basically, if data is empty, Recharts will default to a domain of [0, "auto"] and our tickFormatter trips up
|
|
46
|
+
// on formatting a non-string. This hack manually overrides the ticks for the axis and blanks it out.
|
|
47
|
+
// - David L, 2023-01-03
|
|
48
|
+
return (_jsxs(ChartWrapper, { responsive: typeof width !== 'number', children: [_jsx("div", { style: TITLE_STYLE, children: title }), _jsx(ResponsiveContainer, { width: width !== null && width !== void 0 ? width : '100%', height: height, children: _jsxs(BarChart, { data: data, margin: BAR_CHART_MARGINS, children: [_jsx(XAxis, { dataKey: "x", height: 20, angle: -45, ticks: data.length ? undefined : [''], tickFormatter: tickFormatter, tickMargin: TICK_MARGIN, textAnchor: "end", interval: data.length < TICKS_SHOW_ALL_LABELS_BELOW ? 0 : 'preserveStartEnd', children: _jsx(Label, { value: units, offset: UNITS_LABEL_OFFSET, position: "insideBottom" }) }), _jsx(YAxis, { children: _jsx(Label, { value: t[COUNT_KEY], offset: -10, position: "left", angle: 270 }) }), _jsx(CartesianGrid, { strokeDasharray: "3 3", vertical: false }), _jsx(Tooltip, { content: _jsx(BarTooltip, { totalCount: totalCount }) }), _jsx(Bar, { dataKey: "y", isAnimationActive: false, onClick: onClick, onMouseEnter: onHover, maxBarSize: 70, children: data.map(function (entry, index) { return (_jsx(Cell, { fill: fill(entry, index) }, entry.x)); }) })] }) })] }));
|
|
49
|
+
};
|
|
50
|
+
var BarTooltip = function (_a) {
|
|
51
|
+
var _b, _c, _d;
|
|
52
|
+
var active = _a.active, payload = _a.payload, totalCount = _a.totalCount;
|
|
53
|
+
if (!active) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
var name = (payload && ((_c = (_b = payload[0]) === null || _b === void 0 ? void 0 : _b.payload) === null || _c === void 0 ? void 0 : _c.x)) || '';
|
|
57
|
+
var value = (payload && ((_d = payload[0]) === null || _d === void 0 ? void 0 : _d.value)) || 0;
|
|
58
|
+
var percentage = totalCount ? Math.round((value / totalCount) * 100) : 0;
|
|
59
|
+
return (_jsxs("div", { style: TOOLTIP_STYLE, children: [_jsx("p", { style: LABEL_STYLE, children: name }), _jsxs("p", { style: COUNT_STYLE, children: [value, " (", percentage, "%)"] })] }));
|
|
60
|
+
};
|
|
61
|
+
export default BaseBarChart;
|
|
62
|
+
//# sourceMappingURL=BaseBarChart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseBarChart.js","sourceRoot":"","sources":["../../../src/Components/Charts/BaseBarChart.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAc,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EACL,GAAG,EACH,QAAQ,EAER,aAAa,EACb,IAAI,EACJ,KAAK,EACL,mBAAmB,EACnB,OAAO,EACP,KAAK,EACL,KAAK,GACN,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,aAAa,EACb,WAAW,EACX,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,2BAA2B,EAC3B,kBAAkB,EAClB,WAAW,EACX,SAAS,GACV,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,IAAM,aAAa,GAAG,UAAC,SAAiB;IACtC,IAAI,SAAS,CAAC,MAAM,IAAI,oBAAoB,EAAE,CAAC;QAC7C,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,UAAG,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,oBAAoB,CAAC,QAAK,CAAC;AAC9D,CAA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/F,IAAI,CAAC,GAAG,CAAC,UAAC,KAAK,EAAE,KAAK,IAAK,OAAA,CAC1B,KAAC,IAAI,IAAe,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,IAAjC,KAAK,CAAC,CAAC,CAA8B,CACjD,EAF2B,CAE3B,CAAC,GACE,IACG,GACS,IACT,CAChB,CAAC;AACJ,CAAC,CAAC;AAEF,IAAM,UAAU,GAAG,UAAC,EAQnB;;QAPC,MAAM,YAAA,EACN,OAAO,aAAA,EACP,UAAU,gBAAA;IAMV,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAM,IAAI,GAAG,CAAC,OAAO,KAAI,MAAA,MAAA,OAAO,CAAC,CAAC,CAAC,0CAAE,OAAO,0CAAE,CAAC,CAAA,CAAC,IAAI,EAAE,CAAC;IACvD,IAAM,KAAK,GAAG,CAAC,OAAO,KAAI,MAAA,OAAO,CAAC,CAAC,CAAC,0CAAE,KAAK,CAAA,CAAC,IAAI,CAAC,CAAC;IAClD,IAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3E,OAAO,CACL,eAAK,KAAK,EAAE,aAAa,aACvB,YAAG,KAAK,EAAE,WAAW,YAAG,IAAI,GAAK,EACjC,aAAG,KAAK,EAAE,WAAW,aAClB,KAAK,QAAI,UAAU,UAClB,IACA,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BarChartProps } from '../../types/chartTypes';
|
|
3
|
+
declare const BentoBarChart: React.FC<BarChartProps>;
|
|
3
4
|
export default BentoBarChart;
|
|
@@ -20,55 +20,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
}
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
|
-
import { jsx as _jsx
|
|
24
|
-
import {
|
|
25
|
-
import
|
|
26
|
-
import { TOOLTIP_STYLE, TOOLTIP_OTHER_PROPS, COUNT_STYLE, LABEL_STYLE, MAX_TICK_LABEL_CHARS, TITLE_STYLE, TICKS_SHOW_ALL_LABELS_BELOW, UNITS_LABEL_OFFSET, TICK_MARGIN, COUNT_KEY, } from '../../constants/chartConstants';
|
|
27
|
-
import { useChartTheme, useChartTranslation } from '../../ChartConfigProvider';
|
|
28
|
-
import NoData from '../NoData';
|
|
29
|
-
import { useTransformedChartData } from '../../util/chartUtils';
|
|
30
|
-
import ChartWrapper from './ChartWrapper';
|
|
31
|
-
var tickFormatter = function (tickLabel) {
|
|
32
|
-
if (tickLabel.length <= MAX_TICK_LABEL_CHARS) {
|
|
33
|
-
return tickLabel;
|
|
34
|
-
}
|
|
35
|
-
return "".concat(tickLabel.substring(0, MAX_TICK_LABEL_CHARS), "...");
|
|
36
|
-
};
|
|
37
|
-
var BAR_CHART_MARGINS = { top: 10, bottom: 100, right: 20 };
|
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
+
import { useChartTheme } from '../../ChartConfigProvider';
|
|
25
|
+
import BaseBarChart from './BaseBarChart';
|
|
38
26
|
var BentoBarChart = function (_a) {
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
var fill = function (entry, index) {
|
|
43
|
-
return entry.x === 'missing' ? other : chartFill[index % chartFill.length];
|
|
44
|
-
};
|
|
45
|
-
var data = useTransformedChartData(params, true);
|
|
46
|
-
var totalCount = data.reduce(function (sum, e) { return sum + e.y; }, 0);
|
|
47
|
-
var onHover = useCallback(function (_data, _index, e) {
|
|
48
|
-
var target = e.target;
|
|
49
|
-
if (onClick && target)
|
|
50
|
-
target.style.cursor = 'pointer';
|
|
51
|
-
}, [onClick]);
|
|
52
|
-
if (data.length === 0) {
|
|
53
|
-
return _jsx(NoData, { height: height });
|
|
54
|
-
}
|
|
55
|
-
// Regarding XAxis.ticks below:
|
|
56
|
-
// The weird conditional is added from https://github.com/recharts/recharts/issues/2593#issuecomment-1311678397
|
|
57
|
-
// Basically, if data is empty, Recharts will default to a domain of [0, "auto"] and our tickFormatter trips up
|
|
58
|
-
// on formatting a non-string. This hack manually overrides the ticks for the axis and blanks it out.
|
|
59
|
-
// - David L, 2023-01-03
|
|
60
|
-
return (_jsxs(ChartWrapper, { responsive: typeof width !== 'number', children: [_jsx("div", { style: TITLE_STYLE, children: title }), _jsx(ResponsiveContainer, { width: width !== null && width !== void 0 ? width : '100%', height: height, children: _jsxs(BarChart, { data: data, margin: BAR_CHART_MARGINS, children: [_jsx(XAxis, { dataKey: "x", height: 20, angle: -45, ticks: data.length ? undefined : [''], tickFormatter: tickFormatter, tickMargin: TICK_MARGIN, textAnchor: "end", interval: data.length < TICKS_SHOW_ALL_LABELS_BELOW ? 0 : 'preserveStartEnd', children: _jsx(Label, { value: units, offset: UNITS_LABEL_OFFSET, position: "insideBottom" }) }), _jsx(YAxis, { children: _jsx(Label, { value: t[COUNT_KEY], offset: -10, position: "left", angle: 270 }) }), _jsx(CartesianGrid, { strokeDasharray: "3 3", vertical: false }), _jsx(Tooltip, __assign({}, TOOLTIP_OTHER_PROPS, { content: _jsx(BarTooltip, { totalCount: totalCount }) })), _jsx(Bar, { dataKey: "y", isAnimationActive: false, onClick: onClick, onMouseEnter: onHover, maxBarSize: 70, children: data.map(function (entry, index) { return (_jsx(Cell, { fill: fill(entry, index) }, entry.x)); }) })] }) })] }));
|
|
61
|
-
};
|
|
62
|
-
var BarTooltip = function (_a) {
|
|
63
|
-
var _b, _c, _d;
|
|
64
|
-
var active = _a.active, payload = _a.payload, totalCount = _a.totalCount;
|
|
65
|
-
if (!active) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
var name = (payload && ((_c = (_b = payload[0]) === null || _b === void 0 ? void 0 : _b.payload) === null || _c === void 0 ? void 0 : _c.x)) || '';
|
|
69
|
-
var value = (payload && ((_d = payload[0]) === null || _d === void 0 ? void 0 : _d.value)) || 0;
|
|
70
|
-
var percentage = totalCount ? Math.round((value / totalCount) * 100) : 0;
|
|
71
|
-
return (_jsxs("div", { style: TOOLTIP_STYLE, children: [_jsx("p", { style: LABEL_STYLE, children: name }), _jsxs("p", { style: COUNT_STYLE, children: [value, " (", percentage, "%)"] })] }));
|
|
27
|
+
var _b = _a.colorTheme, colorTheme = _b === void 0 ? 'default' : _b, params = __rest(_a, ["colorTheme"]);
|
|
28
|
+
var _c = useChartTheme().bar[colorTheme], chartFill = _c.fill, otherFill = _c.other;
|
|
29
|
+
return _jsx(BaseBarChart, __assign({ chartFill: chartFill, otherFill: otherFill }, params));
|
|
72
30
|
};
|
|
73
31
|
export default BentoBarChart;
|
|
74
32
|
//# sourceMappingURL=BentoBarChart.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BentoBarChart.js","sourceRoot":"","sources":["../../../src/Components/Charts/BentoBarChart.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"BentoBarChart.js","sourceRoot":"","sources":["../../../src/Components/Charts/BentoBarChart.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,IAAM,aAAa,GAA4B,UAAC,EAAqC;IAAnC,IAAA,kBAAsB,EAAtB,UAAU,mBAAG,SAAS,KAAA,EAAK,MAAM,cAAnC,cAAqC,CAAF;IAC3E,IAAA,KAAwC,aAAa,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,EAA/D,SAAS,UAAA,EAAS,SAAS,WAAoC,CAAC;IAE9E,OAAO,KAAC,YAAY,aAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,IAAM,MAAM,EAAI,CAAC;AAClF,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
+
import { useChartTheme } from '../../ChartConfigProvider';
|
|
25
|
+
import BaseBarChart from './BaseBarChart';
|
|
26
|
+
var BentoHistogram = function (_a) {
|
|
27
|
+
var _b = _a.colorTheme, colorTheme = _b === void 0 ? 'default' : _b, params = __rest(_a, ["colorTheme"]);
|
|
28
|
+
var _c = useChartTheme().histogram[colorTheme], chartFill = _c.fill, otherFill = _c.other;
|
|
29
|
+
return _jsx(BaseBarChart, __assign({ chartFill: chartFill, otherFill: otherFill }, params));
|
|
30
|
+
};
|
|
31
|
+
export default BentoHistogram;
|
|
32
|
+
//# sourceMappingURL=BentoHistogram.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BentoHistogram.js","sourceRoot":"","sources":["../../../src/Components/Charts/BentoHistogram.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,IAAM,cAAc,GAA6B,UAAC,EAAqC;IAAnC,IAAA,kBAAsB,EAAtB,UAAU,mBAAG,SAAS,KAAA,EAAK,MAAM,cAAnC,cAAqC,CAAF;IAC7E,IAAA,KAAwC,aAAa,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,EAArE,SAAS,UAAA,EAAS,SAAS,WAA0C,CAAC;IAEpF,OAAO,KAAC,YAAY,aAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,IAAM,MAAM,EAAI,CAAC;AAClF,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -4,6 +4,7 @@ export declare const COUNT_KEY = "Count";
|
|
|
4
4
|
export declare const OTHER_KEY = "Other";
|
|
5
5
|
export declare const defaultTranslationObject: TranslationObject;
|
|
6
6
|
export declare const COLORS: HexColor[];
|
|
7
|
+
export declare const NEW_CHART_COLORS: HexColor[];
|
|
7
8
|
export declare const BAR_CHART_FILL = "#4575b4";
|
|
8
9
|
export declare const CHART_MISSING_FILL = "#bbbbbb";
|
|
9
10
|
export declare const DEFAULT_CHART_THEME: ChartTheme;
|
|
@@ -36,6 +36,7 @@ export var COLORS = [
|
|
|
36
36
|
'#5574A6',
|
|
37
37
|
'#3B3EAC',
|
|
38
38
|
];
|
|
39
|
+
export var NEW_CHART_COLORS = ['#F94144', '#F3722C', '#F8961E', '#F9C74F', '#90BE6D', '#2D9CDB'];
|
|
39
40
|
export var BAR_CHART_FILL = '#4575b4';
|
|
40
41
|
export var CHART_MISSING_FILL = '#bbbbbb';
|
|
41
42
|
export var DEFAULT_CHART_THEME = {
|
|
@@ -44,12 +45,26 @@ export var DEFAULT_CHART_THEME = {
|
|
|
44
45
|
fill: COLORS,
|
|
45
46
|
other: CHART_MISSING_FILL,
|
|
46
47
|
},
|
|
48
|
+
new: {
|
|
49
|
+
fill: NEW_CHART_COLORS,
|
|
50
|
+
other: CHART_MISSING_FILL,
|
|
51
|
+
},
|
|
47
52
|
},
|
|
48
53
|
bar: {
|
|
49
54
|
default: {
|
|
50
55
|
fill: [BAR_CHART_FILL],
|
|
51
56
|
other: CHART_MISSING_FILL,
|
|
52
57
|
},
|
|
58
|
+
new: {
|
|
59
|
+
fill: NEW_CHART_COLORS,
|
|
60
|
+
other: CHART_MISSING_FILL,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
histogram: {
|
|
64
|
+
default: {
|
|
65
|
+
fill: [BAR_CHART_FILL],
|
|
66
|
+
other: CHART_MISSING_FILL,
|
|
67
|
+
},
|
|
53
68
|
},
|
|
54
69
|
};
|
|
55
70
|
// ################### CHART STYLES ###################
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chartConstants.js","sourceRoot":"","sources":["../../src/constants/chartConstants.ts"],"names":[],"mappings":";AAGA,4DAA4D;AAE5D,MAAM,CAAC,IAAM,SAAS,GAAG,OAAO,CAAC;AACjC,MAAM,CAAC,IAAM,SAAS,GAAG,OAAO,CAAC;AAEjC,MAAM,CAAC,IAAM,wBAAwB,GAAsB;IACzD,EAAE;QACA,GAAC,SAAS,IAAG,OAAO;QACpB,GAAC,SAAS,IAAG,OAAO;WACrB;IACD,EAAE;QACA,GAAC,SAAS,IAAG,UAAU;QACvB,GAAC,SAAS,IAAG,OAAO;WACrB;CACF,CAAC;AAEF,0DAA0D;AAC1D,oBAAoB;AACpB,MAAM,CAAC,IAAM,MAAM,GAAe;IAChC,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT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AAC,CAAC,sDAAsD;AACrG,MAAM,CAAC,IAAM,WAAW,GAAG,CAAC,CAAC,CAAC,oDAAoD;AAElF,YAAY;AACZ,MAAM,CAAC,IAAM,eAAe,GAAG,IAAI,CAAC;AAEpC,yDAAyD;AACzD,MAAM,CAAC,IAAM,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as BarChart } from './Components/Charts/BentoBarChart';
|
|
2
|
+
export { default as Histogram } from './Components/Charts/BentoHistogram';
|
|
2
3
|
export { default as PieChart } from './Components/Charts/BentoPie';
|
|
3
4
|
export { default as ChartConfigProvider } from './ChartConfigProvider';
|
|
4
5
|
export * from './types/chartTypes';
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// noinspection JSUnusedGlobalSymbols
|
|
3
3
|
// Categorical charts
|
|
4
4
|
export { default as BarChart } from './Components/Charts/BentoBarChart';
|
|
5
|
+
export { default as Histogram } from './Components/Charts/BentoHistogram';
|
|
5
6
|
export { default as PieChart } from './Components/Charts/BentoPie';
|
|
6
7
|
// Maps are not included in index.ts - instead, they need to be included from `bento-charts/maps`.
|
|
7
8
|
// This way, we can have optional peer dependencies.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,qCAAqC;AAErC,qBAAqB;AACrB,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAEnE,kGAAkG;AAClG,oDAAoD;AAEpD,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACvE,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,qCAAqC;AAErC,qBAAqB;AACrB,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAEnE,kGAAkG;AAClG,oDAAoD;AAEpD,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACvE,cAAc,oBAAoB,CAAC"}
|
|
@@ -26,6 +26,7 @@ export type ChartTypeContext = {
|
|
|
26
26
|
export type ChartTheme = {
|
|
27
27
|
pie: ChartTypeContext;
|
|
28
28
|
bar: ChartTypeContext;
|
|
29
|
+
histogram: ChartTypeContext;
|
|
29
30
|
};
|
|
30
31
|
export type FilterCallback<T> = (value: T, index: number, array: T[]) => boolean;
|
|
31
32
|
export type UnitaryMapCallback<T> = (value: T, index: number, array: T[]) => T;
|
|
@@ -59,10 +60,17 @@ export interface PieChartProps extends BaseCategoricalChartProps {
|
|
|
59
60
|
chartThreshold?: number;
|
|
60
61
|
maxLabelChars?: number;
|
|
61
62
|
}
|
|
62
|
-
export interface
|
|
63
|
-
|
|
63
|
+
export interface BaseBarChartProps extends BaseCategoricalChartProps {
|
|
64
|
+
chartFill: HexColor[];
|
|
65
|
+
otherFill: HexColor;
|
|
64
66
|
title?: string;
|
|
65
67
|
units: string;
|
|
66
68
|
onClick?: BarProps['onClick'];
|
|
67
69
|
}
|
|
70
|
+
export interface BarChartProps extends Omit<BaseBarChartProps, 'chartFill' | 'otherFill'> {
|
|
71
|
+
colorTheme?: keyof ChartTheme['bar'];
|
|
72
|
+
}
|
|
73
|
+
export interface HistogramProps extends Omit<BaseBarChartProps, 'chartFill' | 'otherFill'> {
|
|
74
|
+
colorTheme?: keyof ChartTheme['bar'];
|
|
75
|
+
}
|
|
68
76
|
export {};
|
package/package.json
CHANGED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Bar,
|
|
4
|
+
BarChart,
|
|
5
|
+
BarProps,
|
|
6
|
+
CartesianGrid,
|
|
7
|
+
Cell,
|
|
8
|
+
Label,
|
|
9
|
+
ResponsiveContainer,
|
|
10
|
+
Tooltip,
|
|
11
|
+
XAxis,
|
|
12
|
+
YAxis,
|
|
13
|
+
} from 'recharts';
|
|
14
|
+
import {
|
|
15
|
+
TOOLTIP_STYLE,
|
|
16
|
+
COUNT_STYLE,
|
|
17
|
+
LABEL_STYLE,
|
|
18
|
+
MAX_TICK_LABEL_CHARS,
|
|
19
|
+
TITLE_STYLE,
|
|
20
|
+
TICKS_SHOW_ALL_LABELS_BELOW,
|
|
21
|
+
UNITS_LABEL_OFFSET,
|
|
22
|
+
TICK_MARGIN,
|
|
23
|
+
COUNT_KEY,
|
|
24
|
+
} from '../../constants/chartConstants';
|
|
25
|
+
|
|
26
|
+
import type { BaseBarChartProps, CategoricalChartDataItem, TooltipPayload } from '../../types/chartTypes';
|
|
27
|
+
import { useChartTranslation } from '../../ChartConfigProvider';
|
|
28
|
+
import NoData from '../NoData';
|
|
29
|
+
import { useTransformedChartData } from '../../util/chartUtils';
|
|
30
|
+
import ChartWrapper from './ChartWrapper';
|
|
31
|
+
|
|
32
|
+
const tickFormatter = (tickLabel: string) => {
|
|
33
|
+
if (tickLabel.length <= MAX_TICK_LABEL_CHARS) {
|
|
34
|
+
return tickLabel;
|
|
35
|
+
}
|
|
36
|
+
return `${tickLabel.substring(0, MAX_TICK_LABEL_CHARS)}...`;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const BAR_CHART_MARGINS = { top: 10, bottom: 100, right: 20 };
|
|
40
|
+
|
|
41
|
+
const BaseBarChart: React.FC<BaseBarChartProps> = ({
|
|
42
|
+
height,
|
|
43
|
+
width,
|
|
44
|
+
units,
|
|
45
|
+
title,
|
|
46
|
+
onClick,
|
|
47
|
+
chartFill,
|
|
48
|
+
otherFill,
|
|
49
|
+
...params
|
|
50
|
+
}) => {
|
|
51
|
+
const t = useChartTranslation();
|
|
52
|
+
|
|
53
|
+
const fill = (entry: CategoricalChartDataItem, index: number) =>
|
|
54
|
+
entry.x === 'missing' ? otherFill : chartFill[index % chartFill.length];
|
|
55
|
+
|
|
56
|
+
const data = useTransformedChartData(params, true);
|
|
57
|
+
|
|
58
|
+
const totalCount = data.reduce((sum, e) => sum + e.y, 0);
|
|
59
|
+
|
|
60
|
+
const onHover: BarProps['onMouseEnter'] = useCallback(
|
|
61
|
+
(_data, _index, e) => {
|
|
62
|
+
const { target } = e;
|
|
63
|
+
if (onClick && target) (target as SVGElement).style.cursor = 'pointer';
|
|
64
|
+
},
|
|
65
|
+
[onClick]
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
if (data.length === 0) {
|
|
69
|
+
return <NoData height={height} />;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Regarding XAxis.ticks below:
|
|
73
|
+
// The weird conditional is added from https://github.com/recharts/recharts/issues/2593#issuecomment-1311678397
|
|
74
|
+
// Basically, if data is empty, Recharts will default to a domain of [0, "auto"] and our tickFormatter trips up
|
|
75
|
+
// on formatting a non-string. This hack manually overrides the ticks for the axis and blanks it out.
|
|
76
|
+
// - David L, 2023-01-03
|
|
77
|
+
return (
|
|
78
|
+
<ChartWrapper responsive={typeof width !== 'number'}>
|
|
79
|
+
<div style={TITLE_STYLE}>{title}</div>
|
|
80
|
+
<ResponsiveContainer width={width ?? '100%'} height={height}>
|
|
81
|
+
<BarChart data={data} margin={BAR_CHART_MARGINS}>
|
|
82
|
+
<XAxis
|
|
83
|
+
dataKey="x"
|
|
84
|
+
height={20}
|
|
85
|
+
angle={-45}
|
|
86
|
+
ticks={data.length ? undefined : ['']}
|
|
87
|
+
tickFormatter={tickFormatter}
|
|
88
|
+
tickMargin={TICK_MARGIN}
|
|
89
|
+
textAnchor="end"
|
|
90
|
+
interval={data.length < TICKS_SHOW_ALL_LABELS_BELOW ? 0 : 'preserveStartEnd'}
|
|
91
|
+
>
|
|
92
|
+
<Label value={units} offset={UNITS_LABEL_OFFSET} position="insideBottom" />
|
|
93
|
+
</XAxis>
|
|
94
|
+
<YAxis>
|
|
95
|
+
<Label value={t[COUNT_KEY]} offset={-10} position="left" angle={270} />
|
|
96
|
+
</YAxis>
|
|
97
|
+
<CartesianGrid strokeDasharray="3 3" vertical={false} />
|
|
98
|
+
<Tooltip content={<BarTooltip totalCount={totalCount} />} />
|
|
99
|
+
<Bar dataKey="y" isAnimationActive={false} onClick={onClick} onMouseEnter={onHover} maxBarSize={70}>
|
|
100
|
+
{data.map((entry, index) => (
|
|
101
|
+
<Cell key={entry.x} fill={fill(entry, index)} />
|
|
102
|
+
))}
|
|
103
|
+
</Bar>
|
|
104
|
+
</BarChart>
|
|
105
|
+
</ResponsiveContainer>
|
|
106
|
+
</ChartWrapper>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const BarTooltip = ({
|
|
111
|
+
active,
|
|
112
|
+
payload,
|
|
113
|
+
totalCount,
|
|
114
|
+
}: {
|
|
115
|
+
active?: boolean;
|
|
116
|
+
payload?: TooltipPayload;
|
|
117
|
+
totalCount: number;
|
|
118
|
+
}) => {
|
|
119
|
+
if (!active) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const name = (payload && payload[0]?.payload?.x) || '';
|
|
124
|
+
const value = (payload && payload[0]?.value) || 0;
|
|
125
|
+
const percentage = totalCount ? Math.round((value / totalCount) * 100) : 0;
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<div style={TOOLTIP_STYLE}>
|
|
129
|
+
<p style={LABEL_STYLE}>{name}</p>
|
|
130
|
+
<p style={COUNT_STYLE}>
|
|
131
|
+
{value} ({percentage}%)
|
|
132
|
+
</p>
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export default BaseBarChart;
|
|
@@ -1,129 +1,13 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import {
|
|
3
|
-
Bar,
|
|
4
|
-
BarChart,
|
|
5
|
-
BarProps,
|
|
6
|
-
CartesianGrid,
|
|
7
|
-
Cell,
|
|
8
|
-
Label,
|
|
9
|
-
ResponsiveContainer,
|
|
10
|
-
Tooltip,
|
|
11
|
-
XAxis,
|
|
12
|
-
YAxis,
|
|
13
|
-
} from 'recharts';
|
|
14
|
-
import type { TooltipProps } from 'recharts';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BarChartProps } from '../../types/chartTypes';
|
|
15
3
|
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
TOOLTIP_OTHER_PROPS,
|
|
19
|
-
COUNT_STYLE,
|
|
20
|
-
LABEL_STYLE,
|
|
21
|
-
MAX_TICK_LABEL_CHARS,
|
|
22
|
-
TITLE_STYLE,
|
|
23
|
-
TICKS_SHOW_ALL_LABELS_BELOW,
|
|
24
|
-
UNITS_LABEL_OFFSET,
|
|
25
|
-
TICK_MARGIN,
|
|
26
|
-
COUNT_KEY,
|
|
27
|
-
} from '../../constants/chartConstants';
|
|
4
|
+
import { useChartTheme } from '../../ChartConfigProvider';
|
|
5
|
+
import BaseBarChart from './BaseBarChart';
|
|
28
6
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
import NoData from '../NoData';
|
|
32
|
-
import { useTransformedChartData } from '../../util/chartUtils';
|
|
33
|
-
import ChartWrapper from './ChartWrapper';
|
|
7
|
+
const BentoBarChart: React.FC<BarChartProps> = ({ colorTheme = 'default', ...params }) => {
|
|
8
|
+
const { fill: chartFill, other: otherFill } = useChartTheme().bar[colorTheme];
|
|
34
9
|
|
|
35
|
-
|
|
36
|
-
if (tickLabel.length <= MAX_TICK_LABEL_CHARS) {
|
|
37
|
-
return tickLabel;
|
|
38
|
-
}
|
|
39
|
-
return `${tickLabel.substring(0, MAX_TICK_LABEL_CHARS)}...`;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const BAR_CHART_MARGINS = { top: 10, bottom: 100, right: 20 };
|
|
43
|
-
|
|
44
|
-
const BentoBarChart = ({ height, width, units, title, onClick, colorTheme = 'default', ...params }: BarChartProps) => {
|
|
45
|
-
const t = useChartTranslation();
|
|
46
|
-
const { fill: chartFill, other } = useChartTheme().bar[colorTheme];
|
|
47
|
-
|
|
48
|
-
const fill = (entry: CategoricalChartDataItem, index: number) =>
|
|
49
|
-
entry.x === 'missing' ? other : chartFill[index % chartFill.length];
|
|
50
|
-
|
|
51
|
-
const data = useTransformedChartData(params, true);
|
|
52
|
-
|
|
53
|
-
const totalCount = data.reduce((sum, e) => sum + e.y, 0);
|
|
54
|
-
|
|
55
|
-
const onHover: BarProps['onMouseEnter'] = useCallback(
|
|
56
|
-
(_data, _index, e) => {
|
|
57
|
-
const { target } = e;
|
|
58
|
-
if (onClick && target) (target as SVGElement).style.cursor = 'pointer';
|
|
59
|
-
},
|
|
60
|
-
[onClick]
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
if (data.length === 0) {
|
|
64
|
-
return <NoData height={height} />;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Regarding XAxis.ticks below:
|
|
68
|
-
// The weird conditional is added from https://github.com/recharts/recharts/issues/2593#issuecomment-1311678397
|
|
69
|
-
// Basically, if data is empty, Recharts will default to a domain of [0, "auto"] and our tickFormatter trips up
|
|
70
|
-
// on formatting a non-string. This hack manually overrides the ticks for the axis and blanks it out.
|
|
71
|
-
// - David L, 2023-01-03
|
|
72
|
-
return (
|
|
73
|
-
<ChartWrapper responsive={typeof width !== 'number'}>
|
|
74
|
-
<div style={TITLE_STYLE}>{title}</div>
|
|
75
|
-
<ResponsiveContainer width={width ?? '100%'} height={height}>
|
|
76
|
-
<BarChart data={data} margin={BAR_CHART_MARGINS}>
|
|
77
|
-
<XAxis
|
|
78
|
-
dataKey="x"
|
|
79
|
-
height={20}
|
|
80
|
-
angle={-45}
|
|
81
|
-
ticks={data.length ? undefined : ['']}
|
|
82
|
-
tickFormatter={tickFormatter}
|
|
83
|
-
tickMargin={TICK_MARGIN}
|
|
84
|
-
textAnchor="end"
|
|
85
|
-
interval={data.length < TICKS_SHOW_ALL_LABELS_BELOW ? 0 : 'preserveStartEnd'}
|
|
86
|
-
>
|
|
87
|
-
<Label value={units} offset={UNITS_LABEL_OFFSET} position="insideBottom" />
|
|
88
|
-
</XAxis>
|
|
89
|
-
<YAxis>
|
|
90
|
-
<Label value={t[COUNT_KEY]} offset={-10} position="left" angle={270} />
|
|
91
|
-
</YAxis>
|
|
92
|
-
<CartesianGrid strokeDasharray="3 3" vertical={false} />
|
|
93
|
-
<Tooltip {...TOOLTIP_OTHER_PROPS} content={<BarTooltip totalCount={totalCount} />} />
|
|
94
|
-
<Bar dataKey="y" isAnimationActive={false} onClick={onClick} onMouseEnter={onHover} maxBarSize={70}>
|
|
95
|
-
{data.map((entry, index) => (
|
|
96
|
-
<Cell key={entry.x} fill={fill(entry, index)} />
|
|
97
|
-
))}
|
|
98
|
-
</Bar>
|
|
99
|
-
</BarChart>
|
|
100
|
-
</ResponsiveContainer>
|
|
101
|
-
</ChartWrapper>
|
|
102
|
-
);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
interface BarTooltipProps extends TooltipProps<number, string> {
|
|
106
|
-
payload?: TooltipPayload;
|
|
107
|
-
totalCount: number;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const BarTooltip = ({ active, payload, totalCount }: BarTooltipProps) => {
|
|
111
|
-
if (!active) {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const name = (payload && payload[0]?.payload?.x) || '';
|
|
116
|
-
const value = (payload && payload[0]?.value) || 0;
|
|
117
|
-
const percentage = totalCount ? Math.round((value / totalCount) * 100) : 0;
|
|
118
|
-
|
|
119
|
-
return (
|
|
120
|
-
<div style={TOOLTIP_STYLE}>
|
|
121
|
-
<p style={LABEL_STYLE}>{name}</p>
|
|
122
|
-
<p style={COUNT_STYLE}>
|
|
123
|
-
{value} ({percentage}%)
|
|
124
|
-
</p>
|
|
125
|
-
</div>
|
|
126
|
-
);
|
|
10
|
+
return <BaseBarChart chartFill={chartFill} otherFill={otherFill} {...params} />;
|
|
127
11
|
};
|
|
128
12
|
|
|
129
13
|
export default BentoBarChart;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { HistogramProps } from '../../types/chartTypes';
|
|
3
|
+
|
|
4
|
+
import { useChartTheme } from '../../ChartConfigProvider';
|
|
5
|
+
import BaseBarChart from './BaseBarChart';
|
|
6
|
+
|
|
7
|
+
const BentoHistogram: React.FC<HistogramProps> = ({ colorTheme = 'default', ...params }) => {
|
|
8
|
+
const { fill: chartFill, other: otherFill } = useChartTheme().histogram[colorTheme];
|
|
9
|
+
|
|
10
|
+
return <BaseBarChart chartFill={chartFill} otherFill={otherFill} {...params} />;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default BentoHistogram;
|
|
@@ -42,6 +42,8 @@ export const COLORS: HexColor[] = [
|
|
|
42
42
|
'#3B3EAC',
|
|
43
43
|
];
|
|
44
44
|
|
|
45
|
+
export const NEW_CHART_COLORS: HexColor[] = ['#F94144', '#F3722C', '#F8961E', '#F9C74F', '#90BE6D', '#2D9CDB'];
|
|
46
|
+
|
|
45
47
|
export const BAR_CHART_FILL = '#4575b4';
|
|
46
48
|
export const CHART_MISSING_FILL = '#bbbbbb';
|
|
47
49
|
|
|
@@ -51,12 +53,26 @@ export const DEFAULT_CHART_THEME: ChartTheme = {
|
|
|
51
53
|
fill: COLORS,
|
|
52
54
|
other: CHART_MISSING_FILL,
|
|
53
55
|
},
|
|
56
|
+
new: {
|
|
57
|
+
fill: NEW_CHART_COLORS,
|
|
58
|
+
other: CHART_MISSING_FILL,
|
|
59
|
+
},
|
|
54
60
|
},
|
|
55
61
|
bar: {
|
|
56
62
|
default: {
|
|
57
63
|
fill: [BAR_CHART_FILL],
|
|
58
64
|
other: CHART_MISSING_FILL,
|
|
59
65
|
},
|
|
66
|
+
new: {
|
|
67
|
+
fill: NEW_CHART_COLORS,
|
|
68
|
+
other: CHART_MISSING_FILL,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
histogram: {
|
|
72
|
+
default: {
|
|
73
|
+
fill: [BAR_CHART_FILL],
|
|
74
|
+
other: CHART_MISSING_FILL,
|
|
75
|
+
},
|
|
60
76
|
},
|
|
61
77
|
};
|
|
62
78
|
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
// Categorical charts
|
|
5
5
|
export { default as BarChart } from './Components/Charts/BentoBarChart';
|
|
6
|
+
export { default as Histogram } from './Components/Charts/BentoHistogram';
|
|
6
7
|
export { default as PieChart } from './Components/Charts/BentoPie';
|
|
7
8
|
|
|
8
9
|
// Maps are not included in index.ts - instead, they need to be included from `bento-charts/maps`.
|
package/src/types/chartTypes.ts
CHANGED
|
@@ -28,7 +28,8 @@ export type ChartTypeContext = {
|
|
|
28
28
|
};
|
|
29
29
|
export type ChartTheme = {
|
|
30
30
|
pie: ChartTypeContext,
|
|
31
|
-
bar: ChartTypeContext
|
|
31
|
+
bar: ChartTypeContext,
|
|
32
|
+
histogram: ChartTypeContext
|
|
32
33
|
};
|
|
33
34
|
|
|
34
35
|
export type FilterCallback<T> = (value: T, index: number, array: T[]) => boolean;
|
|
@@ -76,9 +77,18 @@ export interface PieChartProps extends BaseCategoricalChartProps {
|
|
|
76
77
|
maxLabelChars?: number;
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
export interface
|
|
80
|
-
|
|
80
|
+
export interface BaseBarChartProps extends BaseCategoricalChartProps {
|
|
81
|
+
chartFill: HexColor[];
|
|
82
|
+
otherFill: HexColor;
|
|
81
83
|
title?: string;
|
|
82
84
|
units: string;
|
|
83
85
|
onClick?: BarProps['onClick'];
|
|
84
86
|
}
|
|
87
|
+
|
|
88
|
+
export interface BarChartProps extends Omit<BaseBarChartProps, 'chartFill' | 'otherFill'> {
|
|
89
|
+
colorTheme?: keyof ChartTheme['bar'];
|
|
90
|
+
}
|
|
91
|
+
export interface HistogramProps extends Omit<BaseBarChartProps, 'chartFill' | 'otherFill'> {
|
|
92
|
+
colorTheme?: keyof ChartTheme['bar'];
|
|
93
|
+
}
|
|
94
|
+
|