@auth0/quantum-charts 0.3.2 → 0.3.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.
@@ -64,7 +64,7 @@ var chart_card_1 = require("../chart-card");
64
64
  var chart_1 = require("../common/chart");
65
65
  var custom_legend_1 = require("../common/custom-legend");
66
66
  function BarChart(props) {
67
- 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;
67
+ 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, additionalMenuItems = _a.additionalMenuItems;
68
68
  var theme = (0, quantum_product_1.useTheme)();
69
69
  // Function to know how many bars we need based of how much different group values are.
70
70
  var groups = lodash_1.default.uniqBy(data, 'group').map(function (item) { return item.group; });
@@ -105,7 +105,7 @@ function BarChart(props) {
105
105
  _b[entry.group] = entry[leftAxisDataKey],
106
106
  _b;
107
107
  });
108
- return (React.createElement(chart_card_1.ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText },
108
+ return (React.createElement(chart_card_1.ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText, additionalMenuItems: additionalMenuItems },
109
109
  React.createElement(recharts_1.ResponsiveContainer, { width: "100%", height: height }, data.length ? (React.createElement(recharts_1.BarChart, { width: 500, layout: layout === 'horizontal' ? 'vertical' : 'horizontal', height: height, data: Object.values(entries), margin: {
110
110
  top: 24,
111
111
  right: 10,
@@ -28,9 +28,9 @@ var quantum_product_1 = require("@auth0/quantum-product");
28
28
  var React = __importStar(require("react"));
29
29
  var chart_summary_1 = require("../chart-summary");
30
30
  function ChartCard(props) {
31
- var children = props.children, title = props.title, value = props.value, dataTable = props.dataTable, helperText = props.helperText, label = props.label, height = props.height, headerAction = props.headerAction;
31
+ var children = props.children, title = props.title, value = props.value, dataTable = props.dataTable, helperText = props.helperText, label = props.label, height = props.height, headerAction = props.headerAction, additionalMenuItems = props.additionalMenuItems;
32
32
  return (React.createElement(quantum_product_1.Card, { sx: { height: height, padding: 3 } },
33
- React.createElement(chart_summary_1.ChartSummary, { title: title, value: value, dataTable: dataTable, helperText: helperText, label: label, headerAction: headerAction }),
33
+ React.createElement(chart_summary_1.ChartSummary, { title: title, value: value, dataTable: dataTable, helperText: helperText, label: label, headerAction: headerAction, additionalMenuItems: additionalMenuItems }),
34
34
  children));
35
35
  }
36
36
  exports.ChartCard = ChartCard;
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import { DropdownMenuListItemValue } from '@auth0/quantum-product';
2
3
  export interface IChartSummaryProps {
3
4
  title?: string;
4
5
  value?: string | number;
@@ -7,5 +8,6 @@ export interface IChartSummaryProps {
7
8
  helperText?: React.ReactNode;
8
9
  dataTable?: any;
9
10
  headerAction?: React.ReactElement;
11
+ additionalMenuItems?: DropdownMenuListItemValue[];
10
12
  }
11
13
  export declare function ChartSummary(props: IChartSummaryProps): React.JSX.Element;
@@ -3,6 +3,17 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
3
3
  if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
4
  return cooked;
5
5
  };
6
+ var __assign = (this && this.__assign) || function () {
7
+ __assign = Object.assign || function(t) {
8
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
9
+ s = arguments[i];
10
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11
+ t[p] = s[p];
12
+ }
13
+ return t;
14
+ };
15
+ return __assign.apply(this, arguments);
16
+ };
6
17
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
18
  if (k2 === undefined) k2 = k;
8
19
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -42,6 +53,15 @@ var __read = (this && this.__read) || function (o, n) {
42
53
  }
43
54
  return ar;
44
55
  };
56
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
57
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
58
+ if (ar || !(i in from)) {
59
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
60
+ ar[i] = from[i];
61
+ }
62
+ }
63
+ return to.concat(ar || Array.prototype.slice.call(from));
64
+ };
45
65
  Object.defineProperty(exports, "__esModule", { value: true });
46
66
  exports.ChartSummary = void 0;
47
67
  var React = __importStar(require("react"));
@@ -55,11 +75,47 @@ var Aggregate = (0, quantum_product_1.styled)('h4')(templateObject_1 || (templat
55
75
  return theme.typography.h4.fontSize;
56
76
  });
57
77
  function ChartSummary(props) {
58
- var title = props.title, value = props.value, helperText = props.helperText, label = props.label, dataTable = props.dataTable, headerAction = props.headerAction;
78
+ var title = props.title, value = props.value, helperText = props.helperText, label = props.label, dataTable = props.dataTable, headerAction = props.headerAction, additionalMenuItems = props.additionalMenuItems;
59
79
  var _a = __read(React.useState(false), 2), isOpen = _a[0], setIsOpen = _a[1];
80
+ var _b = (0, quantum_product_1.useDropdownMenuState)({ baseId: 'chart-actions-menu' }), triggerProps = _b.triggerProps, menuProps = _b.menuProps;
60
81
  var toggleIsOpen = function () {
61
82
  setIsOpen(function (prev) { return !prev; });
62
83
  };
84
+ var menuItems = React.useMemo(function () {
85
+ var menuItems = [];
86
+ if (dataTable && dataTable[0]) {
87
+ menuItems = [
88
+ {
89
+ type: 'item',
90
+ endIcon: React.createElement(quantum_product_1.ListIcon, null),
91
+ onClick: function () {
92
+ setIsOpen(true);
93
+ },
94
+ title: 'View list',
95
+ },
96
+ ];
97
+ }
98
+ if (additionalMenuItems) {
99
+ if (menuItems.length > 0)
100
+ menuItems.unshift({ type: 'divider' });
101
+ menuItems = __spreadArray(__spreadArray([], __read(additionalMenuItems), false), __read(menuItems), false);
102
+ }
103
+ var handleClick = function (cb) {
104
+ return function (event) {
105
+ cb(event);
106
+ if (menuProps.onClose) {
107
+ menuProps.onClose(event, 'itemSelect');
108
+ }
109
+ };
110
+ };
111
+ menuItems = menuItems.map(function (item) {
112
+ if (item.type === 'item' && item.onClick) {
113
+ item.onClick = handleClick(item.onClick);
114
+ }
115
+ return item;
116
+ });
117
+ return menuItems;
118
+ }, [dataTable, additionalMenuItems, menuProps]);
63
119
  return (React.createElement("div", null,
64
120
  React.createElement(quantum_product_1.DescriptionBlock, { label: React.createElement("div", { style: { display: 'flex', justifyContent: 'space-between' } },
65
121
  React.createElement(quantum_product_1.StackLayout, { gutter: 1 },
@@ -74,10 +130,11 @@ function ChartSummary(props) {
74
130
  } },
75
131
  React.createElement(quantum_product_1.HelpCircleIcon, { size: "16" })))))),
76
132
  React.createElement(quantum_product_1.StackLayout, { gutter: 1 },
77
- dataTable && dataTable[0] && (React.createElement(quantum_product_1.StackLayoutItem, null,
78
- React.createElement(quantum_product_1.IconButton, { label: "List button", onClick: function () { return setIsOpen(true); } },
79
- React.createElement(quantum_product_1.ListIcon, null)))),
80
- headerAction && (React.createElement(quantum_product_1.StackLayoutItem, { sx: { justifyContent: 'flex-end', display: 'flex', width: '100', flex: 1 } }, headerAction)))), labelTypographyProps: { variant: 'subtitle1' }, description: React.createElement(quantum_product_1.StackLayout, { gutter: 1 },
133
+ headerAction && (React.createElement(quantum_product_1.StackLayoutItem, { sx: { justifyContent: 'flex-end', display: 'flex', width: '100', flex: 1 } }, headerAction)),
134
+ menuItems.length > 0 && (React.createElement(React.Fragment, null,
135
+ React.createElement(quantum_product_1.IconButton, __assign({ size: "small" }, triggerProps, { label: "More actions" }),
136
+ React.createElement(quantum_product_1.MoreVerticalIcon, null)),
137
+ React.createElement(quantum_product_1.DropdownMenu, __assign({}, menuProps, { items: menuItems })))))), labelTypographyProps: { variant: 'subtitle1' }, description: React.createElement(quantum_product_1.StackLayout, { gutter: 1 },
81
138
  React.createElement(Aggregate, null, value),
82
139
  label) }),
