bento-charts 2.6.8 → 2.8.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/.eslintrc.js +27 -28
- package/.github/workflows/lint.yml +16 -4
- 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/Components/Charts/BentoPie.js +13 -9
- package/dist/Components/Charts/BentoPie.js.map +1 -1
- package/dist/Components/Maps/BentoChoroplethMap.js +2 -2
- package/dist/Components/Maps/BentoChoroplethMap.js.map +1 -1
- 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/dist/util/chartUtils.js +1 -1
- package/dist/util/chartUtils.js.map +1 -1
- package/package.json +10 -5
- 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/Components/Charts/BentoPie.tsx +14 -8
- package/src/Components/Maps/BentoChoroplethMap.tsx +2 -2
- package/src/constants/chartConstants.ts +16 -0
- package/src/index.ts +1 -0
- package/src/types/chartTypes.ts +17 -8
- package/src/util/chartUtils.ts +2 -2
package/.eslintrc.js
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
env: {
|
|
3
|
+
browser: true,
|
|
4
|
+
es2021: true,
|
|
5
|
+
},
|
|
6
|
+
extends: [
|
|
7
|
+
'eslint:recommended',
|
|
8
|
+
'plugin:@typescript-eslint/recommended',
|
|
9
|
+
'plugin:react/recommended',
|
|
10
|
+
'plugin:react-hooks/recommended',
|
|
11
|
+
'plugin:prettier/recommended',
|
|
12
|
+
],
|
|
13
|
+
plugins: ['@typescript-eslint', 'react', 'react-hooks', 'prettier'],
|
|
14
|
+
parser: '@typescript-eslint/parser',
|
|
15
|
+
parserOptions: {
|
|
16
|
+
ecmaVersion: 'latest',
|
|
17
|
+
sourceType: 'module',
|
|
18
|
+
},
|
|
19
|
+
settings: {
|
|
20
|
+
react: {
|
|
21
|
+
version: 'detect',
|
|
5
22
|
},
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
],
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"parser": "@typescript-eslint/parser",
|
|
14
|
-
"parserOptions": {
|
|
15
|
-
"ecmaVersion": "latest",
|
|
16
|
-
"sourceType": "module"
|
|
17
|
-
},
|
|
18
|
-
"plugins": [
|
|
19
|
-
"react",
|
|
20
|
-
"@typescript-eslint"
|
|
21
|
-
],
|
|
22
|
-
"rules": {
|
|
23
|
-
"semi": [2, "always"]
|
|
24
|
-
},
|
|
25
|
-
"settings": {
|
|
26
|
-
"react": {
|
|
27
|
-
"version": "^18.2.0"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
23
|
+
},
|
|
24
|
+
rules: {
|
|
25
|
+
'prettier/prettier': 'error',
|
|
26
|
+
'react/prop-types': 'off',
|
|
27
|
+
semi: [2, 'always'],
|
|
28
|
+
},
|
|
29
|
+
};
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
name: Lint
|
|
1
|
+
name: Lint and Format
|
|
2
|
+
|
|
2
3
|
on:
|
|
3
4
|
push:
|
|
4
5
|
branches:
|
|
5
6
|
- main
|
|
6
7
|
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
|
|
7
11
|
jobs:
|
|
8
12
|
lint:
|
|
9
13
|
runs-on: ubuntu-latest
|
|
10
14
|
steps:
|
|
11
|
-
-
|
|
12
|
-
|
|
15
|
+
- name: Checkout code
|
|
16
|
+
uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Set up Node.js
|
|
19
|
+
uses: actions/setup-node@v4
|
|
20
|
+
with:
|
|
21
|
+
node-version: 'lts/*'
|
|
22
|
+
|
|
23
|
+
- name: Install dependencies
|
|
13
24
|
run: npm install
|
|
14
|
-
|
|
25
|
+
|
|
26
|
+
- name: Run Linter (Checks for Eslint and Prettier errors)
|
|
15
27
|
run: npm run lint
|
|
@@ -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,CAAC,CAAC;AAEF,IAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;AAE9D,IAAM,YAAY,GAAgC,UAAC,EASlD;IARC,IAAA,MAAM,YAAA,EACN,KAAK,WAAA,EACL,KAAK,WAAA,EACL,KAAK,WAAA,EACL,OAAO,aAAA,EACP,SAAS,eAAA,EACT,SAAS,eAAA,EACN,MAAM,cARwC,0EASlD,CADU;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O,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"}
|
|
@@ -45,18 +45,22 @@ var labelShortName = function (name, maxChars) {
|
|
|
45
45
|
return "".concat(name.substring(0, maxChars - 3), "\u2026");
|
|
46
46
|
};
|
|
47
47
|
var BentoPie = function (_a) {
|
|
48
|
-
var height = _a.height, width = _a.width, onClick = _a.onClick, _b = _a.sort, sort = _b === void 0 ? true : _b, _c = _a.colorTheme, colorTheme = _c === void 0 ? 'default' : _c,
|
|
48
|
+
var height = _a.height, width = _a.width, onClick = _a.onClick, _b = _a.sort, sort = _b === void 0 ? true : _b, _c = _a.colorTheme, colorTheme = _c === void 0 ? 'default' : _c, chartThreshold = _a.chartThreshold, maxLabelChars = _a.maxLabelChars, params = __rest(_a, ["height", "width", "onClick", "sort", "colorTheme", "chartThreshold", "maxLabelChars"]);
|
|
49
49
|
var t = useChartTranslation();
|
|
50
50
|
var theme = useChartTheme().pie[colorTheme].fill;
|
|
51
|
-
var
|
|
51
|
+
var defaultChartThreshold = useChartThreshold();
|
|
52
|
+
var defaultMaxLabelChars = useChartMaxLabelChars();
|
|
53
|
+
var resolvedChartThreshold = chartThreshold !== null && chartThreshold !== void 0 ? chartThreshold : defaultChartThreshold;
|
|
54
|
+
var resolvedMaxLabelChars = maxLabelChars !== null && maxLabelChars !== void 0 ? maxLabelChars : defaultMaxLabelChars;
|
|
55
|
+
var _d = useState(undefined), activeIndex = _d[0], setActiveIndex = _d[1];
|
|
52
56
|
// ##################### Data processing #####################
|
|
53
57
|
var transformedData = useTransformedChartData(params, true, sort);
|
|
54
|
-
var
|
|
58
|
+
var _e = useMemo(function () {
|
|
55
59
|
var data = __spreadArray([], transformedData, true);
|
|
56
60
|
// combining sections with less than chartThreshold
|
|
57
61
|
var sum = data.reduce(function (acc, e) { return acc + e.y; }, 0);
|
|
58
62
|
var length = data.length;
|
|
59
|
-
var threshold =
|
|
63
|
+
var threshold = resolvedChartThreshold * sum;
|
|
60
64
|
var dataAboveThreshold = data.filter(function (e) { return e.y > threshold; });
|
|
61
65
|
// length - 1 intentional: if there is just one category below threshold, the "Other" category is not necessary.
|
|
62
66
|
data = dataAboveThreshold.length === length - 1 ? data : dataAboveThreshold;
|
|
@@ -70,7 +74,7 @@ var BentoPie = function (_a) {
|
|
|
70
74
|
data: data.map(function (e) { return ({ name: e.x, value: e.y }); }),
|
|
71
75
|
sum: sum,
|
|
72
76
|
};
|
|
73
|
-
}, [
|
|
77
|
+
}, [t, transformedData, resolvedChartThreshold]), data = _e.data, sum = _e.sum;
|
|
74
78
|
// ##################### Rendering #####################
|
|
75
79
|
var onEnter = useCallback(function (_data, index) {
|
|
76
80
|
setActiveIndex(index);
|
|
@@ -79,14 +83,14 @@ var BentoPie = function (_a) {
|
|
|
79
83
|
var target = e.target;
|
|
80
84
|
if (onClick && target && data.name !== t[OTHER_KEY])
|
|
81
85
|
target.style.cursor = 'pointer';
|
|
82
|
-
}, [onClick]);
|
|
86
|
+
}, [t, onClick]);
|
|
83
87
|
var onLeave = useCallback(function () {
|
|
84
88
|
setActiveIndex(undefined);
|
|
85
89
|
}, []);
|
|
86
90
|
if (data.length === 0) {
|
|
87
91
|
return _jsx(NoData, { height: height });
|
|
88
92
|
}
|
|
89
|
-
return (_jsx(ChartWrapper, { responsive: typeof width !== 'number', children: _jsx(ResponsiveContainer, { width: width !== null && width !== void 0 ? width : '100%', height: height, children: _jsxs(PieChart, { children: [_jsx(Pie, { data: data, dataKey: "value", cx: "50%", cy: "50%", innerRadius: "25%", outerRadius: "55%", label: renderLabel(
|
|
93
|
+
return (_jsx(ChartWrapper, { responsive: typeof width !== 'number', children: _jsx(ResponsiveContainer, { width: width !== null && width !== void 0 ? width : '100%', height: height, children: _jsxs(PieChart, { children: [_jsx(Pie, { data: data, dataKey: "value", cx: "50%", cy: "50%", innerRadius: "25%", outerRadius: "55%", label: renderLabel(resolvedMaxLabelChars), labelLine: false, isAnimationActive: false, onMouseEnter: onEnter, onMouseLeave: onLeave, onMouseOver: onHover, activeIndex: activeIndex, activeShape: RenderActiveLabel, onClick: onClick, children: data.map(function (entry, index) {
|
|
90
94
|
var fill = entry.name.toLowerCase() === 'missing' ? CHART_MISSING_FILL : theme[index % theme.length];
|
|
91
95
|
return _jsx(Cell, { fill: fill }, index);
|
|
92
96
|
}) }), _jsx(Tooltip, __assign({}, TOOLTIP_OTHER_PROPS, { content: _jsx(CustomTooltip, { totalCount: sum }), isAnimationActive: false }))] }) }) }));
|
|
@@ -100,7 +104,7 @@ var toNumber = function (val, defaultValue) {
|
|
|
100
104
|
}
|
|
101
105
|
return defaultValue || 0;
|
|
102
106
|
};
|
|
103
|
-
var renderLabel = function (
|
|
107
|
+
var renderLabel = function (resolvedMaxLabelChars) {
|
|
104
108
|
var BentoPieLabel = function (params) {
|
|
105
109
|
var fill = params.fill, payload = params.payload, index = params.index, activeIndex = params.activeIndex;
|
|
106
110
|
var percent = params.percent || 0;
|
|
@@ -129,7 +133,7 @@ var renderLabel = function (maxLabelChars) {
|
|
|
129
133
|
var startPoint = polarToCartesian(cx, cy, outerRadius, midAngle);
|
|
130
134
|
var endPoint = polarToCartesian(cx, cy, outerRadius + offsetRadius, midAngle);
|
|
131
135
|
var lineProps = __assign(__assign({}, params), { fill: 'none', stroke: fill, points: [startPoint, endPoint] });
|
|
132
|
-
return (_jsxs("g", { children: [_jsx(Curve, __assign({}, lineProps, { type: "linear", className: "recharts-pie-label-line" })), _jsx("path", { d: "M".concat(sx, ",").concat(sy, "L").concat(mx, ",").concat(my, "L").concat(ex, ",").concat(ey), stroke: fill, fill: "none" }), _jsx("circle", { cx: ex, cy: ey, r: 2, fill: fill, stroke: "none" }), _jsx("text", { x: ex + (cos >= 0 ? 1 : -1) * 12, y: ey + 3, textAnchor: textAnchor, style: currentTextStyle, children: labelShortName(name,
|
|
136
|
+
return (_jsxs("g", { children: [_jsx(Curve, __assign({}, lineProps, { type: "linear", className: "recharts-pie-label-line" })), _jsx("path", { d: "M".concat(sx, ",").concat(sy, "L").concat(mx, ",").concat(my, "L").concat(ex, ",").concat(ey), stroke: fill, fill: "none" }), _jsx("circle", { cx: ex, cy: ey, r: 2, fill: fill, stroke: "none" }), _jsx("text", { x: ex + (cos >= 0 ? 1 : -1) * 12, y: ey + 3, textAnchor: textAnchor, style: currentTextStyle, children: labelShortName(name, resolvedMaxLabelChars) }), _jsx("text", { x: ex + (cos >= 0 ? 1 : -1) * 12, y: ey, dy: 14, textAnchor: textAnchor, style: COUNT_TEXT_STYLE, children: "(".concat(payload.value, ")") })] }));
|
|
133
137
|
};
|
|
134
138
|
BentoPieLabel.displayName = BentoPieLabel;
|
|
135
139
|
return BentoPieLabel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BentoPie.js","sourceRoot":"","sources":["../../../src/Components/Charts/BentoPie.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAc,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9D,OAAO,EACL,QAAQ,EACR,GAAG,EACH,IAAI,EACJ,KAAK,EACL,OAAO,EACP,MAAM,EAGN,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,MAAM,EACN,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,SAAS,GACV,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,GACtB,M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EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5C,IAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,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,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,CACxB,eAAK,KAAK,EAAE,aAAa,aACvB,YAAG,KAAK,EAAE,WAAW,YAAG,IAAI,GAAK,EACjC,aAAG,KAAK,EAAE,WAAW,aAClB,GAAG,EACH,KAAK,QAAI,UAAU,UAElB,IACA,CACP,CAAC,CAAC,CAAC,CACF,oCAAkB,CACnB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -43,7 +43,7 @@ var BentoChoroplethMap = function (_a) {
|
|
|
43
43
|
fillColor: calculateColor(dataByFeatureCat[cat]),
|
|
44
44
|
fillOpacity: 1, // actual opacity set by fillColor
|
|
45
45
|
};
|
|
46
|
-
}, [
|
|
46
|
+
}, [calculateColor, categoryProp, dataByFeatureCat]);
|
|
47
47
|
var _b = useState(null), popupContents = _b[0], setPopupContents = _b[1];
|
|
48
48
|
var eventHandlers = useMemo(function () {
|
|
49
49
|
return ({
|
|
@@ -59,7 +59,7 @@ var BentoChoroplethMap = function (_a) {
|
|
|
59
59
|
}, children: title })) : (_jsx("span", { children: title })) }), renderPopupBody ? renderPopupBody(feature, dataByFeatureCat[fProps[categoryProp]]) : null] }));
|
|
60
60
|
},
|
|
61
61
|
});
|
|
62
|
-
}, [onClick, categoryProp, renderPopupBody]);
|
|
62
|
+
}, [onClick, categoryProp, dataByFeatureCat, renderPopupBody]);
|
|
63
63
|
var geoJsonLayer = useRef(null);
|
|
64
64
|
useEffect(function () {
|
|
65
65
|
// Bizarre workaround needed for react-leaflet when handling `features` change:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BentoChoroplethMap.js","sourceRoot":"","sources":["../../../src/Components/Maps/BentoChoroplethMap.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAc,EAAO,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtF,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAYhD,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,mBAAmB,MAAM,gCAAgC,CAAC;AACjE,OAAO,iBAAiB,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,IAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,IAAM,gBAAgB,GAAoB,aAAa,CAAC;AAExD,IAAM,kBAAkB,GAAG,UAAC,EAWP;IAVnB,IAAA,MAAM,YAAA,EACN,MAAM,YAAA,EACN,IAAI,UAAA,EACJ,SAAS,eAAA,EACT,SAAS,eAAA,EACT,QAAQ,cAAA,EACR,YAAY,kBAAA,EACZ,OAAO,aAAA,EACP,eAAe,qBAAA,EACZ,MAAM,cAViB,gHAW3B,CADU;IAET,IAAM,IAAI,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAE7C,IAAM,gBAAgB,GAAG,OAAO,CAAC,cAAM,OAAA,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,C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,gBAAgB,EAAE,WAAW,EAAE,SAAS,CAAC,WAAW,GAAI,CACtF,IACiB,CACrB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,kBAAkB,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,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;CACV,CAAC;AAEF,MAAM,CAAC,IAAM,cAAc,GAAG,SAAS,CAAC;AACxC,MAAM,CAAC,IAAM,kBAAkB,GAAG,SAAS,CAAC;AAE5C,MAAM,CAAC,IAAM,mBAAmB,GAAe;IAC7C,GAAG,EAAE;QACH,OAAO,EAAE;YACP,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,kBAAkB;SAC1B;KACF;IACD,GAAG,EAAE;QACH,OAAO,EAAE;YACP,IAAI,EAAE,CAAC,cAAc,CAAC;YACtB,KAAK,EAAE,kBAAkB;SAC1B;KACF;CACF,CAAC;AAEF,uDAAuD;AAEvD,SAA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CAAC,IAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,MAAM,CAAC,IAAM,kBAAkB,GAAG,CAAC,EAAE,CAAC;AACtC,MAAM,CAAC,IAAM,2BAA2B,GAAG,EAAE,CAAC,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"}
|
|
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,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;CACV,CAAC;AAEF,MAAM,CAAC,IAAM,gBAAgB,GAAe,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAE/G,MAAM,CAAC,IAAM,cAAc,GAAG,SAAS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IACpB,QAAQ,EAAE,MAAM;IAChB,OAAO,EAAE,GAAG;IACZ,MAAM,EAAE,GAAG;CACZ,CAAC;AAEF,MAAM,CAAC,IAAM,mBAAmB,GAAmB;IACjD,OAAO,EAAE,MAAM;IACf,aAAa,EAAE,QAAQ;IACvB,UAAU,EAAE,QAAQ;CACrB,CAAC;AAEF,YAAY;AACZ,MAAM,CAAC,IAAM,WAAW,GAAmB;IACzC,SAAS,EAAE,QAAQ;IACnB,QAAQ,EAAE,OAAO;IACjB,SAAS,EAAE,QAAQ;CACpB,CAAC;AAEF,YAAY;AACZ,MAAM,CAAC,IAAM,UAAU,GAAmB;IACxC,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE,MAAM;CACb,CAAC;AACF,MAAM,CAAC,IAAM,gBAAgB,GAAmB;IAC9C,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE,MAAM;CACb,CAAC;AAEF,0DAA0D;AAC1D,YAAY;AACZ,MAAM,CAAC,IAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,MAAM,CAAC,IAAM,kBAAkB,GAAG,CAAC,EAAE,CAAC;AACtC,MAAM,CAAC,IAAM,2BAA2B,GAAG,EAAE,CAAC,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/dist/util/chartUtils.js
CHANGED
|
@@ -33,6 +33,6 @@ export var useTransformedChartData = function (_a, defaultRemoveEmpty, sortY) {
|
|
|
33
33
|
if (sortY)
|
|
34
34
|
data.sort(function (a, b) { return a.y - b.y; });
|
|
35
35
|
return data;
|
|
36
|
-
}, [originalData,
|
|
36
|
+
}, [dataMap, defaultRemoveEmpty, originalData, origRemoveEmpty, preFilter, postFilter, sortY]);
|
|
37
37
|
};
|
|
38
38
|
//# sourceMappingURL=chartUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chartUtils.js","sourceRoot":"","sources":["../../src/util/chartUtils.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,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I,WAAW;YAAE,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,CAAC,KAAK,CAAC,EAAT,CAAS,CAAC,CAAC;QAEtD,IAAI,KAAK;YAAE,IAAI,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAT,CAAS,CAAC,CAAC;QAE1C,OAAO,IAAI,CAAC;IACd,CAAC,EAAE,CAAC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;AAd9F,CAc8F,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bento-charts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "Charts library for Bento-platform",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
"build": "npx tsc && npm run copy-files",
|
|
9
9
|
"copy-files": "cp ./src/styles.css ./dist/",
|
|
10
10
|
"prepublishOnly": "npm run build",
|
|
11
|
-
"lint": "npx eslint src",
|
|
11
|
+
"lint": "npx eslint 'src/**/*.{js,ts,tsx}'",
|
|
12
|
+
"lint:fix": "npx eslint 'src/**/*.{js,ts,tsx}' --fix",
|
|
13
|
+
"format": "npx prettier --write 'src/**/*.{js,ts,tsx}'",
|
|
12
14
|
"buildpack": "rm ./packs/*.tgz && tsc && npm pack --pack-destination ./packs",
|
|
13
15
|
"test": "npx webpack-dev-server"
|
|
14
16
|
},
|
|
@@ -85,18 +87,21 @@
|
|
|
85
87
|
"@types/react-dom": "^18.2.8",
|
|
86
88
|
"@types/react-leaflet": "^3.0.0",
|
|
87
89
|
"@types/recharts": "^1.8.25",
|
|
88
|
-
"@typescript-eslint/eslint-plugin": "^7.0
|
|
90
|
+
"@typescript-eslint/eslint-plugin": "^7.11.0",
|
|
89
91
|
"@typescript-eslint/parser": "^7.0.1",
|
|
90
92
|
"@webpack-cli/serve": "^2.0.5",
|
|
91
93
|
"antd": "^5.9.4",
|
|
92
94
|
"css-loader": "^6.8.1",
|
|
93
95
|
"eslint": "^8.50.0",
|
|
94
|
-
"eslint-
|
|
96
|
+
"eslint-config-prettier": "^9.1.0",
|
|
97
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
98
|
+
"eslint-plugin-react": "^7.34.2",
|
|
99
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
95
100
|
"file-loader": "^6.2.0",
|
|
96
101
|
"geojson": "^0.5.0",
|
|
97
102
|
"html-webpack-plugin": "^5.5.3",
|
|
98
103
|
"husky": "^8.0.3",
|
|
99
|
-
"prettier": "3.2.5",
|
|
104
|
+
"prettier": "^3.2.5",
|
|
100
105
|
"react-router-dom": "^6.16.0",
|
|
101
106
|
"semantic-release": "^23.0.2",
|
|
102
107
|
"style-loader": "^3.3.3",
|
|
@@ -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;
|
|
@@ -49,13 +49,19 @@ const BentoPie = ({
|
|
|
49
49
|
onClick,
|
|
50
50
|
sort = true,
|
|
51
51
|
colorTheme = 'default',
|
|
52
|
-
chartThreshold
|
|
53
|
-
maxLabelChars
|
|
52
|
+
chartThreshold,
|
|
53
|
+
maxLabelChars,
|
|
54
54
|
...params
|
|
55
55
|
}: PieChartProps) => {
|
|
56
56
|
const t = useChartTranslation();
|
|
57
57
|
const { fill: theme } = useChartTheme().pie[colorTheme];
|
|
58
58
|
|
|
59
|
+
const defaultChartThreshold = useChartThreshold();
|
|
60
|
+
const defaultMaxLabelChars = useChartMaxLabelChars();
|
|
61
|
+
|
|
62
|
+
const resolvedChartThreshold = chartThreshold ?? defaultChartThreshold;
|
|
63
|
+
const resolvedMaxLabelChars = maxLabelChars ?? defaultMaxLabelChars;
|
|
64
|
+
|
|
59
65
|
const [activeIndex, setActiveIndex] = useState<number | undefined>(undefined);
|
|
60
66
|
|
|
61
67
|
// ##################### Data processing #####################
|
|
@@ -67,7 +73,7 @@ const BentoPie = ({
|
|
|
67
73
|
// combining sections with less than chartThreshold
|
|
68
74
|
const sum = data.reduce((acc, e) => acc + e.y, 0);
|
|
69
75
|
const length = data.length;
|
|
70
|
-
const threshold =
|
|
76
|
+
const threshold = resolvedChartThreshold * sum;
|
|
71
77
|
const dataAboveThreshold = data.filter((e) => e.y > threshold);
|
|
72
78
|
// length - 1 intentional: if there is just one category below threshold, the "Other" category is not necessary.
|
|
73
79
|
data = dataAboveThreshold.length === length - 1 ? data : dataAboveThreshold;
|
|
@@ -82,7 +88,7 @@ const BentoPie = ({
|
|
|
82
88
|
data: data.map((e) => ({ name: e.x, value: e.y })),
|
|
83
89
|
sum,
|
|
84
90
|
};
|
|
85
|
-
}, [
|
|
91
|
+
}, [t, transformedData, resolvedChartThreshold]);
|
|
86
92
|
|
|
87
93
|
// ##################### Rendering #####################
|
|
88
94
|
const onEnter: PieProps['onMouseEnter'] = useCallback((_data, index) => {
|
|
@@ -94,7 +100,7 @@ const BentoPie = ({
|
|
|
94
100
|
const { target } = e;
|
|
95
101
|
if (onClick && target && data.name !== t[OTHER_KEY]) (target as SVGElement).style.cursor = 'pointer';
|
|
96
102
|
},
|
|
97
|
-
[onClick]
|
|
103
|
+
[t, onClick]
|
|
98
104
|
);
|
|
99
105
|
|
|
100
106
|
const onLeave: PieProps['onMouseLeave'] = useCallback(() => {
|
|
@@ -116,7 +122,7 @@ const BentoPie = ({
|
|
|
116
122
|
cy="50%"
|
|
117
123
|
innerRadius="25%"
|
|
118
124
|
outerRadius="55%"
|
|
119
|
-
label={renderLabel(
|
|
125
|
+
label={renderLabel(resolvedMaxLabelChars)}
|
|
120
126
|
labelLine={false}
|
|
121
127
|
isAnimationActive={false}
|
|
122
128
|
onMouseEnter={onEnter}
|
|
@@ -147,7 +153,7 @@ const toNumber = (val: number | string | undefined, defaultValue?: number): numb
|
|
|
147
153
|
return defaultValue || 0;
|
|
148
154
|
};
|
|
149
155
|
|
|
150
|
-
const renderLabel = (
|
|
156
|
+
const renderLabel = (resolvedMaxLabelChars: number): PieProps['label'] => {
|
|
151
157
|
const BentoPieLabel = (params: PieLabelRenderProps) => {
|
|
152
158
|
const { fill, payload, index, activeIndex } = params;
|
|
153
159
|
const percent = params.percent || 0;
|
|
@@ -198,7 +204,7 @@ const renderLabel = (maxLabelChars: number): PieProps['label'] => {
|
|
|
198
204
|
<path d={`M${sx},${sy}L${mx},${my}L${ex},${ey}`} stroke={fill} fill="none" />
|
|
199
205
|
<circle cx={ex} cy={ey} r={2} fill={fill} stroke="none" />
|
|
200
206
|
<text x={ex + (cos >= 0 ? 1 : -1) * 12} y={ey + 3} textAnchor={textAnchor} style={currentTextStyle}>
|
|
201
|
-
{labelShortName(name,
|
|
207
|
+
{labelShortName(name, resolvedMaxLabelChars)}
|
|
202
208
|
</text>
|
|
203
209
|
<text x={ex + (cos >= 0 ? 1 : -1) * 12} y={ey} dy={14} textAnchor={textAnchor} style={COUNT_TEXT_STYLE}>
|
|
204
210
|
{`(${payload.value})`}
|
|
@@ -61,7 +61,7 @@ const BentoChoroplethMap = ({
|
|
|
61
61
|
fillOpacity: 1, // actual opacity set by fillColor
|
|
62
62
|
};
|
|
63
63
|
},
|
|
64
|
-
[
|
|
64
|
+
[calculateColor, categoryProp, dataByFeatureCat]
|
|
65
65
|
);
|
|
66
66
|
|
|
67
67
|
const [popupContents, setPopupContents] = useState<React.ReactNode | null>(null);
|
|
@@ -95,7 +95,7 @@ const BentoChoroplethMap = ({
|
|
|
95
95
|
);
|
|
96
96
|
},
|
|
97
97
|
}) as LeafletEventHandlerFnMap,
|
|
98
|
-
[onClick, categoryProp, renderPopupBody]
|
|
98
|
+
[onClick, categoryProp, dataByFeatureCat, renderPopupBody]
|
|
99
99
|
);
|
|
100
100
|
|
|
101
101
|
const geoJsonLayer: Ref<LeafletGeoJSON> = useRef(null);
|
|
@@ -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
|
@@ -22,13 +22,14 @@ export type HexColor = `#${string}`;
|
|
|
22
22
|
|
|
23
23
|
export type ChartThemeContext = { fill: HexColor[]; other: HexColor };
|
|
24
24
|
export type ChartTypeContext = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
[key in string]: ChartThemeContext;
|
|
26
|
+
} & {
|
|
27
|
+
default: ChartThemeContext;
|
|
28
|
+
};
|
|
29
29
|
export type ChartTheme = {
|
|
30
|
-
pie: ChartTypeContext
|
|
31
|
-
bar: ChartTypeContext
|
|
30
|
+
pie: 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,17 @@ 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
|
+
}
|
package/src/util/chartUtils.ts
CHANGED
|
@@ -18,7 +18,7 @@ export const useTransformedChartData = (
|
|
|
18
18
|
removeEmpty: origRemoveEmpty,
|
|
19
19
|
}: CategoricalChartDataWithTransforms,
|
|
20
20
|
defaultRemoveEmpty = true,
|
|
21
|
-
sortY = false
|
|
21
|
+
sortY = false
|
|
22
22
|
) =>
|
|
23
23
|
useMemo(() => {
|
|
24
24
|
const removeEmpty = origRemoveEmpty ?? defaultRemoveEmpty;
|
|
@@ -34,4 +34,4 @@ export const useTransformedChartData = (
|
|
|
34
34
|
if (sortY) data.sort((a, b) => a.y - b.y);
|
|
35
35
|
|
|
36
36
|
return data;
|
|
37
|
-
}, [originalData,
|
|
37
|
+
}, [dataMap, defaultRemoveEmpty, originalData, origRemoveEmpty, preFilter, postFilter, sortY]);
|