@auth0/quantum-charts 0.0.2

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.
Files changed (68) hide show
  1. package/LICENSE +186 -0
  2. package/bar-chart/index.d.ts +7 -0
  3. package/bar-chart/index.js +115 -0
  4. package/chart-card/index.d.ts +6 -0
  5. package/chart-card/index.js +36 -0
  6. package/chart-summary/data-table-chart.d.ts +8 -0
  7. package/chart-summary/data-table-chart.js +84 -0
  8. package/chart-summary/index.d.ts +10 -0
  9. package/chart-summary/index.js +83 -0
  10. package/common/chart.d.ts +24 -0
  11. package/common/chart.js +2 -0
  12. package/compare-aggregate/compare-aggregate.d.ts +19 -0
  13. package/compare-aggregate/compare-aggregate.js +40 -0
  14. package/compare-aggregate/index.d.ts +2 -0
  15. package/compare-aggregate/index.js +5 -0
  16. package/custom-color-status-dot.d.ts +12 -0
  17. package/custom-color-status-dot.js +17 -0
  18. package/delta/delta.d.ts +18 -0
  19. package/delta/delta.js +99 -0
  20. package/delta/index.d.ts +2 -0
  21. package/delta/index.js +6 -0
  22. package/donut-chart/center.d.ts +8 -0
  23. package/donut-chart/center.js +61 -0
  24. package/donut-chart/decoupled-legend.d.ts +9 -0
  25. package/donut-chart/decoupled-legend.js +72 -0
  26. package/donut-chart/index.d.ts +12 -0
  27. package/donut-chart/index.js +82 -0
  28. package/esm/bar-chart/index.js +85 -0
  29. package/esm/chart-card/index.js +9 -0
  30. package/esm/chart-summary/data-table-chart.js +54 -0
  31. package/esm/chart-summary/index.js +56 -0
  32. package/esm/common/chart.js +1 -0
  33. package/esm/compare-aggregate/compare-aggregate.js +13 -0
  34. package/esm/compare-aggregate/index.js +1 -0
  35. package/esm/custom-color-status-dot.js +15 -0
  36. package/esm/delta/delta.js +71 -0
  37. package/esm/delta/index.js +1 -0
  38. package/esm/donut-chart/center.js +36 -0
  39. package/esm/donut-chart/decoupled-legend.js +44 -0
  40. package/esm/donut-chart/index.js +52 -0
  41. package/esm/helpers/dataSampleFactory.js +55 -0
  42. package/esm/helpers/format-number.js +30 -0
  43. package/esm/index.js +10 -0
  44. package/esm/line-chart/custom-active-dot.js +19 -0
  45. package/esm/line-chart/custom-tooltip.js +20 -0
  46. package/esm/line-chart/index.js +65 -0
  47. package/esm/scorecard/index.js +12 -0
  48. package/esm/styles.js +37 -0
  49. package/esm/theme.js +22 -0
  50. package/helpers/dataSampleFactory.d.ts +1 -0
  51. package/helpers/dataSampleFactory.js +59 -0
  52. package/helpers/format-number.d.ts +7 -0
  53. package/helpers/format-number.js +39 -0
  54. package/index.d.ts +10 -0
  55. package/index.js +26 -0
  56. package/line-chart/custom-active-dot.d.ts +4 -0
  57. package/line-chart/custom-active-dot.js +44 -0
  58. package/line-chart/custom-tooltip.d.ts +6 -0
  59. package/line-chart/custom-tooltip.js +48 -0
  60. package/line-chart/index.d.ts +6 -0
  61. package/line-chart/index.js +95 -0
  62. package/package.json +49 -0
  63. package/scorecard/index.d.ts +7 -0
  64. package/scorecard/index.js +39 -0
  65. package/styles.d.ts +8 -0
  66. package/styles.js +43 -0
  67. package/theme.d.ts +3 -0
  68. package/theme.js +27 -0
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ declare const CustomColorStatusDot: React.FC<{
3
+ label: React.ReactNode;
4
+ color?: "default" | "warning" | "danger" | "success" | "info" | undefined;
5
+ details?: React.ReactNode;
6
+ textVariant?: "button" | "caption" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "inherit" | "overline" | "subtitle1" | "subtitle2" | "body1" | "body2" | "code1" | "code2" | undefined;
7
+ textColor?: import("@mui/system/styleFunctionSx").ResponsiveStyleValue<import("csstype").Property.Color | import("csstype").Property.Color[] | undefined> | ((theme: import("@mui/material").Theme) => import("@mui/system/styleFunctionSx").ResponsiveStyleValue<import("csstype").Property.Color | import("csstype").Property.Color[] | undefined>);
8
+ classes?: Partial<Record<"dot" | "root", string>> | undefined;
9
+ } & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "details" | "label" | "ref" | "color" | "classes" | "textColor" | "textVariant"> & import("@auth0/quantum-product").IStyledCommonProps & {
10
+ dotColor: string;
11
+ }>;
12
+ export default CustomColorStatusDot;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var lodash_1 = require("lodash");
4
+ var quantum_product_1 = require("@auth0/quantum-product");
5
+ var CustomColorStatusDot = (0, quantum_product_1.styled)(quantum_product_1.StatusDot, {
6
+ shouldForwardProp: function (prop) { return (0, quantum_product_1.rootShouldForwardProp)(prop) && prop !== 'dotColor'; },
7
+ })(function (_a) {
8
+ var _b;
9
+ var theme = _a.theme, dotColor = _a.dotColor;
10
+ var backgroundColor = (0, lodash_1.get)(theme.palette, dotColor, dotColor);
11
+ return _b = {},
12
+ _b["& .".concat(quantum_product_1.statusDotClasses.dot)] = {
13
+ backgroundColor: typeof backgroundColor === 'object' ? backgroundColor[500] : backgroundColor,
14
+ },
15
+ _b;
16
+ });
17
+ exports.default = CustomColorStatusDot;
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+ export declare type DeltaDirection = 'upIsGood' | 'upIsBad' | 'neutral';
3
+ export declare type DeltaDisplayType = 'percent' | 'number';
4
+ export declare type DeltaEmphasis = 'bad' | 'good' | 'neutral';
5
+ export interface IDeltaProps {
6
+ value: number;
7
+ comparedValue: number;
8
+ direction: DeltaDirection;
9
+ displayType: DeltaDisplayType;
10
+ darkBackground?: boolean;
11
+ useAdaptivePercentage?: boolean;
12
+ }
13
+ export interface IComputeDeltaReturn {
14
+ emphasis: DeltaEmphasis;
15
+ delta: string;
16
+ }
17
+ export declare const computeDelta: (props: IDeltaProps) => IComputeDeltaReturn;
18
+ export declare const Delta: React.FC<IDeltaProps>;
package/delta/delta.js ADDED
@@ -0,0 +1,99 @@
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.Delta = exports.computeDelta = void 0;
27
+ var React = __importStar(require("react"));
28
+ var lodash_1 = require("lodash");
29
+ var format_number_1 = require("../helpers/format-number");
30
+ var quantum_product_1 = require("@auth0/quantum-product");
31
+ var deltaFromAggregates = function (displayType, value, comparedValue) {
32
+ /*
33
+ - When absolute, (50 becoming 75) is 1.5 (meaning 150%, which is +50% when displayed)
34
+ - When percent, (0.50 becoming 0.75) is 0.25 (meaning +25%)
35
+ This function returns the 1.5 and 0.25 of those examples.
36
+ Note that when dealing with percentages we use `static percentage`,
37
+ but when dealing with absolutes we use `relative percentage`.
38
+ */
39
+ return displayType === 'percent' ? value - comparedValue : value / comparedValue;
40
+ };
41
+ var isDeltaUp = function (displayType, delta) {
42
+ return Number.isNaN(delta) || delta > (displayType === 'percent' ? 0 : 1);
43
+ };
44
+ var cleanUpDelta = function (displayType, deltaIsUp, delta) {
45
+ if (displayType === 'percent') {
46
+ return delta;
47
+ }
48
+ /*
49
+ Following up on our example in deltaFromAggregates:
50
+ - When absolute, (50 becoming 75) is 1.5 (meaning 150%, which is +50% when displayed)
51
+ - When percent, (0.50 becoming 0.75) is 0.25 (meaning +25%)
52
+ Since the logic for finding the delta of and absolute metric includes a division,
53
+ we need to be prepared for NaN and infinite values.
54
+ If it's NaN or infinite, we fallback to some reasonnable defaults:
55
+ - NaN is 0%
56
+ - Infinite -> -100% or +100% depending on whether deltaIsUp
57
+ For all other happy-path cases, we want to go from this 150% result to +50% displayed value,
58
+ so we add or remove 100% to adjust properly:
59
+ - 150% is up so we remove 100%, which gives us our 50%
60
+ - 75% is down so we remove it from 100%, which gives us our 25%.
61
+ The + or - symbol is handled later, we don't need to care about it here.
62
+ */
63
+ var adjustedDelta = deltaIsUp ? delta - 1 : 1 - delta;
64
+ if (Number.isNaN(adjustedDelta)) {
65
+ return 0;
66
+ }
67
+ if (Number.isFinite(adjustedDelta)) {
68
+ return adjustedDelta;
69
+ }
70
+ return deltaIsUp ? 1 : -1;
71
+ };
72
+ var hasNoSignificantChanges = function (aggregate, comparedAggregate) {
73
+ return (aggregate === comparedAggregate ||
74
+ (0, lodash_1.inRange)(aggregate, comparedAggregate - 0.001 * comparedAggregate, comparedAggregate + 0.001 * comparedAggregate));
75
+ };
76
+ var findEmphasis = function (direction, deltaIsUp, noSignificantChanges) {
77
+ if (direction === 'neutral' || noSignificantChanges) {
78
+ return 'neutral';
79
+ }
80
+ return (deltaIsUp && direction === 'upIsGood') || (!deltaIsUp && direction === 'upIsBad') ? 'good' : 'bad';
81
+ };
82
+ var computeDelta = function (props) {
83
+ var displayType = props.displayType, value = props.value, comparedValue = props.comparedValue;
84
+ var delta = deltaFromAggregates(displayType, value, comparedValue);
85
+ var deltaIsUp = isDeltaUp(displayType, delta);
86
+ var usableDelta = cleanUpDelta(displayType, deltaIsUp, delta);
87
+ var noSignificantChanges = hasNoSignificantChanges(value, comparedValue);
88
+ var emphasis = findEmphasis(props.direction, deltaIsUp, noSignificantChanges);
89
+ var symbol = noSignificantChanges ? '' : deltaIsUp ? '+' : '-';
90
+ var percentFormatter = props.useAdaptivePercentage ? format_number_1.toPercentageAdaptive : format_number_1.toPercentage;
91
+ var finalDelta = symbol + percentFormatter(Math.abs(usableDelta));
92
+ return { emphasis: emphasis, delta: finalDelta };
93
+ };
94
+ exports.computeDelta = computeDelta;
95
+ var Delta = function (props) {
96
+ var delta = (0, exports.computeDelta)(props).delta;
97
+ return (React.createElement(quantum_product_1.Label, { color: props.direction === 'upIsGood' ? 'success' : props.direction === 'upIsBad' ? 'danger' : 'default' }, delta));
98
+ };
99
+ exports.Delta = Delta;
@@ -0,0 +1,2 @@
1
+ export { Delta, computeDelta } from './delta';
2
+ export type { IDeltaProps, IComputeDeltaReturn, DeltaDirection, DeltaDisplayType, DeltaEmphasis } from './delta';
package/delta/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeDelta = exports.Delta = void 0;
4
+ var delta_1 = require("./delta");
5
+ Object.defineProperty(exports, "Delta", { enumerable: true, get: function () { return delta_1.Delta; } });
6
+ Object.defineProperty(exports, "computeDelta", { enumerable: true, get: function () { return delta_1.computeDelta; } });
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ declare type CenterProps = {
3
+ data: any;
4
+ activeIndex?: number;
5
+ displayType: 'absolute' | 'percent';
6
+ };
7
+ declare const Center: React.FC<CenterProps>;
8
+ export default Center;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
+ return cooked;
5
+ };
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || function (mod) {
23
+ if (mod && mod.__esModule) return mod;
24
+ var result = {};
25
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
26
+ __setModuleDefault(result, mod);
27
+ return result;
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ var React = __importStar(require("react"));
31
+ var quantum_product_1 = require("@auth0/quantum-product");
32
+ var format_number_1 = require("../helpers/format-number");
33
+ var sumValues = function (data) {
34
+ return data.reduce(function (accum, item) { return accum + item.value; }, 0);
35
+ };
36
+ var findAggregate = function (data, isTotal, activeIndex) { var _a; return (isTotal ? sumValues(data) : (_a = data === null || data === void 0 ? void 0 : data[activeIndex]) === null || _a === void 0 ? void 0 : _a.value); };
37
+ 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) {
38
+ var theme = _a.theme;
39
+ return theme.typography.fontWeightRegular;
40
+ }, function (_a) {
41
+ var theme = _a.theme;
42
+ return theme.typography.h4.fontSize;
43
+ });
44
+ var CenterPositioning = (0, quantum_product_1.styled)(quantum_product_1.Box)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: grid;\n place-items: center;\n height: 100%;\n text-align: center;\n"], ["\n display: grid;\n place-items: center;\n height: 100%;\n text-align: center;\n"])));
45
+ var Center = function (props) {
46
+ var activeIndex = props.activeIndex, data = props.data, displayType = props.displayType;
47
+ var hasNoData = data.length === 0;
48
+ var aggregate = findAggregate(data, activeIndex === undefined, activeIndex);
49
+ var percentage = function (partialValue, totalValue) {
50
+ return (100 * partialValue) / totalValue;
51
+ };
52
+ return (React.createElement(CenterPositioning, null,
53
+ React.createElement(quantum_product_1.Box, null,
54
+ React.createElement(Aggregate, null, hasNoData
55
+ ? 'No data'
56
+ : displayType === 'absolute'
57
+ ? (0, format_number_1.toShortCompactNotation)(aggregate)
58
+ : (0, format_number_1.toPercentageAdaptive)(percentage(aggregate, sumValues(data)) / 100)))));
59
+ };
60
+ exports.default = Center;
61
+ var templateObject_1, templateObject_2;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { IDonutChartDataPoint } from './';
3
+ export declare type IDecoupledLegendProps<DataType = unknown> = {
4
+ data: IDonutChartDataPoint<DataType>[];
5
+ activeIndex?: number;
6
+ setActiveIndex: (index: number | undefined) => void;
7
+ };
8
+ declare function DecoupledLegend<DataType = unknown>(props: IDecoupledLegendProps<DataType>): JSX.Element;
9
+ export default DecoupledLegend;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
+ return cooked;
5
+ };
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || function (mod) {
23
+ if (mod && mod.__esModule) return mod;
24
+ var result = {};
25
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
26
+ __setModuleDefault(result, mod);
27
+ return result;
28
+ };
29
+ var __importDefault = (this && this.__importDefault) || function (mod) {
30
+ return (mod && mod.__esModule) ? mod : { "default": mod };
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ var React = __importStar(require("react"));
34
+ var styled_components_1 = __importDefault(require("styled-components"));
35
+ var quantum_product_1 = require("@auth0/quantum-product");
36
+ var theme_1 = require("../theme");
37
+ function DecoupledLegend(props) {
38
+ var data = props.data, activeIndex = props.activeIndex, setActiveIndex = props.setActiveIndex;
39
+ var theme = (0, quantum_product_1.useTheme)();
40
+ var BASE_COLORS = (0, theme_1.getBaseColorScale)(theme);
41
+ return (React.createElement("div", { style: { display: 'flex', flexDirection: 'column', gap: '8px', height: '150px', flexWrap: 'wrap' } }, data.map(function (datum, index) {
42
+ var isActive = activeIndex !== undefined && activeIndex === index;
43
+ var color = BASE_COLORS[index % BASE_COLORS.length];
44
+ return (React.createElement(React.Fragment, { key: index },
45
+ React.createElement(quantum_product_1.StackLayout, { gutter: 1, onMouseEnter: function () {
46
+ setActiveIndex(index);
47
+ }, onMouseLeave: function () {
48
+ setActiveIndex(undefined);
49
+ }, sx: {
50
+ flexWrap: 'nowrap',
51
+ } },
52
+ React.createElement(quantum_product_1.StackLayoutItem, { sx: {
53
+ alignSelf: 'center',
54
+ } },
55
+ React.createElement(LegendDotWrapper, { style: {
56
+ border: '2px solid ' + (isActive ? color : 'white'),
57
+ } },
58
+ React.createElement(LegendDot, { style: { backgroundColor: color } }))),
59
+ React.createElement(quantum_product_1.StackLayoutItem, { sx: {
60
+ alignSelf: 'center',
61
+ } },
62
+ React.createElement(LegendText, { color: isActive ? 'primary' : 'secondary' }, datum.name)))));
63
+ })));
64
+ }
65
+ var LegendDot = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n height: 12px;\n width: 12px;\n border: 2px solid white;\n border-radius: 2px;\n"], ["\n height: 12px;\n width: 12px;\n border: 2px solid white;\n border-radius: 2px;\n"])));
66
+ var LegendDotWrapper = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n border-radius: 4px;\n"], ["\n border-radius: 4px;\n"])));
67
+ var LegendText = styled_components_1.default.span(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n color: ", ";\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n cursor: default;\n"], ["\n color: ", ";\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n cursor: default;\n"])), function (_a) {
68
+ var theme = _a.theme, color = _a.color;
69
+ return theme.palette.text[color !== null && color !== void 0 ? color : 'secondary'];
70
+ });
71
+ exports.default = DecoupledLegend;
72
+ var templateObject_1, templateObject_2, templateObject_3;
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { IChartCardProps } from '../chart-card';
3
+ export declare type IDonutChartDataPoint<DataType = unknown> = {
4
+ name: string;
5
+ value?: number;
6
+ } & DataType;
7
+ interface IDonutChartProps<DataType = unknown> extends IChartCardProps {
8
+ data: IDonutChartDataPoint<DataType>[];
9
+ displayType: 'absolute' | 'percent';
10
+ }
11
+ export declare function DonutChart(props: IDonutChartProps): JSX.Element;
12
+ export {};
@@ -0,0 +1,82 @@
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
+ var __read = (this && this.__read) || function (o, n) {
26
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
27
+ if (!m) return o;
28
+ var i = m.call(o), r, ar = [], e;
29
+ try {
30
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
31
+ }
32
+ catch (error) { e = { error: error }; }
33
+ finally {
34
+ try {
35
+ if (r && !r.done && (m = i["return"])) m.call(i);
36
+ }
37
+ finally { if (e) throw e.error; }
38
+ }
39
+ return ar;
40
+ };
41
+ var __importDefault = (this && this.__importDefault) || function (mod) {
42
+ return (mod && mod.__esModule) ? mod : { "default": mod };
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.DonutChart = void 0;
46
+ var React = __importStar(require("react"));
47
+ var recharts_1 = require("recharts");
48
+ var quantum_product_1 = require("@auth0/quantum-product");
49
+ var theme_1 = require("../theme");
50
+ var center_1 = __importDefault(require("./center"));
51
+ var decoupled_legend_1 = __importDefault(require("./decoupled-legend"));
52
+ var chart_card_1 = require("../chart-card");
53
+ function DonutChart(props) {
54
+ var data = props.data, displayType = props.displayType, title = props.title, value = props.value, label = props.label, helperText = props.helperText;
55
+ var _a = __read(React.useState(undefined), 2), activeIndex = _a[0], setActiveIndex = _a[1];
56
+ var theme = (0, quantum_product_1.useTheme)();
57
+ var BASE_COLORS = (0, theme_1.getBaseColorScale)(theme);
58
+ return (React.createElement(chart_card_1.ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText },
59
+ React.createElement(quantum_product_1.StackLayout, { sx: {
60
+ height: '150px',
61
+ flexWrap: 'nowrap',
62
+ mt: '24px',
63
+ } },
64
+ React.createElement(quantum_product_1.StackLayoutItem, { sx: {
65
+ height: '150px',
66
+ width: '150px',
67
+ } },
68
+ React.createElement(recharts_1.ResponsiveContainer, { width: '100%', height: 150 },
69
+ React.createElement(recharts_1.PieChart, { height: 150, width: 150 },
70
+ React.createElement("foreignObject", { x: 0, y: 0, width: '100%', height: '100%' },
71
+ React.createElement(center_1.default, { activeIndex: activeIndex, data: data, displayType: displayType })),
72
+ React.createElement(recharts_1.Pie, { dataKey: 'value', data: data, innerRadius: 55, outerRadius: 75, paddingAngle: 2, animationDuration: 750, animationBegin: 0, activeIndex: activeIndex, onMouseEnter: function (_, index) {
73
+ setActiveIndex(index);
74
+ }, onMouseLeave: function () {
75
+ setActiveIndex(undefined);
76
+ } }, data.map(function (_, index) {
77
+ return (React.createElement(recharts_1.Cell, { key: "cell-".concat(index), fill: BASE_COLORS[index % BASE_COLORS.length], opacity: activeIndex === undefined ? 1 : activeIndex === index ? 1 : 0.5 }));
78
+ }))))),
79
+ React.createElement(quantum_product_1.StackLayoutItem, null,
80
+ React.createElement(decoupled_legend_1.default, { activeIndex: activeIndex, setActiveIndex: setActiveIndex, data: data })))));
81
+ }
82
+ exports.DonutChart = DonutChart;
@@ -0,0 +1,85 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import _ from 'lodash';
13
+ import * as React from 'react';
14
+ import { BarChart as RechartsBarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, } from 'recharts';
15
+ import { useTheme, Text } from '@auth0/quantum-product';
16
+ import { getBaseColorScale } from '../theme';
17
+ import CustomTooltip from '../line-chart/custom-tooltip';
18
+ import { format } from 'date-fns';
19
+ import { ChartCard } from '../chart-card';
20
+ export function BarChart(props) {
21
+ var _a = props, data = _a.data, leftAxis = _a.leftAxis, bottomAxis = _a.bottomAxis, _b = _a.height, height = _b === void 0 ? 300 : _b, title = _a.title, value = _a.value, label = _a.label, helperText = _a.helperText, _c = _a.layout, layout = _c === void 0 ? 'vertical' : _c, _d = _a.isStacked, isStacked = _d === void 0 ? false : _d;
22
+ var theme = useTheme();
23
+ // Function to know how many bars we need based of how much different group values are.
24
+ var groups = _.uniqBy(data, 'group').map(function (item) { return item.group; });
25
+ var bottomAxisDataKey = bottomAxis.mapsTo || 'date';
26
+ var leftAxisDataKey = leftAxis.mapsTo || 'value';
27
+ var entries = {};
28
+ data.forEach(function (entry) {
29
+ var _a, _b;
30
+ var entrytKey = entry[bottomAxisDataKey];
31
+ if (entries[entrytKey]) {
32
+ entries[entrytKey][entry.group] = entry[leftAxisDataKey];
33
+ }
34
+ else {
35
+ entries[entrytKey] = (_a = {},
36
+ _a[bottomAxisDataKey] = entry[bottomAxisDataKey],
37
+ _a[entry.group] = entry[leftAxisDataKey],
38
+ _a);
39
+ }
40
+ return _b = {},
41
+ _b[bottomAxisDataKey] = entry[bottomAxisDataKey],
42
+ _b[entry.group] = entry[leftAxisDataKey],
43
+ _b;
44
+ });
45
+ var formatBottomTick = function (value) {
46
+ if (bottomAxis.scaleType === 'date') {
47
+ return format(new Date(value), 'LLL d');
48
+ }
49
+ if (bottomAxis.scaleType === 'datetime') {
50
+ return format(new Date(value), 'LLL d p');
51
+ }
52
+ return value;
53
+ };
54
+ return (React.createElement(ChartCard, { title: title, value: value, dataTable: data, label: label, helperText: helperText },
55
+ React.createElement(ResponsiveContainer, { width: "100%", height: height }, data.length ? (React.createElement(RechartsBarChart, { width: 500, layout: layout === 'horizontal' ? 'vertical' : 'horizontal', height: height, data: Object.values(entries), margin: {
56
+ top: 24,
57
+ right: 10,
58
+ left: layout === 'vertical' ? -24 : -6,
59
+ bottom: 0,
60
+ } },
61
+ React.createElement(CartesianGrid, { vertical: false, stroke: theme.tokens.color_border_default }),
62
+ React.createElement(XAxis, __assign({}, (layout === 'horizontal'
63
+ ? { type: 'number' }
64
+ : { tickFormatter: formatBottomTick, dataKey: bottomAxisDataKey }), { height: 30 })),
65
+ React.createElement(YAxis, __assign({}, (layout === 'horizontal' && {
66
+ type: 'category',
67
+ tickFormatter: formatBottomTick,
68
+ dataKey: bottomAxisDataKey,
69
+ }), { domain: ['auto', 'auto'] })),
70
+ React.createElement(Tooltip, { content: React.createElement(CustomTooltip, { active: undefined, payload: undefined }) }),
71
+ React.createElement(Legend, { align: "center", iconType: "square", iconSize: 14, wrapperStyle: { paddingTop: 16 } }),
72
+ groups.map(function (group, index) {
73
+ return (React.createElement(Bar, __assign({ key: group, dataKey: group }, (isStacked && { stackId: 'stack' }), { name: group, maxBarSize: 70, fill: getBaseColorScale(theme)[index], radius: !isStacked || index == groups.length - 1
74
+ ? layout === 'vertical'
75
+ ? [4, 4, 0, 0]
76
+ : [0, 4, 4, 0]
77
+ : [0, 0, 0, 0] })));
78
+ }))) : (React.createElement("div", { style: {
79
+ display: 'grid',
80
+ placeItems: 'center',
81
+ height: '100%',
82
+ textAlign: 'center',
83
+ } },
84
+ React.createElement(Text, { variant: "subtitle1" }, "No data"))))));
85
+ }
@@ -0,0 +1,9 @@
1
+ import { Card } from '@auth0/quantum-product';
2
+ import * as React from 'react';
3
+ import { ChartSummary } from '../chart-summary';
4
+ export function ChartCard(props) {
5
+ var children = props.children, title = props.title, value = props.value, dataTable = props.dataTable, helperText = props.helperText, label = props.label;
6
+ return (React.createElement(Card, null,
7
+ React.createElement(ChartSummary, { title: title, value: value, dataTable: dataTable, helperText: helperText, label: label }),
8
+ children));
9
+ }
@@ -0,0 +1,54 @@
1
+ var __read = (this && this.__read) || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o), r, ar = [], e;
5
+ try {
6
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
+ }
8
+ catch (error) { e = { error: error }; }
9
+ finally {
10
+ try {
11
+ if (r && !r.done && (m = i["return"])) m.call(i);
12
+ }
13
+ finally { if (e) throw e.error; }
14
+ }
15
+ return ar;
16
+ };
17
+ import _ from 'lodash';
18
+ import * as React from 'react';
19
+ import { format } from 'date-fns';
20
+ import { Box, Button, DataTable, Dialog, Tab, TabList, TabPanel, Tabs } from '@auth0/quantum-product';
21
+ export function DataTableChart(props) {
22
+ var isOpen = props.isOpen, title = props.title, toggleIsOpen = props.toggleIsOpen, data = props.data;
23
+ var isDonut = data[0] && data[0].name !== undefined;
24
+ var groups = _.groupBy(data, 'group');
25
+ var _a = __read(React.useState(Object.keys(groups)[0]), 2), selectedTab = _a[0], setSelectedTab = _a[1];
26
+ return (React.createElement(Dialog, { open: isOpen, fullWidth: true, title: title, onClose: toggleIsOpen, actions: React.createElement(React.Fragment, null,
27
+ React.createElement(Button, { color: "primary", variant: "contained" }, "Download CSV")) },
28
+ React.createElement(Box, { p: 2 },
29
+ React.createElement(Tabs, { baseId: 'example', onChange: setSelectedTab, value: selectedTab },
30
+ React.createElement(TabList, { classes: { indicator: 'chromatic-ignore' } }, !isDonut &&
31
+ Object.keys(groups).map(function (group, index) {
32
+ return React.createElement(Tab, { key: index, label: group, value: group });
33
+ })),
34
+ React.createElement(Box, { paddingY: 2 }, isDonut ? (React.createElement(DataTable, { items: data, columns: [
35
+ { field: 'name', title: 'Group' },
36
+ { title: 'value', render: function (_a) {
37
+ var item = _a.item;
38
+ return item.value || 'N/A';
39
+ } },
40
+ ] })) : (Object.values(groups).map(function (item, index) {
41
+ return (React.createElement(TabPanel, { key: index, value: item[index].group },
42
+ React.createElement(DataTable, { items: item, columns: [
43
+ { field: 'group', title: 'Group' },
44
+ { title: 'value', render: function (_a) {
45
+ var item = _a.item;
46
+ return item.value || 'N/A';
47
+ } },
48
+ { title: 'date', render: function (_a) {
49
+ var item = _a.item;
50
+ return format(new Date(item.date), 'LLL d p');
51
+ } },
52
+ ] })));
53
+ })))))));
54
+ }
@@ -0,0 +1,56 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ var __read = (this && this.__read) || function (o, n) {
6
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
7
+ if (!m) return o;
8
+ var i = m.call(o), r, ar = [], e;
9
+ try {
10
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
11
+ }
12
+ catch (error) { e = { error: error }; }
13
+ finally {
14
+ try {
15
+ if (r && !r.done && (m = i["return"])) m.call(i);
16
+ }
17
+ finally { if (e) throw e.error; }
18
+ }
19
+ return ar;
20
+ };
21
+ import * as React from 'react';
22
+ import { Box, DescriptionBlock, StackLayout, StackLayoutItem, Tooltip, HelpCircleIcon, styled, IconButton, ListIcon, Text, } from '@auth0/quantum-product';
23
+ import { DataTableChart } from './data-table-chart';
24
+ 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
+ var theme = _a.theme;
26
+ return theme.typography.fontWeightRegular;
27
+ }, function (_a) {
28
+ var theme = _a.theme;
29
+ return theme.typography.h4.fontSize;
30
+ });
31
+ export function ChartSummary(props) {
32
+ var title = props.title, value = props.value, helperText = props.helperText, label = props.label, dataTable = props.dataTable;
33
+ var _a = __read(React.useState(false), 2), isOpen = _a[0], setIsOpen = _a[1];
34
+ var toggleIsOpen = function () {
35
+ setIsOpen(function (prev) { return !prev; });
36
+ };
37
+ return (React.createElement("div", null,
38
+ React.createElement(DescriptionBlock, { label: React.createElement("div", { style: { display: 'flex', justifyContent: 'space-between' } },
39
+ React.createElement(StackLayout, { gutter: 1 },
40
+ React.createElement(StackLayoutItem, null,
41
+ React.createElement(Text, { fontWeight: 500 }, title)),
42
+ helperText && (React.createElement(StackLayoutItem, null,
43
+ React.createElement(Tooltip, { placement: "top", title: helperText },
44
+ React.createElement(Box, { sx: {
45
+ display: 'grid',
46
+ alignSelf: 'center',
47
+ color: 'textSecondary',
48
+ } },
49
+ React.createElement(HelpCircleIcon, { size: "16" })))))),
50
+ dataTable && dataTable[0] && (React.createElement(IconButton, { onClick: function () { return setIsOpen(true); } },
51
+ React.createElement(ListIcon, null)))), labelTypographyProps: { variant: 'subtitle1' }, description: React.createElement(StackLayout, { gutter: 1 },
52
+ React.createElement(Aggregate, null, value),
53
+ label) }),
54
+ dataTable && dataTable[0] && (React.createElement(DataTableChart, { title: title, isOpen: isOpen, toggleIsOpen: toggleIsOpen, data: dataTable }))));
55
+ }
56
+ var templateObject_1;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ import { DefaultCursorBox } from '../styles';
3
+ import { Delta } from '../delta';
4
+ import { StackLayoutItem, Tooltip } from '@auth0/quantum-product';
5
+ import { toLongFormRounded, toPercentageAdaptive } from '../helpers/format-number';
6
+ export function CompareAggregate(props) {
7
+ var value = props.value, comparedValue = props.comparedValue, _a = props.displayType, displayType = _a === void 0 ? 'percent' : _a, _b = props.direction, direction = _b === void 0 ? 'upIsGood' : _b;
8
+ var aggregateFormatter = displayType === 'percent' ? toPercentageAdaptive : toLongFormRounded;
9
+ return (React.createElement(StackLayoutItem, null,
10
+ React.createElement(Tooltip, { placement: "top", title: "From ".concat(aggregateFormatter(comparedValue), " to ").concat(aggregateFormatter(value)) },
11
+ React.createElement(DefaultCursorBox, null,
12
+ React.createElement(Delta, { value: value, comparedValue: comparedValue, displayType: displayType, direction: direction })))));
13
+ }
@@ -0,0 +1 @@
1
+ export { CompareAggregate } from './compare-aggregate';