83
140
  dataTable && dataTable[0] && (React.createElement(data_table_chart_1.DataTableChart, { title: title, isOpen: isOpen, toggleIsOpen: toggleIsOpen, data: dataTable }))));
package/common/chart.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { TooltipProps } from 'recharts';
3
3
  import { IChartCardProps } from '../chart-card';
4
+ import { DropdownMenuListItemValue } from '@auth0/quantum-product';
4
5
  export type ScaleType = 'date' | 'datetime' | 'label' | 'number';
5
6
  export interface ICustomTooltipProps extends TooltipProps<number, string> {
6
7
  scaleType?: 'datetime' | 'date';
@@ -26,6 +27,8 @@ export interface IBaseChartProps<DataType = unknown> extends IChartCardProps {
26
27
  leftAxis: IAxisOptions<DataType>;
27
28
  legend?: ILegendOptions;
28
29
  color?: 'categorical' | 'sequential';
30
+ additionalMenuItems?: DropdownMenuListItemValue[];
31
+ headerAction?: React.ReactElement;
29
32
  }
30
33
  export type IDonutChartDataPoint<DataType = unknown> = {
31
34
  name: string;
@@ -33,10 +33,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
33
33
  __setModuleDefault(result, mod);
34
34
  return result;
35
35
  };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
36
39
  Object.defineProperty(exports, "__esModule", { value: true });
37
40
  exports.CustomLegend = void 0;
38
41
  var quantum_product_1 = require("@auth0/quantum-product");
39
42
  var React = __importStar(require("react"));
43
+ var custom_threshold_legend_1 = __importDefault(require("../line-chart/custom-threshold-legend"));
40
44
  var Root = (0, quantum_product_1.styled)(quantum_product_1.StackLayout)({
41
45
  justifyContent: 'center',
42
46
  });
@@ -57,9 +61,12 @@ var LegendIcon = (0, quantum_product_1.styled)('div')(function (_a) {
57
61
  })));
