@auth0/quantum-charts 0.0.4 → 0.1.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/README.md +1 -1
- package/bar-chart/index.js +46 -25
- package/chart-card/index.d.ts +1 -0
- package/chart-card/index.js +2 -2
- package/chart-summary/data-table-chart.d.ts +2 -2
- package/chart-summary/data-table-chart.js +46 -4
- package/chart-summary/index.d.ts +1 -1
- package/common/chart.d.ts +6 -0
- package/common/chart.js +30 -0
- package/common/custom-legend.d.ts +2 -0
- package/common/custom-legend.js +69 -0
- package/common/custom-tooltip.d.ts +4 -0
- package/common/custom-tooltip.js +54 -0
- package/donut-chart/decoupled-legend.d.ts +2 -0
- package/donut-chart/decoupled-legend.js +44 -21
- package/donut-chart/index.d.ts +3 -0
- package/donut-chart/index.js +27 -11
- package/esm/bar-chart/index.js +47 -26
- package/esm/chart-card/index.js +2 -2
- package/esm/chart-summary/data-table-chart.js +47 -5
- package/esm/common/chart.js +28 -1
- package/esm/common/custom-legend.js +42 -0
- package/esm/common/custom-tooltip.js +26 -0
- package/esm/donut-chart/decoupled-legend.js +46 -20
- package/esm/donut-chart/index.js +29 -13
- package/esm/line-chart/index.js +56 -18
- package/esm/scorecard/index.js +9 -3
- package/esm/styles.js +11 -11
- package/esm/theme.js +37 -21
- package/line-chart/index.js +55 -17
- package/package.json +14 -12
- package/scorecard/index.js +8 -2
- package/styles.d.ts +3 -4
- package/styles.js +11 -14
- package/theme.d.ts +10 -2
- package/theme.js +39 -24
- package/esm/line-chart/custom-tooltip.js +0 -20
- package/line-chart/custom-tooltip.d.ts +0 -6
- package/line-chart/custom-tooltip.js +0 -48
- /package/{custom-color-status-dot.d.ts → common/custom-color-status-dot.d.ts} +0 -0
- /package/{custom-color-status-dot.js → common/custom-color-status-dot.js} +0 -0
- /package/esm/{custom-color-status-dot.js → common/custom-color-status-dot.js} +0 -0
package/esm/bar-chart/index.js
CHANGED
|
@@ -9,19 +9,53 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
+
if (!m) return o;
|
|
15
|
+
var i = m.call(o), r, ar = [], e;
|
|
16
|
+
try {
|
|
17
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
+
}
|
|
19
|
+
catch (error) { e = { error: error }; }
|
|
20
|
+
finally {
|
|
21
|
+
try {
|
|
22
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
+
}
|
|
24
|
+
finally { if (e) throw e.error; }
|
|
25
|
+
}
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
12
28
|
import _ from 'lodash';
|
|
13
29
|
import * as React from 'react';
|
|
14
30
|
import { BarChart as RechartsBarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, } from 'recharts';
|
|
15
31
|
import { useTheme, Text } from '@auth0/quantum-product';
|
|
16
|
-
import {
|
|
17
|
-
import CustomTooltip from '../
|
|
18
|
-
import { format } from 'date-fns';
|
|
32
|
+
import { getColorScale } from '../theme';
|
|
33
|
+
import CustomTooltip from '../common/custom-tooltip';
|
|
19
34
|
import { ChartCard } from '../chart-card';
|
|
35
|
+
import { tickFormatter } from '../common/chart';
|
|
36
|
+
import { CustomLegend } from '../common/custom-legend';
|
|
20
37
|
export function BarChart(props) {
|
|
21
|
-
var _a = props, data = _a.data, leftAxis = _a.leftAxis, bottomAxis = _a.bottomAxis, _b = _a.height, height = _b === void 0 ? 300 : _b, title = _a.title, value = _a.value, label = _a.label, helperText = _a.helperText, _c = _a.layout, layout = _c === void 0 ? 'vertical' : _c, _d = _a.isStacked, isStacked = _d === void 0 ? false : _d;
|
|
38
|
+
var _a = props, data = _a.data, leftAxis = _a.leftAxis, bottomAxis = _a.bottomAxis, _b = _a.height, height = _b === void 0 ? 300 : _b, title = _a.title, value = _a.value, label = _a.label, helperText = _a.helperText, _c = _a.layout, layout = _c === void 0 ? 'vertical' : _c, _d = _a.isStacked, isStacked = _d === void 0 ? false : _d, _e = _a.color, color = _e === void 0 ? 'categorical' : _e;
|
|
22
39
|
var theme = useTheme();
|
|
23
40
|
// Function to know how many bars we need based of how much different group values are.
|
|
24
41
|
var groups = _.uniqBy(data, 'group').map(function (item) { return item.group; });
|
|
42
|
+
var initialState = __assign({ hover: null }, groups.reduce(function (acc, group) {
|
|
43
|
+
var _a;
|
|
44
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[group] = false, _a)));
|
|
45
|
+
}, {}));
|
|
46
|
+
var _f = __read(React.useState(initialState), 2), barVisibility = _f[0], setBarVisibility = _f[1];
|
|
47
|
+
var handleLegendMouseEnter = function (e) {
|
|
48
|
+
if (!barVisibility[e.dataKey]) {
|
|
49
|
+
setBarVisibility(__assign(__assign({}, barVisibility), { hover: e.dataKey }));
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var handleLegendMouseLeave = function () {
|
|
53
|
+
setBarVisibility(__assign(__assign({}, barVisibility), { hover: null }));
|
|
54
|
+
};
|
|
55
|
+
var selectBar = function (e) {
|
|
56
|
+
var _a;
|
|
57
|
+
setBarVisibility(__assign(__assign({}, barVisibility), (_a = {}, _a[e.dataKey] = !barVisibility[e.dataKey], _a.hover = null, _a)));
|
|
58
|
+
};
|
|
25
59
|
var bottomAxisDataKey = bottomAxis.mapsTo || 'date';
|
|
26
60
|
var leftAxisDataKey = leftAxis.mapsTo || 'value';
|
|
27
61
|
var entries = {};
|
|
@@ -42,39 +76,26 @@ export function BarChart(props) {
|
|
|
42
76
|
_b[entry.group] = entry[leftAxisDataKey],
|
|
43
77
|
_b;
|
|
44
78
|
});
|
|
45
|
-
var formatBottomTick = function (value) {
|
|
46
|
-
if (bottomAxis.scaleType === 'date') {
|
|
47
|
-
return format(new Date(value), 'LLL d');
|
|
48
|
-
}
|
|
49
|
-
if (bottomAxis.scaleType === 'datetime') {
|
|
50
|
-
return format(new Date(value), 'LLL d p');
|
|
51
|
-
}
|
|
52
|
-
return value;
|
|
53
|
-
};
|
|
54
79
|
return (React.createElement(ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText },
|
|
55
80
|
React.createElement(ResponsiveContainer, { width: "100%", height: height }, data.length ? (React.createElement(RechartsBarChart, { width: 500, layout: layout === 'horizontal' ? 'vertical' : 'horizontal', height: height, data: Object.values(entries), margin: {
|
|
56
81
|
top: 24,
|
|
57
82
|
right: 10,
|
|
58
|
-
left: layout === 'vertical' ? -24 :
|
|
83
|
+
left: layout === 'vertical' ? -24 : 36,
|
|
59
84
|
bottom: 0,
|
|
60
85
|
} },
|
|
61
86
|
React.createElement(CartesianGrid, { vertical: false, stroke: theme.tokens.color_border_default }),
|
|
62
|
-
React.createElement(XAxis, __assign({}, (layout === 'horizontal'
|
|
63
|
-
? { type: 'number' }
|
|
64
|
-
: { tickFormatter: formatBottomTick, dataKey: bottomAxisDataKey }), { height: 30 })),
|
|
87
|
+
React.createElement(XAxis, __assign({}, (layout === 'horizontal' ? { type: 'number' } : { dataKey: bottomAxisDataKey }), { height: 30, tickFormatter: function (value) { return tickFormatter(value, bottomAxis.scaleType); }, axisLine: { stroke: theme.tokens.color_border_bold }, tickLine: { stroke: theme.tokens.color_border_bold } })),
|
|
65
88
|
React.createElement(YAxis, __assign({}, (layout === 'horizontal' && {
|
|
66
89
|
type: 'category',
|
|
67
|
-
tickFormatter:
|
|
90
|
+
tickFormatter: function (value) { return tickFormatter(value, leftAxis.scaleType); },
|
|
68
91
|
dataKey: bottomAxisDataKey,
|
|
69
|
-
}), { domain: ['auto', 'auto'] })),
|
|
70
|
-
React.createElement(Tooltip, { content: React.createElement(CustomTooltip, { active: undefined, payload: undefined }) }),
|
|
71
|
-
React.createElement(Legend, { align: "center", iconType: "square", iconSize: 14, wrapperStyle: { paddingTop: 16 } }),
|
|
92
|
+
}), { domain: ['auto', 'auto'], axisLine: { stroke: theme.tokens.color_border_bold }, tickLine: { stroke: theme.tokens.color_border_bold } })),
|
|
93
|
+
React.createElement(Tooltip, { wrapperStyle: { outline: 'none' }, content: React.createElement(CustomTooltip, { active: undefined, payload: undefined, scaleType: bottomAxis.scaleType }) }),
|
|
94
|
+
React.createElement(Legend, { align: "center", iconType: "square", iconSize: 14, wrapperStyle: { paddingTop: 16 }, content: React.createElement(CustomLegend, { selectData: selectBar, handleLegendMouseEnter: handleLegendMouseEnter, handleLegendMouseLeave: handleLegendMouseLeave, dataVisibility: barVisibility }) }),
|
|
72
95
|
groups.map(function (group, index) {
|
|
73
|
-
return (React.createElement(Bar, __assign({ key: group, dataKey: group }, (isStacked && { stackId: 'stack' }), { name: group, maxBarSize: 70,
|
|
74
|
-
?
|
|
75
|
-
|
|
76
|
-
: [0, 4, 4, 0]
|
|
77
|
-
: [0, 0, 0, 0] })));
|
|
96
|
+
return (React.createElement(Bar, __assign({ key: group, dataKey: group }, (isStacked && { stackId: 'stack' }), { name: group, maxBarSize: 70, hide: barVisibility[group] === true, fill: barVisibility.hover === group || !barVisibility.hover
|
|
97
|
+
? getColorScale(theme)[color]['base'][index]
|
|
98
|
+
: getColorScale(theme)[color]['muted'][index] })));
|
|
78
99
|
}))) : (React.createElement("div", { style: {
|
|
79
100
|
display: 'grid',
|
|
80
101
|
placeItems: 'center',
|
package/esm/chart-card/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import { Card } from '@auth0/quantum-product';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { ChartSummary } from '../chart-summary';
|
|
4
4
|
export function ChartCard(props) {
|
|
5
|
-
var children = props.children, title = props.title, value = props.value, dataTable = props.dataTable, helperText = props.helperText, label = props.label;
|
|
6
|
-
return (React.createElement(Card,
|
|
5
|
+
var children = props.children, title = props.title, value = props.value, dataTable = props.dataTable, helperText = props.helperText, label = props.label, height = props.height;
|
|
6
|
+
return (React.createElement(Card, { sx: { height: height } },
|
|
7
7
|
React.createElement(ChartSummary, { title: title, value: value, dataTable: dataTable, helperText: helperText, label: label }),
|
|
8
8
|
children));
|
|
9
9
|
}
|
|
@@ -17,14 +17,53 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
17
17
|
import _ from 'lodash';
|
|
18
18
|
import * as React from 'react';
|
|
19
19
|
import { format } from 'date-fns';
|
|
20
|
-
import { Box, Button, DataTable, Dialog, Tab, TabList, TabPanel, Tabs } from '@auth0/quantum-product';
|
|
20
|
+
import { Box, Button, DataTable, Dialog, DownloadIcon, Tab, TabList, TabPanel, Tabs } from '@auth0/quantum-product';
|
|
21
21
|
export function DataTableChart(props) {
|
|
22
22
|
var isOpen = props.isOpen, title = props.title, toggleIsOpen = props.toggleIsOpen, data = props.data;
|
|
23
23
|
var isDonut = data[0] && data[0].name !== undefined;
|
|
24
24
|
var groups = _.groupBy(data, 'group');
|
|
25
25
|
var _a = __read(React.useState(Object.keys(groups)[0]), 2), selectedTab = _a[0], setSelectedTab = _a[1];
|
|
26
|
+
var hasKey = data[0] && data[0].key !== undefined;
|
|
27
|
+
var downloadCSV = function (filename) {
|
|
28
|
+
if (filename === void 0) { filename = 'chart data'; }
|
|
29
|
+
var mappedData = data.map(function (row) {
|
|
30
|
+
if (row.date) {
|
|
31
|
+
row.date = format(new Date(row.date), 'LLL d p');
|
|
32
|
+
}
|
|
33
|
+
return Object.values(row).map(function (column) { return "\"".concat(column === '–' ? '–' : column, "\""); });
|
|
34
|
+
});
|
|
35
|
+
mappedData.unshift(Object.keys(data[0]));
|
|
36
|
+
var content = '', csvData = '';
|
|
37
|
+
mappedData.forEach(function (d, i) {
|
|
38
|
+
csvData = d.join(',');
|
|
39
|
+
content += i < data.length ? csvData + '\n' : csvData;
|
|
40
|
+
});
|
|
41
|
+
var anchor = document.createElement('a');
|
|
42
|
+
var mimeType = 'text/csv;encoding:utf-8';
|
|
43
|
+
if (navigator['msSaveBlob']) {
|
|
44
|
+
// Internet Explorer 10
|
|
45
|
+
navigator['msSaveBlob'](new Blob([content], {
|
|
46
|
+
type: mimeType,
|
|
47
|
+
}), filename);
|
|
48
|
+
}
|
|
49
|
+
else if (URL && 'download' in anchor) {
|
|
50
|
+
// HTML5
|
|
51
|
+
var href = URL.createObjectURL(new Blob([content], {
|
|
52
|
+
type: mimeType,
|
|
53
|
+
}));
|
|
54
|
+
anchor.href = href;
|
|
55
|
+
anchor.setAttribute('download', filename);
|
|
56
|
+
document.body.appendChild(anchor);
|
|
57
|
+
anchor.click();
|
|
58
|
+
document.body.removeChild(anchor);
|
|
59
|
+
URL.revokeObjectURL(href);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
location.href = "data:application/octet-stream,".concat(encodeURIComponent(content));
|
|
63
|
+
}
|
|
64
|
+
};
|
|
26
65
|
return (React.createElement(Dialog, { open: isOpen, fullWidth: true, title: title, onClose: toggleIsOpen, actions: React.createElement(React.Fragment, null,
|
|
27
|
-
React.createElement(Button, { color: "primary", variant: "contained" }, "Download
|
|
66
|
+
React.createElement(Button, { color: "primary", variant: "contained", startIcon: React.createElement(DownloadIcon, null), onClick: function () { return downloadCSV(title); } }, "Download")) },
|
|
28
67
|
React.createElement(Box, { p: 2 },
|
|
29
68
|
React.createElement(Tabs, { baseId: 'example', onChange: setSelectedTab, value: selectedTab },
|
|
30
69
|
React.createElement(TabList, { classes: { indicator: 'chromatic-ignore' } }, !isDonut &&
|
|
@@ -45,10 +84,13 @@ export function DataTableChart(props) {
|
|
|
45
84
|
var item = _a.item;
|
|
46
85
|
return item.value || 'N/A';
|
|
47
86
|
} },
|
|
48
|
-
{
|
|
87
|
+
{
|
|
88
|
+
title: hasKey ? 'key' : 'date',
|
|
89
|
+
render: function (_a) {
|
|
49
90
|
var item = _a.item;
|
|
50
|
-
return format(new Date(item.date), 'LLL d p');
|
|
51
|
-
}
|
|
91
|
+
return (hasKey ? item.key : format(new Date(item.date), 'LLL d p'));
|
|
92
|
+
},
|
|
93
|
+
},
|
|
52
94
|
] })));
|
|
53
95
|
})))))));
|
|
54
96
|
}
|
package/esm/common/chart.js
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
import { format } from 'date-fns';
|
|
2
|
+
export var tickFormatter = function (value, scaleType) {
|
|
3
|
+
switch (scaleType) {
|
|
4
|
+
case 'number':
|
|
5
|
+
if (value > 1000000000) {
|
|
6
|
+
return (value / 1000000000).toString() + 'B';
|
|
7
|
+
}
|
|
8
|
+
else if (value > 1000000) {
|
|
9
|
+
return (value / 1000000).toString() + 'M';
|
|
10
|
+
}
|
|
11
|
+
else if (value > 1000) {
|
|
12
|
+
return (value / 1000).toString() + 'K';
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return value.toString();
|
|
16
|
+
}
|
|
17
|
+
case 'label':
|
|
18
|
+
if (value.length <= 8)
|
|
19
|
+
return value;
|
|
20
|
+
return "".concat(value.substring(0, 8), "...");
|
|
21
|
+
case 'date':
|
|
22
|
+
return format(new Date(value), 'LLL d');
|
|
23
|
+
case 'datetime':
|
|
24
|
+
return format(new Date(value), 'LLL d p');
|
|
25
|
+
default:
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
import { StackLayout, Text, styled } from '@auth0/quantum-product';
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
var Root = styled(StackLayout)(function (_a) {
|
|
15
|
+
var theme = _a.theme;
|
|
16
|
+
return ({
|
|
17
|
+
justifyContent: 'center',
|
|
18
|
+
marginTop: theme.spacing(3),
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
var LegendIcon = styled('div')(function (_a) {
|
|
22
|
+
var theme = _a.theme, ownerState = _a.ownerState;
|
|
23
|
+
return (__assign({}, (ownerState.isHide
|
|
24
|
+
? {
|
|
25
|
+
borderRadius: theme.spacing(0.5),
|
|
26
|
+
border: "2px solid ".concat(ownerState.color),
|
|
27
|
+
width: '14px',
|
|
28
|
+
height: '14px',
|
|
29
|
+
}
|
|
30
|
+
: {
|
|
31
|
+
background: ownerState.color,
|
|
32
|
+
width: '14px',
|
|
33
|
+
height: '14px',
|
|
34
|
+
borderRadius: '4px',
|
|
35
|
+
})));
|
|
36
|
+
});
|
|
37
|
+
export var CustomLegend = function (props) {
|
|
38
|
+
var payload = props.payload, selectData = props.selectData, handleLegendMouseEnter = props.handleLegendMouseEnter, handleLegendMouseLeave = props.handleLegendMouseLeave, dataVisibility = props.dataVisibility;
|
|
39
|
+
return (React.createElement(Root, { gutter: 1 }, payload.map(function (entry, index) { return (React.createElement(StackLayout, { sx: { padding: '4px 8px', cursor: 'pointer' }, key: index, gutter: 1, onClick: function () { return selectData(entry); }, onMouseEnter: function () { return handleLegendMouseEnter(entry); }, onMouseLeave: function () { return handleLegendMouseLeave(entry); } },
|
|
40
|
+
React.createElement(LegendIcon, { ownerState: { isHide: dataVisibility[entry.dataKey], color: entry.color } }),
|
|
41
|
+
React.createElement(Text, { variant: "body2" }, entry.value))); })));
|
|
42
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Box, RowLayout, StackLayout, Text } from '@auth0/quantum-product';
|
|
3
|
+
import StatusDot from './custom-color-status-dot';
|
|
4
|
+
import { format } from 'date-fns';
|
|
5
|
+
import { CustomTooltip as CustomTooltipStyled } from '../styles';
|
|
6
|
+
var CustomTooltip = function (props) {
|
|
7
|
+
var _a, _b, _c;
|
|
8
|
+
var active = props.active, payload = props.payload, scaleType = props.scaleType, labelProp = props.label;
|
|
9
|
+
if (active && payload && payload.length) {
|
|
10
|
+
var label = ((_a = payload[0].payload) === null || _a === void 0 ? void 0 : _a.date)
|
|
11
|
+
? scaleType === 'datetime'
|
|
12
|
+
? "".concat(format(new Date((_b = payload[0].payload) === null || _b === void 0 ? void 0 : _b.date), 'LLL d HH:mm'))
|
|
13
|
+
: "".concat(format(new Date((_c = payload[0].payload) === null || _c === void 0 ? void 0 : _c.date), 'LLL d'))
|
|
14
|
+
: labelProp;
|
|
15
|
+
return (React.createElement(CustomTooltipStyled, null,
|
|
16
|
+
React.createElement(Text, { color: "text.secondary" }, label),
|
|
17
|
+
React.createElement(Box, null,
|
|
18
|
+
React.createElement(RowLayout, { gutter: 1 }, payload.map(function (x, index) {
|
|
19
|
+
return (React.createElement(StackLayout, { key: index, gutter: 0.5 },
|
|
20
|
+
React.createElement(StatusDot, { key: index, dotColor: x.color || 'grey', label: "".concat(x.name, ":") + ' ' }),
|
|
21
|
+
React.createElement(Text, { color: "text.secondary" }, x.payload[x.name || ''])));
|
|
22
|
+
})))));
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
26
|
+
export default CustomTooltip;
|
|
@@ -1,18 +1,54 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
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);
|
|
4
11
|
};
|
|
5
12
|
import * as React from 'react';
|
|
6
|
-
import styled from '
|
|
7
|
-
import {
|
|
8
|
-
|
|
13
|
+
import { StackLayout, StackLayoutItem, styled, useTheme } from '@auth0/quantum-product';
|
|
14
|
+
import { getColorScale } from '../theme';
|
|
15
|
+
var Root = styled('div')(function (_a) {
|
|
16
|
+
var _b;
|
|
17
|
+
var theme = _a.theme, ownerState = _a.ownerState;
|
|
18
|
+
return (__assign((_b = { display: 'flex', flexDirection: 'column' }, _b[theme.breakpoints.down('sm')] = {
|
|
19
|
+
flexDirection: 'row',
|
|
20
|
+
justifyContent: 'center',
|
|
21
|
+
gap: theme.spacing(2),
|
|
22
|
+
maxWidth: '300px',
|
|
23
|
+
flexWrap: 'wrap',
|
|
24
|
+
}, _b), (ownerState.layout === 'vertical' && {
|
|
25
|
+
flexDirection: 'row',
|
|
26
|
+
justifyContent: 'center',
|
|
27
|
+
gap: theme.spacing(2),
|
|
28
|
+
maxWidth: '300px',
|
|
29
|
+
flexWrap: 'wrap',
|
|
30
|
+
})));
|
|
31
|
+
});
|
|
32
|
+
var LegendDot = styled('div')({
|
|
33
|
+
height: '14px',
|
|
34
|
+
width: '14px',
|
|
35
|
+
borderRadius: '4px',
|
|
36
|
+
});
|
|
37
|
+
var LegendText = styled('span')({
|
|
38
|
+
whiteSpace: 'nowrap',
|
|
39
|
+
overflow: 'hidden',
|
|
40
|
+
textOverflow: 'ellipsis',
|
|
41
|
+
cursor: 'default',
|
|
42
|
+
});
|
|
9
43
|
function DecoupledLegend(props) {
|
|
10
|
-
var data = props.data, activeIndex = props.activeIndex, setActiveIndex = props.setActiveIndex;
|
|
44
|
+
var data = props.data, activeIndex = props.activeIndex, setActiveIndex = props.setActiveIndex, _a = props.color, color = _a === void 0 ? 'categorical' : _a, _b = props.layout, layout = _b === void 0 ? 'horizontal' : _b;
|
|
11
45
|
var theme = useTheme();
|
|
12
|
-
var BASE_COLORS =
|
|
13
|
-
|
|
46
|
+
var BASE_COLORS = getColorScale(theme)[color]['base'];
|
|
47
|
+
var MUTED_COLORS = getColorScale(theme)[color]['muted'];
|
|
48
|
+
return (React.createElement(Root, { ownerState: { layout: layout } }, data.map(function (datum, index) {
|
|
14
49
|
var isActive = activeIndex !== undefined && activeIndex === index;
|
|
15
50
|
var color = BASE_COLORS[index % BASE_COLORS.length];
|
|
51
|
+
var mutedColor = MUTED_COLORS[index % MUTED_COLORS.length];
|
|
16
52
|
return (React.createElement(React.Fragment, { key: index },
|
|
17
53
|
React.createElement(StackLayout, { gutter: 1, onMouseEnter: function () {
|
|
18
54
|
setActiveIndex(index);
|
|
@@ -24,21 +60,11 @@ function DecoupledLegend(props) {
|
|
|
24
60
|
React.createElement(StackLayoutItem, { sx: {
|
|
25
61
|
alignSelf: 'center',
|
|
26
62
|
} },
|
|
27
|
-
React.createElement(
|
|
28
|
-
border: '2px solid ' + (isActive ? color : 'white'),
|
|
29
|
-
} },
|
|
30
|
-
React.createElement(LegendDot, { style: { backgroundColor: color } }))),
|
|
63
|
+
React.createElement(LegendDot, { style: { backgroundColor: activeIndex === undefined ? color : isActive ? color : mutedColor } })),
|
|
31
64
|
React.createElement(StackLayoutItem, { sx: {
|
|
32
65
|
alignSelf: 'center',
|
|
33
66
|
} },
|
|
34
67
|
React.createElement(LegendText, { color: isActive ? 'primary' : 'secondary' }, datum.name)))));
|
|
35
68
|
})));
|
|
36
69
|
}
|
|
37
|
-
var LegendDot = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n height: 12px;\n width: 12px;\n border: 2px solid white;\n border-radius: 2px;\n"], ["\n height: 12px;\n width: 12px;\n border: 2px solid white;\n border-radius: 2px;\n"])));
|
|
38
|
-
var LegendDotWrapper = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n border-radius: 4px;\n"], ["\n border-radius: 4px;\n"])));
|
|
39
|
-
var LegendText = styled.span(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n color: ", ";\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n cursor: default;\n"], ["\n color: ", ";\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n cursor: default;\n"])), function (_a) {
|
|
40
|
-
var theme = _a.theme, color = _a.color;
|
|
41
|
-
return theme.palette.text[color !== null && color !== void 0 ? color : 'secondary'];
|
|
42
|
-
});
|
|
43
70
|
export default DecoupledLegend;
|
|
44
|
-
var templateObject_1, templateObject_2, templateObject_3;
|
package/esm/donut-chart/index.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
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
|
+
};
|
|
1
12
|
var __read = (this && this.__read) || function (o, n) {
|
|
2
13
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
14
|
if (!m) return o;
|
|
@@ -16,28 +27,33 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
16
27
|
};
|
|
17
28
|
import * as React from 'react';
|
|
18
29
|
import { Cell, Pie, PieChart as RechartsPieChart, ResponsiveContainer } from 'recharts';
|
|
19
|
-
import { StackLayout, StackLayoutItem, useTheme } from '@auth0/quantum-product';
|
|
20
|
-
import {
|
|
30
|
+
import { StackLayout, StackLayoutItem, styled, useTheme } from '@auth0/quantum-product';
|
|
31
|
+
import { getColorScale } from '../theme';
|
|
21
32
|
import Center from './center';
|
|
22
33
|
import DecoupledLegend from './decoupled-legend';
|
|
23
34
|
import { ChartCard } from '../chart-card';
|
|
35
|
+
var ResponsiveChartCard = styled(StackLayout)(function (_a) {
|
|
36
|
+
var _b;
|
|
37
|
+
var theme = _a.theme, ownerState = _a.ownerState;
|
|
38
|
+
return (__assign((_b = {}, _b[theme.breakpoints.down('sm')] = {
|
|
39
|
+
flexDirection: 'column',
|
|
40
|
+
}, _b.flexWrap = 'nowrap', _b.justifyContent = 'space-around', _b.paddingTop = theme.spacing(3), _b.paddingBottom = theme.spacing(4), _b.height = 'calc(100% - 44px)', _b), (ownerState.layout === 'vertical' && {
|
|
41
|
+
flexDirection: 'column',
|
|
42
|
+
})));
|
|
43
|
+
});
|
|
24
44
|
export function DonutChart(props) {
|
|
25
|
-
var data = props.data, displayType = props.displayType, title = props.title, value = props.value, label = props.label, helperText = props.helperText;
|
|
26
|
-
var
|
|
45
|
+
var data = props.data, displayType = props.displayType, title = props.title, value = props.value, label = props.label, helperText = props.helperText, _a = props.layout, layout = _a === void 0 ? 'horizontal' : _a, _b = props.color, color = _b === void 0 ? 'categorical' : _b, _c = props.height, height = _c === void 0 ? '100%' : _c;
|
|
46
|
+
var _d = __read(React.useState(undefined), 2), activeIndex = _d[0], setActiveIndex = _d[1];
|
|
27
47
|
var theme = useTheme();
|
|
28
|
-
var BASE_COLORS =
|
|
29
|
-
return (React.createElement(ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText },
|
|
30
|
-
React.createElement(
|
|
31
|
-
height: '150px',
|
|
32
|
-
flexWrap: 'nowrap',
|
|
33
|
-
mt: '24px',
|
|
34
|
-
} },
|
|
48
|
+
var BASE_COLORS = getColorScale(theme)[color]['base'];
|
|
49
|
+
return (React.createElement(ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText, height: height },
|
|
50
|
+
React.createElement(ResponsiveChartCard, { ownerState: { layout: layout } },
|
|
35
51
|
React.createElement(StackLayoutItem, { sx: {
|
|
36
52
|
height: '150px',
|
|
37
53
|
width: '150px',
|
|
38
54
|
} },
|
|
39
55
|
React.createElement(ResponsiveContainer, { width: '100%', height: 150 },
|
|
40
|
-
React.createElement(RechartsPieChart, {
|
|
56
|
+
React.createElement(RechartsPieChart, { style: { minWidth: '150px', minHeight: '150px' } },
|
|
41
57
|
React.createElement("foreignObject", { x: 0, y: 0, width: '100%', height: '100%' },
|
|
42
58
|
React.createElement(Center, { activeIndex: activeIndex, data: data, displayType: displayType })),
|
|
43
59
|
React.createElement(Pie, { dataKey: 'value', data: data, innerRadius: 55, outerRadius: 75, paddingAngle: 2, animationDuration: 750, animationBegin: 0, activeIndex: activeIndex, onMouseEnter: function (_, index) {
|
|
@@ -48,5 +64,5 @@ export function DonutChart(props) {
|
|
|
48
64
|
return (React.createElement(Cell, { key: "cell-".concat(index), fill: BASE_COLORS[index % BASE_COLORS.length], opacity: activeIndex === undefined ? 1 : activeIndex === index ? 1 : 0.5 }));
|
|
49
65
|
}))))),
|
|
50
66
|
React.createElement(StackLayoutItem, null,
|
|
51
|
-
React.createElement(DecoupledLegend, { activeIndex: activeIndex, setActiveIndex: setActiveIndex, data: data })))));
|
|
67
|
+
React.createElement(DecoupledLegend, { activeIndex: activeIndex, setActiveIndex: setActiveIndex, data: data, color: color, layout: layout })))));
|
|
52
68
|
}
|
package/esm/line-chart/index.js
CHANGED
|
@@ -1,17 +1,62 @@
|
|
|
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 __read = (this && this.__read) || function (o, n) {
|
|
13
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
+
if (!m) return o;
|
|
15
|
+
var i = m.call(o), r, ar = [], e;
|
|
16
|
+
try {
|
|
17
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
+
}
|
|
19
|
+
catch (error) { e = { error: error }; }
|
|
20
|
+
finally {
|
|
21
|
+
try {
|
|
22
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
+
}
|
|
24
|
+
finally { if (e) throw e.error; }
|
|
25
|
+
}
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
1
28
|
import _ from 'lodash';
|
|
2
29
|
import * as React from 'react';
|
|
3
30
|
import { CartesianGrid, Legend, Line, LineChart as RechartsLineChart, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts';
|
|
4
|
-
import { format } from 'date-fns';
|
|
5
31
|
import { useTheme, Text } from '@auth0/quantum-product';
|
|
6
|
-
import {
|
|
32
|
+
import { getColorScale } from '../theme';
|
|
7
33
|
import CustomActiveDot from './custom-active-dot';
|
|
8
|
-
import CustomTooltip from '
|
|
34
|
+
import CustomTooltip from '../common/custom-tooltip';
|
|
9
35
|
import { ChartCard } from '../chart-card';
|
|
36
|
+
import { tickFormatter } from '../common/chart';
|
|
37
|
+
import { CustomLegend } from '../common/custom-legend';
|
|
10
38
|
export function LineChart(props) {
|
|
11
|
-
var _a = props, data = _a.data, leftAxis = _a.leftAxis, bottomAxis = _a.bottomAxis, _b = _a.height, height = _b === void 0 ? 300 : _b, title = _a.title, value = _a.value, label = _a.label, helperText = _a.helperText, _c = _a.legend, legend = _c === void 0 ? true : _c, syncId = _a.syncId;
|
|
39
|
+
var _a = props, data = _a.data, leftAxis = _a.leftAxis, bottomAxis = _a.bottomAxis, _b = _a.height, height = _b === void 0 ? 300 : _b, title = _a.title, value = _a.value, label = _a.label, helperText = _a.helperText, _c = _a.legend, legend = _c === void 0 ? true : _c, syncId = _a.syncId, _d = _a.color, color = _d === void 0 ? 'categorical' : _d;
|
|
12
40
|
var theme = useTheme();
|
|
13
41
|
// Function to know how many lines we need based of how much different group values are.
|
|
14
42
|
var groups = _.uniqBy(data, 'group').map(function (item) { return item.group; });
|
|
43
|
+
var initialState = __assign({ hover: null }, groups.reduce(function (acc, group) {
|
|
44
|
+
var _a;
|
|
45
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[group] = false, _a)));
|
|
46
|
+
}, {}));
|
|
47
|
+
var _e = __read(React.useState(initialState), 2), lineVisibility = _e[0], setLineVisibility = _e[1];
|
|
48
|
+
var handleLegendMouseEnter = function (e) {
|
|
49
|
+
if (!lineVisibility[e.dataKey]) {
|
|
50
|
+
setLineVisibility(__assign(__assign({}, lineVisibility), { hover: e.dataKey }));
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var handleLegendMouseLeave = function () {
|
|
54
|
+
setLineVisibility(__assign(__assign({}, lineVisibility), { hover: null }));
|
|
55
|
+
};
|
|
56
|
+
var selectLine = function (e) {
|
|
57
|
+
var _a;
|
|
58
|
+
setLineVisibility(__assign(__assign({}, lineVisibility), (_a = {}, _a[e.dataKey] = !lineVisibility[e.dataKey], _a.hover = null, _a)));
|
|
59
|
+
};
|
|
15
60
|
var bottomAxisDataKey = bottomAxis.mapsTo || 'date';
|
|
16
61
|
var leftAxisDataKey = leftAxis.mapsTo || 'value';
|
|
17
62
|
var entries = {};
|
|
@@ -32,15 +77,6 @@ export function LineChart(props) {
|
|
|
32
77
|
_b[entry.group] = entry[leftAxisDataKey],
|
|
33
78
|
_b;
|
|
34
79
|
});
|
|
35
|
-
var formatBottomTick = function (value) {
|
|
36
|
-
if (bottomAxis.scaleType === 'date') {
|
|
37
|
-
return format(new Date(value), 'LLL d');
|
|
38
|
-
}
|
|
39
|
-
if (bottomAxis.scaleType === 'datetime') {
|
|
40
|
-
return format(new Date(value), 'LLL d p');
|
|
41
|
-
}
|
|
42
|
-
return value;
|
|
43
|
-
};
|
|
44
80
|
return (React.createElement(ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText },
|
|
45
81
|
React.createElement(ResponsiveContainer, { width: '100%', height: height }, data.length ? (React.createElement(RechartsLineChart, { data: Object.values(entries), height: height, width: 500, syncId: syncId, margin: {
|
|
46
82
|
top: 24,
|
|
@@ -48,13 +84,15 @@ export function LineChart(props) {
|
|
|
48
84
|
left: -24,
|
|
49
85
|
bottom: 0,
|
|
50
86
|
} },
|
|
51
|
-
React.createElement(XAxis, { tickFormatter: formatBottomTick, dataKey: bottomAxisDataKey, height: 30, interval: "preserveStartEnd" }),
|
|
52
87
|
React.createElement(CartesianGrid, { vertical: false, stroke: theme.tokens.color_border_default }),
|
|
53
|
-
React.createElement(
|
|
54
|
-
React.createElement(
|
|
55
|
-
|
|
88
|
+
React.createElement(XAxis, { tickFormatter: function (value) { return tickFormatter(value, bottomAxis.scaleType); }, dataKey: bottomAxisDataKey, height: 30, interval: "preserveStartEnd", minTickGap: theme.spacingPX(14), tickMargin: theme.spacingPX(3), axisLine: { stroke: theme.tokens.color_border_bold }, tickLine: { stroke: theme.tokens.color_border_bold } }),
|
|
89
|
+
React.createElement(YAxis, { tickFormatter: function (value) { return tickFormatter(value, leftAxis.scaleType); }, domain: ['auto', 'auto'], width: 78, axisLine: { stroke: theme.tokens.color_border_bold }, tickLine: { stroke: theme.tokens.color_border_bold } }),
|
|
90
|
+
React.createElement(Tooltip, { wrapperStyle: { outline: 'none' }, content: React.createElement(CustomTooltip, { active: undefined, payload: undefined, scaleType: bottomAxis.scaleType }) }),
|
|
91
|
+
legend && (React.createElement(Legend, { align: "center", iconSize: 14, wrapperStyle: { paddingTop: 16 }, content: React.createElement(CustomLegend, { selectData: selectLine, handleLegendMouseEnter: handleLegendMouseEnter, handleLegendMouseLeave: handleLegendMouseLeave, dataVisibility: lineVisibility }) })),
|
|
56
92
|
groups.map(function (group, index) {
|
|
57
|
-
return (React.createElement(Line, { key: group, dataKey: group, name: group, strokeWidth: 3,
|
|
93
|
+
return (React.createElement(Line, { key: group, dataKey: group, name: group, strokeWidth: 3, hide: lineVisibility[group] === true, stroke: lineVisibility.hover === group || !lineVisibility.hover
|
|
94
|
+
? getColorScale(theme)[color]['base'][index]
|
|
95
|
+
: getColorScale(theme)[color]['muted'][index], dot: false, activeDot: CustomActiveDot() }));
|
|
58
96
|
}))) : (React.createElement("div", { style: {
|
|
59
97
|
display: 'grid',
|
|
60
98
|
placeItems: 'center',
|
package/esm/scorecard/index.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ChartSummary } from '../chart-summary';
|
|
3
3
|
import { ChartCard } from '../chart-card';
|
|
4
|
-
import {
|
|
4
|
+
import { StackLayout, StackLayoutItem } from '@auth0/quantum-product';
|
|
5
5
|
export function ScoreCard(props) {
|
|
6
6
|
var data = props.data;
|
|
7
7
|
return (React.createElement(ChartCard, null,
|
|
8
|
-
React.createElement(
|
|
9
|
-
|
|
8
|
+
React.createElement(StackLayout, { sx: {
|
|
9
|
+
justifyContent: 'space-between',
|
|
10
|
+
alignContent: ['initial', 'center'],
|
|
11
|
+
alignItems: ['initial', 'center'],
|
|
12
|
+
flexWrap: 'wrap',
|
|
13
|
+
flexDirection: ['column', 'row'],
|
|
14
|
+
} }, data.map(function (summary, index) {
|
|
15
|
+
return (React.createElement(StackLayoutItem, { key: index, sx: { flex: 1, mr: 2 } },
|
|
10
16
|
React.createElement(ChartSummary, { title: summary.title, value: summary.value, helperText: summary.helperText, label: summary.label })));
|
|
11
17
|
}))));
|
|
12
18
|
}
|
package/esm/styles.js
CHANGED
|
@@ -2,9 +2,8 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
|
|
|
2
2
|
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
3
|
return cooked;
|
|
4
4
|
};
|
|
5
|
-
import styled from '
|
|
6
|
-
|
|
7
|
-
export var ChartContainer = styled.div(function (_a) {
|
|
5
|
+
import { Box, styled } from '@auth0/quantum-product';
|
|
6
|
+
export var ChartContainer = styled('div')(function (_a) {
|
|
8
7
|
var theme = _a.theme, height = _a.height, marginTop = _a.marginTop;
|
|
9
8
|
var props = {
|
|
10
9
|
marginTop: theme.spacing(3),
|
|
@@ -18,20 +17,21 @@ export var ChartContainer = styled.div(function (_a) {
|
|
|
18
17
|
}
|
|
19
18
|
return props;
|
|
20
19
|
});
|
|
21
|
-
export var CustomTooltip = styled
|
|
20
|
+
export var CustomTooltip = styled('div')(function (_a) {
|
|
22
21
|
var theme = _a.theme;
|
|
23
22
|
return ({
|
|
24
|
-
|
|
23
|
+
display: 'grid',
|
|
24
|
+
gap: theme.spacing(1),
|
|
25
|
+
backgroundColor: theme.tokens.color_bg_layer_elevated,
|
|
26
|
+
border: "1px solid ".concat(theme.tokens.color_border_bold),
|
|
25
27
|
borderRadius: theme.shape.borderRadius,
|
|
26
|
-
padding: theme.spacing(1,
|
|
27
|
-
color: theme.tokens.
|
|
28
|
+
padding: theme.spacing(1, 2),
|
|
29
|
+
color: theme.tokens.color_fg_bold,
|
|
28
30
|
fontSize: theme.typography.caption.fontSize,
|
|
29
31
|
fontWeight: theme.typography.caption.fontWeight,
|
|
30
32
|
lineHeight: theme.typography.caption.lineHeight,
|
|
31
33
|
letterSpacing: theme.typography.caption.letterSpacing,
|
|
32
34
|
});
|
|
33
35
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export var DefaultCursorBox = styled(Box)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n cursor: default;\n"], ["\n cursor: default;\n"])));
|
|
37
|
-
var templateObject_1, templateObject_2;
|
|
36
|
+
export var DefaultCursorBox = styled(Box)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n cursor: default;\n"], ["\n cursor: default;\n"])));
|
|
37
|
+
var templateObject_1;
|