@auth0/quantum-charts 1.0.2 → 1.0.4
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/chart-summary/data-table-chart.js +2 -39
- package/chart-summary/index.js +16 -3
- package/common/custom-tooltip.js +1 -2
- package/esm/chart-summary/data-table-chart.js +2 -39
- package/esm/chart-summary/index.js +17 -4
- package/esm/common/custom-tooltip.js +1 -2
- package/esm/helpers/downloadCsv.js +39 -0
- package/esm/line-chart/index.js +14 -4
- package/helpers/downloadCsv.d.ts +1 -0
- package/helpers/downloadCsv.js +43 -0
- package/line-chart/index.js +13 -3
- package/package.json +1 -1
|
@@ -46,6 +46,7 @@ exports.DataTableChart = void 0;
|
|
|
46
46
|
var lodash_1 = __importDefault(require("lodash"));
|
|
47
47
|
var React = __importStar(require("react"));
|
|
48
48
|
var date_fns_1 = require("date-fns");
|
|
49
|
+
var downloadCsv_1 = require("../helpers/downloadCsv");
|
|
49
50
|
var quantum_product_1 = require("@auth0/quantum-product");
|
|
50
51
|
function DataTableChart(props) {
|
|
51
52
|
var isOpen = props.isOpen, title = props.title, toggleIsOpen = props.toggleIsOpen, data = props.data;
|
|
@@ -53,46 +54,8 @@ function DataTableChart(props) {
|
|
|
53
54
|
var groups = lodash_1.default.groupBy(data, 'group');
|
|
54
55
|
var _a = __read(React.useState(Object.keys(groups)[0]), 2), selectedTab = _a[0], setSelectedTab = _a[1];
|
|
55
56
|
var hasKey = data[0] && data[0].key !== undefined;
|
|
56
|
-
var downloadCSV = function (filename) {
|
|
57
|
-
if (filename === void 0) { filename = 'chart data'; }
|
|
58
|
-
var mappedData = data.map(function (row) {
|
|
59
|
-
if (row.date) {
|
|
60
|
-
row.date = (0, date_fns_1.format)(new Date(row.date), 'LLL d p');
|
|
61
|
-
}
|
|
62
|
-
return Object.values(row).map(function (column) { return "\"".concat(column === '–' ? '–' : column, "\""); });
|
|
63
|
-
});
|
|
64
|
-
mappedData.unshift(Object.keys(data[0]));
|
|
65
|
-
var content = '', csvData = '';
|
|
66
|
-
mappedData.forEach(function (d, i) {
|
|
67
|
-
csvData = d.join(',');
|
|
68
|
-
content += i < data.length ? csvData + '\n' : csvData;
|
|
69
|
-
});
|
|
70
|
-
var anchor = document.createElement('a');
|
|
71
|
-
var mimeType = 'text/csv;encoding:utf-8';
|
|
72
|
-
if (navigator['msSaveBlob']) {
|
|
73
|
-
// Internet Explorer 10
|
|
74
|
-
navigator['msSaveBlob'](new Blob([content], {
|
|
75
|
-
type: mimeType,
|
|
76
|
-
}), filename);
|
|
77
|
-
}
|
|
78
|
-
else if (URL && 'download' in anchor) {
|
|
79
|
-
// HTML5
|
|
80
|
-
var href = URL.createObjectURL(new Blob([content], {
|
|
81
|
-
type: mimeType,
|
|
82
|
-
}));
|
|
83
|
-
anchor.href = href;
|
|
84
|
-
anchor.setAttribute('download', filename);
|
|
85
|
-
document.body.appendChild(anchor);
|
|
86
|
-
anchor.click();
|
|
87
|
-
document.body.removeChild(anchor);
|
|
88
|
-
URL.revokeObjectURL(href);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
location.href = "data:application/octet-stream,".concat(encodeURIComponent(content));
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
57
|
return (React.createElement(quantum_product_1.Dialog, { open: isOpen, fullWidth: true, title: title, onClose: toggleIsOpen, actions: React.createElement(React.Fragment, null,
|
|
95
|
-
React.createElement(quantum_product_1.Button, { color: "primary", variant: "contained", startIcon: React.createElement(quantum_product_1.DownloadIcon, null), onClick: function () { return downloadCSV(title); } }, "Download")) },
|
|
58
|
+
React.createElement(quantum_product_1.Button, { color: "primary", variant: "contained", startIcon: React.createElement(quantum_product_1.DownloadIcon, null), onClick: function () { return (0, downloadCsv_1.downloadCSV)(data, title); } }, "Download")) },
|
|
96
59
|
React.createElement(quantum_product_1.Box, null,
|
|
97
60
|
React.createElement(quantum_product_1.Tabs, { baseId: 'example', onChange: setSelectedTab, value: selectedTab },
|
|
98
61
|
React.createElement(quantum_product_1.TabList, { classes: { indicator: 'chromatic-ignore' }, style: isDonut ? { display: 'none' } : { display: 'block' } }, !isDonut &&
|
package/chart-summary/index.js
CHANGED
|
@@ -66,6 +66,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
66
66
|
exports.ChartSummary = void 0;
|
|
67
67
|
var React = __importStar(require("react"));
|
|
68
68
|
var quantum_product_1 = require("@auth0/quantum-product");
|
|
69
|
+
var downloadCsv_1 = require("../helpers/downloadCsv");
|
|
69
70
|
var data_table_chart_1 = require("./data-table-chart");
|
|
70
71
|
var Aggregate = (0, quantum_product_1.styled)('h4')(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n font-weight: ", ";\n font-size: ", ";\n"], ["\n font-weight: ", ";\n font-size: ", ";\n"])), function (_a) {
|
|
71
72
|
var theme = _a.theme;
|
|
@@ -87,11 +88,23 @@ function ChartSummary(props) {
|
|
|
87
88
|
menuItems = [
|
|
88
89
|
{
|
|
89
90
|
type: 'item',
|
|
90
|
-
endIcon: React.createElement(quantum_product_1.
|
|
91
|
+
endIcon: React.createElement(quantum_product_1.TableIcon, null),
|
|
91
92
|
onClick: function () {
|
|
92
93
|
setIsOpen(true);
|
|
93
94
|
},
|
|
94
|
-
title: 'View
|
|
95
|
+
title: 'View table',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
type: 'divider',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
type: 'item',
|
|
102
|
+
endIcon: React.createElement(quantum_product_1.DownloadCloudIcon, null),
|
|
103
|
+
onClick: function () {
|
|
104
|
+
setIsOpen(true);
|
|
105
|
+
(0, downloadCsv_1.downloadCSV)(dataTable, title);
|
|
106
|
+
},
|
|
107
|
+
title: 'Download CSV',
|
|
95
108
|
},
|
|
96
109
|
];
|
|
97
110
|
}
|
|
@@ -115,7 +128,7 @@ function ChartSummary(props) {
|
|
|
115
128
|
return item;
|
|
116
129
|
});
|
|
117
130
|
return menuItems;
|
|
118
|
-
}, [dataTable, additionalMenuItems, menuProps]);
|
|
131
|
+
}, [dataTable, additionalMenuItems, menuProps, title]);
|
|
119
132
|
return (React.createElement("div", null,
|
|
120
133
|
React.createElement(quantum_product_1.DescriptionBlock, { label: React.createElement("div", { style: { display: 'flex', justifyContent: 'space-between' } },
|
|
121
134
|
React.createElement(quantum_product_1.StackLayout, { gutter: 1 },
|
package/common/custom-tooltip.js
CHANGED
|
@@ -27,7 +27,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
var React = __importStar(require("react"));
|
|
30
|
-
var icon_1 = require("@auth0/quantum-product/src/icon");
|
|
31
30
|
var quantum_product_1 = require("@auth0/quantum-product");
|
|
32
31
|
var custom_color_status_dot_1 = __importDefault(require("./custom-color-status-dot"));
|
|
33
32
|
var date_fns_1 = require("date-fns");
|
|
@@ -54,7 +53,7 @@ var CustomTooltip = function (props) {
|
|
|
54
53
|
React.createElement(quantum_product_1.Text, { color: "text.secondary", alignItems: 'end' }, x.payload[x.dataKey || '']),
|
|
55
54
|
x.payload['evaluated_metric'] === x.dataKey &&
|
|
56
55
|
x.payload['breachedPoint'] !== 'none' &&
|
|
57
|
-
(x.payload['breachedPoint'] === 'alert' ? (React.createElement(
|
|
56
|
+
(x.payload['breachedPoint'] === 'alert' ? (React.createElement(quantum_product_1.AlertDiamondFilledIcon, { color: theme.tokens.color_fg_state_danger })) : (React.createElement(quantum_product_1.AlertTriangleFilledIcon, { color: theme.tokens.color_fg_state_caution })))));
|
|
58
57
|
})))));
|
|
59
58
|
}
|
|
60
59
|
return null;
|
|
@@ -17,6 +17,7 @@ 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 { downloadCSV } from '../helpers/downloadCsv';
|
|
20
21
|
import { Box, Button, DataTable, Dialog, DownloadIcon, Tab, TabList, TabPanel, Tabs } from '@auth0/quantum-product';
|
|
21
22
|
export function DataTableChart(props) {
|
|
22
23
|
var isOpen = props.isOpen, title = props.title, toggleIsOpen = props.toggleIsOpen, data = props.data;
|
|
@@ -24,46 +25,8 @@ export function DataTableChart(props) {
|
|
|
24
25
|
var groups = _.groupBy(data, 'group');
|
|
25
26
|
var _a = __read(React.useState(Object.keys(groups)[0]), 2), selectedTab = _a[0], setSelectedTab = _a[1];
|
|
26
27
|
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
|
-
};
|
|
65
28
|
return (React.createElement(Dialog, { open: isOpen, fullWidth: true, title: title, onClose: toggleIsOpen, actions: React.createElement(React.Fragment, null,
|
|
66
|
-
React.createElement(Button, { color: "primary", variant: "contained", startIcon: React.createElement(DownloadIcon, null), onClick: function () { return downloadCSV(title); } }, "Download")) },
|
|
29
|
+
React.createElement(Button, { color: "primary", variant: "contained", startIcon: React.createElement(DownloadIcon, null), onClick: function () { return downloadCSV(data, title); } }, "Download")) },
|
|
67
30
|
React.createElement(Box, null,
|
|
68
31
|
React.createElement(Tabs, { baseId: 'example', onChange: setSelectedTab, value: selectedTab },
|
|
69
32
|
React.createElement(TabList, { classes: { indicator: 'chromatic-ignore' }, style: isDonut ? { display: 'none' } : { display: 'block' } }, !isDonut &&
|
|
@@ -39,7 +39,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
39
39
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
40
40
|
};
|
|
41
41
|
import * as React from 'react';
|
|
42
|
-
import { Box, DescriptionBlock, StackLayout, StackLayoutItem, Tooltip, HelpCircleIcon, styled, IconButton,
|
|
42
|
+
import { Box, DescriptionBlock, DownloadCloudIcon, StackLayout, StackLayoutItem, Tooltip, HelpCircleIcon, styled, IconButton, TableIcon, Text, useDropdownMenuState, DropdownMenu, MoreVerticalIcon, } from '@auth0/quantum-product';
|
|
43
|
+
import { downloadCSV } from '../helpers/downloadCsv';
|
|
43
44
|
import { DataTableChart } from './data-table-chart';
|
|
44
45
|
var Aggregate = styled('h4')(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n font-weight: ", ";\n font-size: ", ";\n"], ["\n font-weight: ", ";\n font-size: ", ";\n"])), function (_a) {
|
|
45
46
|
var theme = _a.theme;
|
|
@@ -61,11 +62,23 @@ export function ChartSummary(props) {
|
|
|
61
62
|
menuItems = [
|
|
62
63
|
{
|
|
63
64
|
type: 'item',
|
|
64
|
-
endIcon: React.createElement(
|
|
65
|
+
endIcon: React.createElement(TableIcon, null),
|
|
65
66
|
onClick: function () {
|
|
66
67
|
setIsOpen(true);
|
|
67
68
|
},
|
|
68
|
-
title: 'View
|
|
69
|
+
title: 'View table',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
type: 'divider',
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
type: 'item',
|
|
76
|
+
endIcon: React.createElement(DownloadCloudIcon, null),
|
|
77
|
+
onClick: function () {
|
|
78
|
+
setIsOpen(true);
|
|
79
|
+
downloadCSV(dataTable, title);
|
|
80
|
+
},
|
|
81
|
+
title: 'Download CSV',
|
|
69
82
|
},
|
|
70
83
|
];
|
|
71
84
|
}
|
|
@@ -89,7 +102,7 @@ export function ChartSummary(props) {
|
|
|
89
102
|
return item;
|
|
90
103
|
});
|
|
91
104
|
return menuItems;
|
|
92
|
-
}, [dataTable, additionalMenuItems, menuProps]);
|
|
105
|
+
}, [dataTable, additionalMenuItems, menuProps, title]);
|
|
93
106
|
return (React.createElement("div", null,
|
|
94
107
|
React.createElement(DescriptionBlock, { label: React.createElement("div", { style: { display: 'flex', justifyContent: 'space-between' } },
|
|
95
108
|
React.createElement(StackLayout, { gutter: 1 },
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { AlertTriangleFilledIcon, AlertDiamondFilledIcon } from '@auth0/quantum-product
|
|
3
|
-
import { Box, RowLayout, StackLayout, Text, useTheme } from '@auth0/quantum-product';
|
|
2
|
+
import { Box, RowLayout, StackLayout, Text, useTheme, AlertTriangleFilledIcon, AlertDiamondFilledIcon, } from '@auth0/quantum-product';
|
|
4
3
|
import StatusDot from './custom-color-status-dot';
|
|
5
4
|
import { format } from 'date-fns';
|
|
6
5
|
import { CustomTooltip as CustomTooltipStyled } from '../styles';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { format } from 'date-fns';
|
|
2
|
+
export var downloadCSV = function (data, filename) {
|
|
3
|
+
if (filename === void 0) { filename = 'chart data'; }
|
|
4
|
+
var mappedData = data.map(function (row) {
|
|
5
|
+
if (row.date) {
|
|
6
|
+
row.date = format(new Date(row.date), 'LLL d p');
|
|
7
|
+
}
|
|
8
|
+
return Object.values(row).map(function (column) { return "\"".concat(column === '–' ? '–' : column, "\""); });
|
|
9
|
+
});
|
|
10
|
+
mappedData.unshift(Object.keys(data[0]));
|
|
11
|
+
var content = '', csvData = '';
|
|
12
|
+
mappedData.forEach(function (d, i) {
|
|
13
|
+
csvData = d.join(',');
|
|
14
|
+
content += i < data.length ? csvData + '\n' : csvData;
|
|
15
|
+
});
|
|
16
|
+
var anchor = document.createElement('a');
|
|
17
|
+
var mimeType = 'text/csv;encoding:utf-8';
|
|
18
|
+
if (navigator['msSaveBlob']) {
|
|
19
|
+
// Internet Explorer 10
|
|
20
|
+
navigator['msSaveBlob'](new Blob([content], {
|
|
21
|
+
type: mimeType,
|
|
22
|
+
}), filename);
|
|
23
|
+
}
|
|
24
|
+
else if (URL && 'download' in anchor) {
|
|
25
|
+
// HTML5
|
|
26
|
+
var href = URL.createObjectURL(new Blob([content], {
|
|
27
|
+
type: mimeType,
|
|
28
|
+
}));
|
|
29
|
+
anchor.href = href;
|
|
30
|
+
anchor.setAttribute('download', filename);
|
|
31
|
+
document.body.appendChild(anchor);
|
|
32
|
+
anchor.click();
|
|
33
|
+
document.body.removeChild(anchor);
|
|
34
|
+
URL.revokeObjectURL(href);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
location.href = "data:application/octet-stream,".concat(encodeURIComponent(content));
|
|
38
|
+
}
|
|
39
|
+
};
|
package/esm/line-chart/index.js
CHANGED
|
@@ -28,13 +28,14 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
28
28
|
import _ from 'lodash';
|
|
29
29
|
import * as React from 'react';
|
|
30
30
|
import { Area, CartesianGrid, ComposedChart, Legend, Line, ReferenceArea, ReferenceLine, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts';
|
|
31
|
-
import { useTheme, Text, DropdownMenu, useDropdownMenuState, Button, StackLayout, Divider, ChevronDownIcon, AlertDiamondIcon, } from '@auth0/quantum-product';
|
|
31
|
+
import { useTheme, Text, DropdownMenu, useDropdownMenuState, Button, StackLayout, Divider, ChevronDownIcon, AlertDiamondIcon, IconButton, TableIcon, } from '@auth0/quantum-product';
|
|
32
32
|
import { getColorScale } from '../theme';
|
|
33
33
|
import CustomActiveDot from './custom-active-dot';
|
|
34
34
|
import CustomTooltip from '../common/custom-tooltip';
|
|
35
35
|
import { ChartCard } from '../chart-card';
|
|
36
36
|
import { tickFormatter } from '../common/chart';
|
|
37
37
|
import { CustomLegend } from '../common/custom-legend';
|
|
38
|
+
import { DataTableChart } from '../chart-summary/data-table-chart';
|
|
38
39
|
export function LineChart(props) {
|
|
39
40
|
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, headerAction = _a.headerAction, additionalMenuItems = _a.additionalMenuItems, thresholds = _a.thresholds, breaches = _a.breaches;
|
|
40
41
|
var theme = useTheme();
|
|
@@ -47,11 +48,15 @@ export function LineChart(props) {
|
|
|
47
48
|
}, {}));
|
|
48
49
|
var _f = __read(React.useState(initialState), 2), lineVisibility = _f[0], setLineVisibility = _f[1];
|
|
49
50
|
var _g = __read(React.useState(thresholds === null || thresholds === void 0 ? void 0 : thresholds[0]), 2), threshold = _g[0], setThreshold = _g[1];
|
|
51
|
+
var _h = __read(React.useState(false), 2), isOpen = _h[0], setIsOpen = _h[1];
|
|
50
52
|
var handleLegendMouseEnter = function (e) {
|
|
51
53
|
if (!lineVisibility[e.dataKey]) {
|
|
52
54
|
setLineVisibility(__assign(__assign({}, lineVisibility), { hover: e.dataKey }));
|
|
53
55
|
}
|
|
54
56
|
};
|
|
57
|
+
var toggleIsOpen = function () {
|
|
58
|
+
setIsOpen(function (prev) { return !prev; });
|
|
59
|
+
};
|
|
55
60
|
var handleLegendMouseLeave = function () {
|
|
56
61
|
setLineVisibility(__assign(__assign({}, lineVisibility), { hover: null }));
|
|
57
62
|
};
|
|
@@ -125,8 +130,12 @@ export function LineChart(props) {
|
|
|
125
130
|
var headerActionWithThresholdDropdown = (React.createElement(StackLayout, { gutter: 1 },
|
|
126
131
|
React.createElement(Button, __assign({}, triggerProps, { startIcon: React.createElement(AlertDiamondIcon, null), endIcon: React.createElement(ChevronDownIcon, null), disabled: !threshold, variant: 'outlined', label: threshold ? threshold.threshold_label : 'No threshold' })),
|
|
127
132
|
React.createElement(DropdownMenu, __assign({}, menuProps, { items: menuItems })),
|
|
128
|
-
|
|
129
|
-
headerAction
|
|
133
|
+
React.createElement(Divider, { orientation: "vertical" }),
|
|
134
|
+
headerAction,
|
|
135
|
+
React.createElement(IconButton, { size: "small", label: "View table", onClick: function () {
|
|
136
|
+
setIsOpen(true);
|
|
137
|
+
} },
|
|
138
|
+
React.createElement(TableIcon, null))));
|
|
130
139
|
return (React.createElement(React.Fragment, null,
|
|
131
140
|
React.createElement(ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText, headerAction: (groups === null || groups === void 0 ? void 0 : groups.length) > 1 ? headerActionWithThresholdDropdown : headerAction, additionalMenuItems: additionalMenuItems },
|
|
132
141
|
React.createElement(ResponsiveContainer, { width: '100%', height: height }, data.length ? (React.createElement(ComposedChart, { data: Object.values(entries), height: height, width: 500, syncId: syncId, margin: {
|
|
@@ -166,5 +175,6 @@ export function LineChart(props) {
|
|
|
166
175
|
height: '100%',
|
|
167
176
|
textAlign: 'center',
|
|
168
177
|
} },
|
|
169
|
-
React.createElement(Text, { variant: "subtitle1" }, "No data")))))
|
|
178
|
+
React.createElement(Text, { variant: "subtitle1" }, "No data"))))),
|
|
179
|
+
data && data[0] && React.createElement(DataTableChart, { title: title, isOpen: isOpen, toggleIsOpen: toggleIsOpen, data: data })));
|
|
170
180
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const downloadCSV: (data: any, filename?: string) => void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.downloadCSV = void 0;
|
|
4
|
+
var date_fns_1 = require("date-fns");
|
|
5
|
+
var downloadCSV = function (data, filename) {
|
|
6
|
+
if (filename === void 0) { filename = 'chart data'; }
|
|
7
|
+
var mappedData = data.map(function (row) {
|
|
8
|
+
if (row.date) {
|
|
9
|
+
row.date = (0, date_fns_1.format)(new Date(row.date), 'LLL d p');
|
|
10
|
+
}
|
|
11
|
+
return Object.values(row).map(function (column) { return "\"".concat(column === '–' ? '–' : column, "\""); });
|
|
12
|
+
});
|
|
13
|
+
mappedData.unshift(Object.keys(data[0]));
|
|
14
|
+
var content = '', csvData = '';
|
|
15
|
+
mappedData.forEach(function (d, i) {
|
|
16
|
+
csvData = d.join(',');
|
|
17
|
+
content += i < data.length ? csvData + '\n' : csvData;
|
|
18
|
+
});
|
|
19
|
+
var anchor = document.createElement('a');
|
|
20
|
+
var mimeType = 'text/csv;encoding:utf-8';
|
|
21
|
+
if (navigator['msSaveBlob']) {
|
|
22
|
+
// Internet Explorer 10
|
|
23
|
+
navigator['msSaveBlob'](new Blob([content], {
|
|
24
|
+
type: mimeType,
|
|
25
|
+
}), filename);
|
|
26
|
+
}
|
|
27
|
+
else if (URL && 'download' in anchor) {
|
|
28
|
+
// HTML5
|
|
29
|
+
var href = URL.createObjectURL(new Blob([content], {
|
|
30
|
+
type: mimeType,
|
|
31
|
+
}));
|
|
32
|
+
anchor.href = href;
|
|
33
|
+
anchor.setAttribute('download', filename);
|
|
34
|
+
document.body.appendChild(anchor);
|
|
35
|
+
anchor.click();
|
|
36
|
+
document.body.removeChild(anchor);
|
|
37
|
+
URL.revokeObjectURL(href);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
location.href = "data:application/octet-stream,".concat(encodeURIComponent(content));
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.downloadCSV = downloadCSV;
|
package/line-chart/index.js
CHANGED
|
@@ -64,6 +64,7 @@ var custom_tooltip_1 = __importDefault(require("../common/custom-tooltip"));
|
|
|
64
64
|
var chart_card_1 = require("../chart-card");
|
|
65
65
|
var chart_1 = require("../common/chart");
|
|
66
66
|
var custom_legend_1 = require("../common/custom-legend");
|
|
67
|
+
var data_table_chart_1 = require("../chart-summary/data-table-chart");
|
|
67
68
|
function LineChart(props) {
|
|
68
69
|
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, headerAction = _a.headerAction, additionalMenuItems = _a.additionalMenuItems, thresholds = _a.thresholds, breaches = _a.breaches;
|
|
69
70
|
var theme = (0, quantum_product_1.useTheme)();
|
|
@@ -76,11 +77,15 @@ function LineChart(props) {
|
|
|
76
77
|
}, {}));
|
|
77
78
|
var _f = __read(React.useState(initialState), 2), lineVisibility = _f[0], setLineVisibility = _f[1];
|
|
78
79
|
var _g = __read(React.useState(thresholds === null || thresholds === void 0 ? void 0 : thresholds[0]), 2), threshold = _g[0], setThreshold = _g[1];
|
|
80
|
+
var _h = __read(React.useState(false), 2), isOpen = _h[0], setIsOpen = _h[1];
|
|
79
81
|
var handleLegendMouseEnter = function (e) {
|
|
80
82
|
if (!lineVisibility[e.dataKey]) {
|
|
81
83
|
setLineVisibility(__assign(__assign({}, lineVisibility), { hover: e.dataKey }));
|
|
82
84
|
}
|
|
83
85
|
};
|
|
86
|
+
var toggleIsOpen = function () {
|
|
87
|
+
setIsOpen(function (prev) { return !prev; });
|
|
88
|
+
};
|
|
84
89
|
var handleLegendMouseLeave = function () {
|
|
85
90
|
setLineVisibility(__assign(__assign({}, lineVisibility), { hover: null }));
|
|
86
91
|
};
|
|
@@ -154,8 +159,12 @@ function LineChart(props) {
|
|
|
154
159
|
var headerActionWithThresholdDropdown = (React.createElement(quantum_product_1.StackLayout, { gutter: 1 },
|
|
155
160
|
React.createElement(quantum_product_1.Button, __assign({}, triggerProps, { startIcon: React.createElement(quantum_product_1.AlertDiamondIcon, null), endIcon: React.createElement(quantum_product_1.ChevronDownIcon, null), disabled: !threshold, variant: 'outlined', label: threshold ? threshold.threshold_label : 'No threshold' })),
|
|
156
161
|
React.createElement(quantum_product_1.DropdownMenu, __assign({}, menuProps, { items: menuItems })),
|
|
157
|
-
|
|
158
|
-
headerAction
|
|
162
|
+
React.createElement(quantum_product_1.Divider, { orientation: "vertical" }),
|
|
163
|
+
headerAction,
|
|
164
|
+
React.createElement(quantum_product_1.IconButton, { size: "small", label: "View table", onClick: function () {
|
|
165
|
+
setIsOpen(true);
|
|
166
|
+
} },
|
|
167
|
+
React.createElement(quantum_product_1.TableIcon, null))));
|
|
159
168
|
return (React.createElement(React.Fragment, null,
|
|
160
169
|
React.createElement(chart_card_1.ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText, headerAction: (groups === null || groups === void 0 ? void 0 : groups.length) > 1 ? headerActionWithThresholdDropdown : headerAction, additionalMenuItems: additionalMenuItems },
|
|
161
170
|
React.createElement(recharts_1.ResponsiveContainer, { width: '100%', height: height }, data.length ? (React.createElement(recharts_1.ComposedChart, { data: Object.values(entries), height: height, width: 500, syncId: syncId, margin: {
|
|
@@ -195,6 +204,7 @@ function LineChart(props) {
|
|
|
195
204
|
height: '100%',
|
|
196
205
|
textAlign: 'center',
|
|
197
206
|
} },
|
|
198
|
-
React.createElement(quantum_product_1.Text, { variant: "subtitle1" }, "No data")))))
|
|
207
|
+
React.createElement(quantum_product_1.Text, { variant: "subtitle1" }, "No data"))))),
|
|
208
|
+
data && data[0] && React.createElement(data_table_chart_1.DataTableChart, { title: title, isOpen: isOpen, toggleIsOpen: toggleIsOpen, data: data })));
|
|
199
209
|
}
|
|
200
210
|
exports.LineChart = LineChart;
|