@auth0/quantum-charts 0.3.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/custom-legend.js +11 -4
- package/esm/common/custom-legend.js +8 -4
- package/esm/line-chart/custom-threshold-label.js +9 -0
- package/esm/line-chart/custom-threshold-legend.js +10 -0
- package/esm/line-chart/index.js +6 -3
- package/line-chart/custom-threshold-label.d.ts +7 -0
- package/line-chart/custom-threshold-label.js +36 -0
- package/line-chart/custom-threshold-legend.d.ts +3 -0
- package/line-chart/custom-threshold-legend.js +35 -0
- package/line-chart/index.d.ts +2 -0
- package/line-chart/index.js +5 -2
- package/package.json +2 -2
package/common/custom-legend.js
CHANGED
|
@@ -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 },
|
|
62
|
-
React.createElement(
|
|
63
|
-
|
|
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;
|
|
@@ -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 },
|
|
36
|
-
React.createElement(
|
|
37
|
-
|
|
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
|
};
|
|
@@ -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;
|
package/esm/line-chart/index.js
CHANGED
|
@@ -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, additionalMenuItems = _a.additionalMenuItems;
|
|
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; });
|
|
@@ -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
|
-
})
|
|
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,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,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;
|
package/line-chart/index.d.ts
CHANGED
|
@@ -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;
|
package/line-chart/index.js
CHANGED
|
@@ -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, additionalMenuItems = _a.additionalMenuItems;
|
|
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; });
|
|
@@ -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
|
-
})
|
|
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
|
+
"version": "1.0.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"registry": "https://registry.npmjs.org/"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@auth0/quantum-product": "^2.
|
|
19
|
+
"@auth0/quantum-product": "^2.1.0",
|
|
20
20
|
"@formatjs/intl": "^2.5.1",
|
|
21
21
|
"date-fns": "^2.29.3",
|
|
22
22
|
"recharts": "^2.0.7"
|