@auth0/quantum-charts 1.0.3 → 1.0.5

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.
@@ -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 &&
@@ -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.ListIcon, null),
91
+ endIcon: React.createElement(quantum_product_1.TableIcon, null),
91
92
  onClick: function () {
92
93
  setIsOpen(true);
93
94
  },
94
- title: 'View list',
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 },
@@ -51,7 +51,7 @@ var CustomTooltip = function (props) {
51
51
  return (React.createElement(quantum_product_1.StackLayout, { key: index, gutter: 0.5 },
52
52
  React.createElement(custom_color_status_dot_1.default, { key: index, dotColor: x.color || 'grey', label: "".concat(x.name, ":") + ' ' }),
53
53
  React.createElement(quantum_product_1.Text, { color: "text.secondary", alignItems: 'end' }, x.payload[x.dataKey || '']),
54
- x.payload['evaluated_metric'] === x.dataKey &&
54
+ x.payload['evaluated_group'] === x.dataKey &&
55
55
  x.payload['breachedPoint'] !== 'none' &&
56
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 })))));
57
57
  })))));
@@ -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 === '&ndash;' ? '–' : 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, ListIcon, Text, useDropdownMenuState, DropdownMenu, MoreVerticalIcon, } from '@auth0/quantum-product';
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(ListIcon, null),
65
+ endIcon: React.createElement(TableIcon, null),
65
66
  onClick: function () {
66
67
  setIsOpen(true);
67
68
  },
68
- title: 'View list',
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 },
@@ -23,7 +23,7 @@ var CustomTooltip = function (props) {
23
23
  return (React.createElement(StackLayout, { key: index, gutter: 0.5 },
24
24
  React.createElement(StatusDot, { key: index, dotColor: x.color || 'grey', label: "".concat(x.name, ":") + ' ' }),
25
25
  React.createElement(Text, { color: "text.secondary", alignItems: 'end' }, x.payload[x.dataKey || '']),
26
- x.payload['evaluated_metric'] === x.dataKey &&
26
+ x.payload['evaluated_group'] === x.dataKey &&
27
27
  x.payload['breachedPoint'] !== 'none' &&
28
28
  (x.payload['breachedPoint'] === 'alert' ? (React.createElement(AlertDiamondFilledIcon, { color: theme.tokens.color_fg_state_danger })) : (React.createElement(AlertTriangleFilledIcon, { color: theme.tokens.color_fg_state_caution })))));
29
29
  })))));
@@ -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 === '&ndash;' ? '–' : 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
+ };
@@ -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
  };
@@ -87,19 +92,20 @@ export function LineChart(props) {
87
92
  _a[entry.group] = entry[leftAxisDataKey],
88
93
  _a);
89
94
  }
90
- if ((threshold === null || threshold === void 0 ? void 0 : threshold.evaluated_metric) === entry.group) {
95
+ if (threshold && threshold.evaluated_metric === entry.evaluated_metric) {
91
96
  var _c = getThresholdData(threshold, entry), ewma_hidden = _c.ewma_hidden, alertThreshold_hidden = _c.alertThreshold_hidden, warnBuffer_hidden = _c.warnBuffer_hidden, warnThreshold_hidden = _c.warnThreshold_hidden;
92
97
  entries[entrytKey].thresholdControl = true;
93
98
  entries[entrytKey].breachedPoint = entry.breachedPoint;
94
99
  // _hidden suffix is used to hide a dataKey from the tooltips and legend
95
- entries[entrytKey].ewma_hidden = ewma_hidden;
100
+ entries[entrytKey].ewma_hidden = Math.max(0, ewma_hidden);
96
101
  entries[entrytKey].alertThreshold_hidden = alertThreshold_hidden;
97
102
  entries[entrytKey].warnThreshold_hidden = warnThreshold_hidden;
98
103
  if (threshold.threshold_trigger === 'BELOW') {
99
- entries[entrytKey].warnBuffer_hidden = warnBuffer_hidden;
104
+ entries[entrytKey].warnBuffer_hidden = Math.max(0, warnBuffer_hidden);
100
105
  entries[entrytKey].warnThreshold_hidden = 0;
101
106
  }
102
107
  entries[entrytKey].evaluated_metric = threshold.evaluated_metric;
108
+ entries[entrytKey].evaluated_group = entry.group;
103
109
  }
104
110
  return _b = {},
105
111
  _b[bottomAxisDataKey] = entry[bottomAxisDataKey],
@@ -125,8 +131,12 @@ export function LineChart(props) {
125
131
  var headerActionWithThresholdDropdown = (React.createElement(StackLayout, { gutter: 1 },
126
132
  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
133
  React.createElement(DropdownMenu, __assign({}, menuProps, { items: menuItems })),
128
- headerAction && React.createElement(Divider, { orientation: "vertical" }),
129
- headerAction));
134
+ React.createElement(Divider, { orientation: "vertical" }),
135
+ headerAction,
136
+ React.createElement(IconButton, { size: "small", label: "View table", onClick: function () {
137
+ setIsOpen(true);
138
+ } },
139
+ React.createElement(TableIcon, null))));
130
140
  return (React.createElement(React.Fragment, null,
131
141
  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
142
  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 +176,6 @@ export function LineChart(props) {
166
176
  height: '100%',
167
177
  textAlign: 'center',
168
178
  } },
169
- React.createElement(Text, { variant: "subtitle1" }, "No data")))))));
179
+ React.createElement(Text, { variant: "subtitle1" }, "No data"))))),
180
+ data && data[0] && React.createElement(DataTableChart, { title: title, isOpen: isOpen, toggleIsOpen: toggleIsOpen, data: data })));
170
181
  }