58
62
  });
59
63
  var CustomLegend = function (props) {
60
- var payload = props.payload, selectData = props.selectData, handleLegendMouseEnter = props.handleLegendMouseEnter, handleLegendMouseLeave = props.handleLegendMouseLeave, dataVisibility = props.dataVisibility;
61
- return (React.createElement(Root, { gutter: 1 }, payload.map(function (entry, index) { return (React.createElement(quantum_product_1.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); } },
62
- React.createElement(LegendIcon, { ownerState: { isHide: dataVisibility[entry.dataKey], color: entry.color } }),
63
- React.createElement(quantum_product_1.Text, { variant: "body2" }, entry.value))); })));
64
+ var payload = props.payload, selectData = props.selectData, handleLegendMouseEnter = props.handleLegendMouseEnter, handleLegendMouseLeave = props.handleLegendMouseLeave, dataVisibility = props.dataVisibility, alertThresholdValue = props.alertThresholdValue, warnThresholdValue = props.warnThresholdValue;
65
+ return (React.createElement(Root, { gutter: 1 },
66
+ React.createElement(quantum_product_1.StackLayout, { sx: { padding: '4px 8px', cursor: 'pointer' }, gutter: 1 },
67
+ payload.map(function (entry, index) { return (React.createElement(quantum_product_1.StackLayout, { key: index, sx: { padding: '4px 8px', cursor: 'pointer' }, gutter: 1, onClick: function () { return selectData(entry); }, onMouseEnter: function () { return handleLegendMouseEnter(entry); }, onMouseLeave: function () { return handleLegendMouseLeave(entry); } },
68
+ React.createElement(LegendIcon, { ownerState: { isHide: dataVisibility[entry.dataKey], color: entry.color } }),
69
+ React.createElement(quantum_product_1.Text, { variant: "body2" }, entry.value))); }),
70
+ (warnThresholdValue || alertThresholdValue) && React.createElement(custom_threshold_legend_1.default, null))));
64
71
  };
65
72
  exports.CustomLegend = CustomLegend;
@@ -71,11 +71,11 @@ var ResponsiveChartCard = (0, quantum_product_1.styled)(quantum_product_1.StackL
71
71
  })));
72
72
  });
73
73
  function DonutChart(props) {
74
- 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;
74
+ 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, additionalMenuItems = props.additionalMenuItems;
75
75
  var _d = __read(React.useState(undefined), 2), activeIndex = _d[0], setActiveIndex = _d[1];
76
76
  var theme = (0, quantum_product_1.useTheme)();
77
77
  var BASE_COLORS = (0, theme_1.getColorScale)(theme)[color]['base'];
78
- return (React.createElement(chart_card_1.ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText, height: height },
78
+ return (React.createElement(chart_card_1.ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText, height: height, additionalMenuItems: additionalMenuItems },
79
79
  React.createElement(ResponsiveChartCard, { ownerState: { layout: layout } },
80
80
  React.createElement(quantum_product_1.StackLayoutItem, { sx: {
81
81
  height: '150px',
@@ -35,7 +35,7 @@ import { ChartCard } from '../chart-card';
35
35
  import { tickFormatter } from '../common/chart';
36
36
  import { CustomLegend } from '../common/custom-legend';
37
37
  export function BarChart(props) {
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;
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, additionalMenuItems = _a.additionalMenuItems;
39
39
  var theme = useTheme();
40
40
  // Function to know how many bars we need based of how much different group values are.
41
41
  var groups = _.uniqBy(data, 'group').map(function (item) { return item.group; });
@@ -76,7 +76,7 @@ export function BarChart(props) {
76
76
  _b[entry.group] = entry[leftAxisDataKey],
77
77
  _b;
78
78
  });
79
- return (React.createElement(ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText },
79
+ return (React.createElement(ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText, additionalMenuItems: additionalMenuItems },
80
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: {
81
81
  top: 24,
82
82
  right: 10,
@@ -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, height = props.height, headerAction = props.headerAction;
5
+ var children = props.children, title = props.title, value = props.value, dataTable = props.dataTable, helperText = props.helperText, label = props.label, height = props.height, headerAction = props.headerAction, additionalMenuItems = props.additionalMenuItems;
6
6
  return (React.createElement(Card, { sx: { height: height, padding: 3 } },
7
- React.createElement(ChartSummary, { title: title, value: value, dataTable: dataTable, helperText: helperText, label: label, headerAction: headerAction }),
7
+ React.createElement(ChartSummary, { title: title, value: value, dataTable: dataTable, helperText: helperText, label: label, headerAction: headerAction, additionalMenuItems: additionalMenuItems }),
8
8
  children));
9
9
  }
@@ -2,6 +2,17 @@ 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
+ var __assign = (this && this.__assign) || function () {
6
+ __assign = Object.assign || function(t) {
7
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8
+ s = arguments[i];
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
+ t[p] = s[p];
11
+ }
12
+ return t;
13
+ };
14
+ return __assign.apply(this, arguments);
15
+ };
5
16
  var __read = (this && this.__read) || function (o, n) {
6
17
  var m = typeof Symbol === "function" && o[Symbol.iterator];
7
18
  if (!m) return o;
@@ -18,8 +29,17 @@ var __read = (this && this.__read) || function (o, n) {
18
29
  }
19
30
  return ar;
20
31
  };
32
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
33
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
34
+ if (ar || !(i in from)) {
35
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
36
+ ar[i] = from[i];
37
+ }
38
+ }
39
+ return to.concat(ar || Array.prototype.slice.call(from));
40
+ };
21
41
  import * as React from 'react';
22
- import { Box, DescriptionBlock, StackLayout, StackLayoutItem, Tooltip, HelpCircleIcon, styled, IconButton, ListIcon, Text, } from '@auth0/quantum-product';
42
+ import { Box, DescriptionBlock, StackLayout, StackLayoutItem, Tooltip, HelpCircleIcon, styled, IconButton, ListIcon, Text, useDropdownMenuState, DropdownMenu, MoreVerticalIcon, } from '@auth0/quantum-product';
23
43
  import { DataTableChart } from './data-table-chart';
24
44
  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) {
25
45
  var theme = _a.theme;
@@ -29,11 +49,47 @@ var Aggregate = styled('h4')(templateObject_1 || (templateObject_1 = __makeTempl
29
49
  return theme.typography.h4.fontSize;
30
50
  });
31
51
  export function ChartSummary(props) {
32
- var title = props.title, value = props.value, helperText = props.helperText, label = props.label, dataTable = props.dataTable, headerAction = props.headerAction;
52
+ var title = props.title, value = props.value, helperText = props.helperText, label = props.label, dataTable = props.dataTable, headerAction = props.headerAction, additionalMenuItems = props.additionalMenuItems;
33
53
  var _a = __read(React.useState(false), 2), isOpen = _a[0], setIsOpen = _a[1];
54
+ var _b = useDropdownMenuState({ baseId: 'chart-actions-menu' }), triggerProps = _b.triggerProps, menuProps = _b.menuProps;
34
55
  var toggleIsOpen = function () {
35
56
  setIsOpen(function (prev) { return !prev; });
36
57
  };
58
+ var menuItems = React.useMemo(function () {
59
+ var menuItems = [];
60
+ if (dataTable && dataTable[0]) {
61
+ menuItems = [
62
+ {
63
+ type: 'item',
64
+ endIcon: React.createElement(ListIcon, null),
65
+ onClick: function () {
66
+ setIsOpen(true);
67
+ },
68
+ title: 'View list',
69
+ },
70
+ ];
71
+ }
72
+ if (additionalMenuItems) {
73
+ if (menuItems.length > 0)
74
+ menuItems.unshift({ type: 'divider' });
75
+ menuItems = __spreadArray(__spreadArray([], __read(additionalMenuItems), false), __read(menuItems), false);
76
+ }
77
+ var handleClick = function (cb) {
78
+ return function (event) {
79
+ cb(event);
80
+ if (menuProps.onClose) {
81
+ menuProps.onClose(event, 'itemSelect');
82
+ }
83
+ };
84
+ };
85
+ menuItems = menuItems.map(function (item) {
86
+ if (item.type === 'item' && item.onClick) {
87
+ item.onClick = handleClick(item.onClick);
88
+ }
89
+ return item;
90
+ });
91
+ return menuItems;
92
+ }, [dataTable, additionalMenuItems, menuProps]);
37
93
  return (React.createElement("div", null,
38
94
  React.createElement(DescriptionBlock, { label: React.createElement("div", { style: { display: 'flex', justifyContent: 'space-between' } },
39
95
  React.createElement(StackLayout, { gutter: 1 },
@@ -48,10 +104,11 @@ export function ChartSummary(props) {
48
104
  } },
49
105
  React.createElement(HelpCircleIcon, { size: "16" })))))),
50
106
  React.createElement(StackLayout, { gutter: 1 },
51
- dataTable && dataTable[0] && (React.createElement(StackLayoutItem, null,
52
- React.createElement(IconButton, { label: "List button", onClick: function () { return setIsOpen(true); } },
53
- React.createElement(ListIcon, null)))),
54
- headerAction && (React.createElement(StackLayoutItem, { sx: { justifyContent: 'flex-end', display: 'flex', width: '100', flex: 1 } }, headerAction)))), labelTypographyProps: { variant: 'subtitle1' }, description: React.createElement(StackLayout, { gutter: 1 },
107
+ headerAction && (React.createElement(StackLayoutItem, { sx: { justifyContent: 'flex-end', display: 'flex', width: '100', flex: 1 } }, headerAction)),
108
+ menuItems.length > 0 && (React.createElement(React.Fragment, null,
109
+ React.createElement(IconButton, __assign({ size: "small" }, triggerProps, { label: "More actions" }),
110
+ React.createElement(MoreVerticalIcon, null)),
111
+ React.createElement(DropdownMenu, __assign({}, menuProps, { items: menuItems })))))), labelTypographyProps: { variant: 'subtitle1' }, description: React.createElement(StackLayout, { gutter: 1 },
55
112
  React.createElement(Aggregate, null, value),
56
113
  label) }),
57
114
  dataTable && dataTable[0] && (React.createElement(DataTableChart, { title: title, isOpen: isOpen, toggleIsOpen: toggleIsOpen, data: dataTable }))));
@@ -11,6 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { StackLayout, Text, styled } from '@auth0/quantum-product';
13
13
  import * as React from 'react';
14
+ import CustomThresholdLegend from '../line-chart/custom-threshold-legend';
14
15
  var Root = styled(StackLayout)({
15
16
  justifyContent: 'center',
16
17
  });
@@ -31,8 +32,11 @@ var LegendIcon = styled('div')(function (_a) {
31
32
  })));