@@ -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 === '&ndash;' ? '–' : 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;
@@ -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
  };
@@ -116,19 +121,20 @@ function LineChart(props) {
116
121
  _a[entry.group] = entry[leftAxisDataKey],
117
122
  _a);
118
123
  }
119
- if ((threshold === null || threshold === void 0 ? void 0 : threshold.evaluated_metric) === entry.group) {
124
+ if (threshold && threshold.evaluated_metric === entry.evaluated_metric) {
120
125
  var _c = getThresholdData(threshold, entry), ewma_hidden = _c.ewma_hidden, alertThreshold_hidden = _c.alertThreshold_hidden, warnBuffer_hidden = _c.warnBuffer_hidden, warnThreshold_hidden = _c.warnThreshold_hidden;
121
126
  entries[entrytKey].thresholdControl = true;
122
127
  entries[entrytKey].breachedPoint = entry.breachedPoint;
123
128
  // _hidden suffix is used to hide a dataKey from the tooltips and legend
124
- entries[entrytKey].ewma_hidden = ewma_hidden;
129
+ entries[entrytKey].ewma_hidden = Math.max(0, ewma_hidden);
125
130
  entries[entrytKey].alertThreshold_hidden = alertThreshold_hidden;
126
131
  entries[entrytKey].warnThreshold_hidden = warnThreshold_hidden;
127
132
  if (threshold.threshold_trigger === 'BELOW') {
128
- entries[entrytKey].warnBuffer_hidden = warnBuffer_hidden;
133
+ entries[entrytKey].warnBuffer_hidden = Math.max(0, warnBuffer_hidden);
129
134
  entries[entrytKey].warnThreshold_hidden = 0;
130
135
  }
131
136
  entries[entrytKey].evaluated_metric = threshold.evaluated_metric;
137
+ entries[entrytKey].evaluated_group = entry.group;
132
138
  }
133
139
  return _b = {},
134
140
  _b[bottomAxisDataKey] = entry[bottomAxisDataKey],
@@ -154,8 +160,12 @@ function LineChart(props) {
154
160
  var headerActionWithThresholdDropdown = (React.createElement(quantum_product_1.StackLayout, { gutter: 1 },
155
161
  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
162
  React.createElement(quantum_product_1.DropdownMenu, __assign({}, menuProps, { items: menuItems })),
157
- headerAction && React.createElement(quantum_product_1.Divider, { orientation: "vertical" }),
158
- headerAction));
163
+ React.createElement(quantum_product_1.Divider, { orientation: "vertical" }),
164
+ headerAction,
165
+ React.createElement(quantum_product_1.IconButton, { size: "small", label: "View table", onClick: function () {
166
+ setIsOpen(true);
167
+ } },
168
+ React.createElement(quantum_product_1.TableIcon, null))));
159
169
  return (React.createElement(React.Fragment, null,
160
170
  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
171
  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 +205,7 @@ function LineChart(props) {
195
205
  height: '100%',
196
206
  textAlign: 'center',
197
207
  } },
198
- React.createElement(quantum_product_1.Text, { variant: "subtitle1" }, "No data")))))));
208
+ React.createElement(quantum_product_1.Text, { variant: "subtitle1" }, "No data"))))),
209
+ data && data[0] && React.createElement(data_table_chart_1.DataTableChart, { title: title, isOpen: isOpen, toggleIsOpen: toggleIsOpen, data: data })));
199
210
  }
200
211
  exports.LineChart = LineChart;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auth0/quantum-charts",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "sideEffects": false,
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",