32
33
  });
33
34
  export var CustomLegend = function (props) {
34
- var payload = props.payload, selectData = props.selectData, handleLegendMouseEnter = props.handleLegendMouseEnter, handleLegendMouseLeave = props.handleLegendMouseLeave, dataVisibility = props.dataVisibility;
35
- 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); } },
36
- React.createElement(LegendIcon, { ownerState: { isHide: dataVisibility[entry.dataKey], color: entry.color } }),
37
- React.createElement(Text, { variant: "body2" }, entry.value))); })));
35
+ var payload = props.payload, selectData = props.selectData, handleLegendMouseEnter = props.handleLegendMouseEnter, handleLegendMouseLeave = props.handleLegendMouseLeave, dataVisibility = props.dataVisibility, alertThresholdValue = props.alertThresholdValue, warnThresholdValue = props.warnThresholdValue;
36
+ return (React.createElement(Root, { gutter: 1 },
37
+ React.createElement(StackLayout, { sx: { padding: '4px 8px', cursor: 'pointer' }, gutter: 1 },
38
+ payload.map(function (entry, index) { return (React.createElement(StackLayout, { key: index, sx: { padding: '4px 8px', cursor: 'pointer' }, gutter: 1, onClick: function () { return selectData(entry); }, onMouseEnter: function () { return handleLegendMouseEnter(entry); }, onMouseLeave: function () { return handleLegendMouseLeave(entry); } },
39
+ React.createElement(LegendIcon, { ownerState: { isHide: dataVisibility[entry.dataKey], color: entry.color } }),
40
+ React.createElement(Text, { variant: "body2" }, entry.value))); }),
41
+ (warnThresholdValue || alertThresholdValue) && React.createElement(CustomThresholdLegend, null))));
38
42
  };
@@ -42,11 +42,11 @@ var ResponsiveChartCard = styled(StackLayout)(function (_a) {
42
42
  })));
43
43
  });
44
44
  export function DonutChart(props) {
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;
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, additionalMenuItems = props.additionalMenuItems;
46
46
  var _d = __read(React.useState(undefined), 2), activeIndex = _d[0], setActiveIndex = _d[1];
47
47
  var theme = useTheme();
48
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 },
49
+ return (React.createElement(ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText, height: height, additionalMenuItems: additionalMenuItems },
50
50
  React.createElement(ResponsiveChartCard, { ownerState: { layout: layout } },
51
51
  React.createElement(StackLayoutItem, { sx: {
52
52
  height: '150px',
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ export var CustomThresholdLabel = function (_a) {
3
+ var label = _a.label, thresholdType = _a.thresholdType, theme = _a.theme, viewBox = _a.viewBox;
4
+ return (React.createElement("g", { transform: "translate(".concat(viewBox.width - 30, ",-10)") },
5
+ React.createElement("rect", { x: viewBox.x, y: viewBox.y, width: 38, height: 20, fill: thresholdType === 'alert' ? theme.tokens.color_bg_state_danger : theme.tokens.color_bg_state_caution, rx: "4" }),
6
+ React.createElement("text", { x: viewBox.x, y: viewBox.y, fill: thresholdType === 'alert'
7
+ ? theme.tokens.color_global_functional_static_neutral_white
8
+ : theme.tokens.color_global_functional_static_neutral_black, textAnchor: "middle", dominantBaseline: "middle", dy: 11, dx: 19, fontWeight: 500 }, label)));
9
+ };
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ import { Text } from '@auth0/quantum-product';
3
+ var CustomThresholdLegend = function () {
4
+ return (React.createElement(React.Fragment, null,
5
+ React.createElement("svg", { width: "14", height: "2", viewBox: "0 0 14 2", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
6
+ React.createElement("rect", { width: "6", height: "2", rx: "1", fill: "#191919" }),
7
+ React.createElement("rect", { x: "8", width: "6", height: "2", rx: "1", fill: "#191919" })),
8
+ React.createElement(Text, { variant: "body2" }, "Threshold")));
9
+ };
10
+ export default CustomThresholdLegend;
@@ -27,16 +27,17 @@ var __read = (this && this.__read) || function (o, n) {
27
27
  };
28
28
  import _ from 'lodash';
29
29
  import * as React from 'react';
30
- import { CartesianGrid, Legend, Line, LineChart as RechartsLineChart, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts';
30
+ import { CartesianGrid, Label, Legend, Line, LineChart as RechartsLineChart, ReferenceLine, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts';
31
31
  import { useTheme, Text } 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
+ import { CustomThresholdLabel } from './custom-threshold-label';
35
36
  import { ChartCard } from '../chart-card';
36
37
  import { tickFormatter } from '../common/chart';
37
38
  import { CustomLegend } from '../common/custom-legend';
38
39
  export function LineChart(props) {
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, headerAction = _a.headerAction;
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, alertThreshold = _a.alertThreshold, warnThreshold = _a.warnThreshold;
40
41
  var theme = useTheme();
41
42
  // Function to know how many lines we need based of how much different group values are.
42
43
  var groups = _.uniqBy(data, 'group').map(function (item) { return item.group; });
@@ -77,7 +78,7 @@ export function LineChart(props) {
77
78
  _b[entry.group] = entry[leftAxisDataKey],
78
79
  _b;
79
80
  });
80
- return (React.createElement(ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText, headerAction: headerAction },
81
+ return (React.createElement(ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText, headerAction: headerAction, additionalMenuItems: additionalMenuItems },
81
82
  React.createElement(ResponsiveContainer, { width: '100%', height: height }, data.length ? (React.createElement(RechartsLineChart, { data: Object.values(entries), height: height, width: 500, syncId: syncId, margin: {
82
83
  top: 24,
83
84
  right: 10,
@@ -93,7 +94,9 @@ export function LineChart(props) {
93
94
  return (React.createElement(Line, { key: group, dataKey: group, name: group, strokeWidth: 3, hide: lineVisibility[group] === true, stroke: lineVisibility.hover === group || !lineVisibility.hover
94
95
  ? getColorScale(theme)[color]['base'][index]
95
96
  : getColorScale(theme)[color]['muted'][index], dot: false, activeDot: CustomActiveDot() }));
96
- }))) : (React.createElement("div", { style: {
97
+ }),
98
+ alertThreshold && (React.createElement(ReferenceLine, { y: alertThreshold.value, stroke: theme.tokens.color_bg_state_danger, strokeDasharray: "8", strokeWidth: "2", label: React.createElement(Label, { value: alertThreshold.value, content: React.createElement(CustomThresholdLabel, { viewBox: true, label: alertThreshold.label, thresholdType: 'alert', theme: theme }) }) })),
99
+ warnThreshold && (React.createElement(ReferenceLine, { y: warnThreshold.value, stroke: theme.tokens.color_bg_state_caution, strokeDasharray: "8", strokeWidth: "2", label: React.createElement(Label, { value: warnThreshold.value, content: React.createElement(CustomThresholdLabel, { viewBox: true, label: warnThreshold.label, thresholdType: 'warn', theme: theme }) }) })))) : (React.createElement("div", { style: {
97
100
  display: 'grid',
98
101
  placeItems: 'center',
99
102
  height: '100%',
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ export declare const CustomThresholdLabel: ({ label, thresholdType, theme, viewBox }: {
3
+ label: any;
4
+ thresholdType: any;
5
+ theme: any;
6
+ viewBox: any;
7
+ }) => React.JSX.Element;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.CustomThresholdLabel = void 0;
27
+ var React = __importStar(require("react"));
28
+ var CustomThresholdLabel = function (_a) {
29
+ var label = _a.label, thresholdType = _a.thresholdType, theme = _a.theme, viewBox = _a.viewBox;
30
+ return (React.createElement("g", { transform: "translate(".concat(viewBox.width - 30, ",-10)") },
31
+ React.createElement("rect", { x: viewBox.x, y: viewBox.y, width: 38, height: 20, fill: thresholdType === 'alert' ? theme.tokens.color_bg_state_danger : theme.tokens.color_bg_state_caution, rx: "4" }),
32
+ React.createElement("text", { x: viewBox.x, y: viewBox.y, fill: thresholdType === 'alert'
33
+ ? theme.tokens.color_global_functional_static_neutral_white
34
+ : theme.tokens.color_global_functional_static_neutral_black, textAnchor: "middle", dominantBaseline: "middle", dy: 11, dx: 19, fontWeight: 500 }, label)));
35
+ };
36
+ exports.CustomThresholdLabel = CustomThresholdLabel;
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ declare const CustomThresholdLegend: () => React.JSX.Element;
3
+ export default CustomThresholdLegend;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ var React = __importStar(require("react"));
27
+ var quantum_product_1 = require("@auth0/quantum-product");
28
+ var CustomThresholdLegend = function () {
29
+ return (React.createElement(React.Fragment, null,
30
+ React.createElement("svg", { width: "14", height: "2", viewBox: "0 0 14 2", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
31
+ React.createElement("rect", { width: "6", height: "2", rx: "1", fill: "#191919" }),
32
+ React.createElement("rect", { x: "8", width: "6", height: "2", rx: "1", fill: "#191919" })),
33
+ React.createElement(quantum_product_1.Text, { variant: "body2" }, "Threshold")));
34
+ };
35
+ exports.default = CustomThresholdLegend;
@@ -2,5 +2,7 @@ import * as React from 'react';
2
2
  import { IBaseChartProps } from '../common/chart';
3
3
  export interface ILineChartProps<DataType = unknown> extends IBaseChartProps<DataType> {
4
4
  syncId?: number | string;
5
+ alertThreshold?: object;
6
+ warnThreshold?: object;
5
7
  }
6
8
  export declare function LineChart<DataType = unknown>(props: ILineChartProps<DataType>): React.JSX.Element;
@@ -61,11 +61,12 @@ var quantum_product_1 = require("@auth0/quantum-product");
61
61
  var theme_1 = require("../theme");
62
62
  var custom_active_dot_1 = __importDefault(require("./custom-active-dot"));
63
63
  var custom_tooltip_1 = __importDefault(require("../common/custom-tooltip"));
64
+ var custom_threshold_label_1 = require("./custom-threshold-label");
64
65
  var chart_card_1 = require("../chart-card");
65
66
  var chart_1 = require("../common/chart");
66
67
  var custom_legend_1 = require("../common/custom-legend");
67
68
  function LineChart(props) {
68
- 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;
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, alertThreshold = _a.alertThreshold, warnThreshold = _a.warnThreshold;
69
70
  var theme = (0, quantum_product_1.useTheme)();
70
71
  // Function to know how many lines we need based of how much different group values are.
71
72
  var groups = lodash_1.default.uniqBy(data, 'group').map(function (item) { return item.group; });
@@ -106,7 +107,7 @@ function LineChart(props) {
106
107
  _b[entry.group] = entry[leftAxisDataKey],
107
108
  _b;
108
109
  });
109
- return (React.createElement(chart_card_1.ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText, headerAction: headerAction },
110
+ return (React.createElement(chart_card_1.ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText, headerAction: headerAction, additionalMenuItems: additionalMenuItems },
110
111
  React.createElement(recharts_1.ResponsiveContainer, { width: '100%', height: height }, data.length ? (React.createElement(recharts_1.LineChart, { data: Object.values(entries), height: height, width: 500, syncId: syncId, margin: {
111
112
  top: 24,
112
113
  right: 10,
@@ -122,7 +123,9 @@ function LineChart(props) {
122
123
  return (React.createElement(recharts_1.Line, { key: group, dataKey: group, name: group, strokeWidth: 3, hide: lineVisibility[group] === true, stroke: lineVisibility.hover === group || !lineVisibility.hover
123
124
  ? (0, theme_1.getColorScale)(theme)[color]['base'][index]
124
125
  : (0, theme_1.getColorScale)(theme)[color]['muted'][index], dot: false, activeDot: (0, custom_active_dot_1.default)() }));
125
- }))) : (React.createElement("div", { style: {
126
+ }),
127
+ alertThreshold && (React.createElement(recharts_1.ReferenceLine, { y: alertThreshold.value, stroke: theme.tokens.color_bg_state_danger, strokeDasharray: "8", strokeWidth: "2", label: React.createElement(recharts_1.Label, { value: alertThreshold.value, content: React.createElement(custom_threshold_label_1.CustomThresholdLabel, { viewBox: true, label: alertThreshold.label, thresholdType: 'alert', theme: theme }) }) })),
128
+ warnThreshold && (React.createElement(recharts_1.ReferenceLine, { y: warnThreshold.value, stroke: theme.tokens.color_bg_state_caution, strokeDasharray: "8", strokeWidth: "2", label: React.createElement(recharts_1.Label, { value: warnThreshold.value, content: React.createElement(custom_threshold_label_1.CustomThresholdLabel, { viewBox: true, label: warnThreshold.label, thresholdType: 'warn', theme: theme }) }) })))) : (React.createElement("div", { style: {
126
129
  display: 'grid',
127
130
  placeItems: 'center',
128
131
  height: '100%',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auth0/quantum-charts",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "sideEffects": false,
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",