ag-common 0.0.795 → 0.0.797
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/dist/ui/components/LineChart/Base.js +2 -2
- package/dist/ui/components/LineChart/LegendX.d.ts +2 -1
- package/dist/ui/components/LineChart/LegendX.js +2 -1
- package/dist/ui/components/LineChart/getLegendItems.d.ts +3 -1
- package/dist/ui/components/LineChart/getLegendItems.js +36 -11
- package/dist/ui/components/LineChart/types.d.ts +4 -0
- package/dist/ui/helpers/useTooltip.js +1 -9
- package/package.json +1 -1
|
@@ -58,7 +58,7 @@ const LineChart = (p) => {
|
|
|
58
58
|
lt !== null && lt !== void 0 ? lt : (lt = (s) => s.toString());
|
|
59
59
|
const lt2 = lt;
|
|
60
60
|
const tt2 = tt;
|
|
61
|
-
const legendItems = (0, getLegendItems_1.getLegendItems)(Object.assign(Object.assign({ colours: p.colours, data: p.data, tt: tt2, lt: lt2 }, (_a = UT.pos) === null || _a === void 0 ? void 0 : _a.data), { fixed: false }));
|
|
61
|
+
const legendItems = (0, getLegendItems_1.getLegendItems)(Object.assign(Object.assign({ colours: p.colours, data: p.data, legendData: p.legendData, tt: tt2, lt: lt2 }, (_a = UT.pos) === null || _a === void 0 ? void 0 : _a.data), { fixed: false }));
|
|
62
62
|
const SvgC = (react_1.default.createElement(Svg, { style: {
|
|
63
63
|
borderLeft: `solid 1px ${style.borderColor}`,
|
|
64
64
|
borderTop: `solid 1px ${style.borderColor}`,
|
|
@@ -116,6 +116,6 @@ const LineChart = (p) => {
|
|
|
116
116
|
react_1.default.createElement(FlexRow_1.FlexRow, { noWrap: true },
|
|
117
117
|
react_1.default.createElement(LegendY_1.LegendY, { data: p.data, style: style }),
|
|
118
118
|
SvgC),
|
|
119
|
-
react_1.default.createElement(LegendX_1.LegendX, { data: p.data, colours: p.colours, lt: lt, tt: tt, style: style })));
|
|
119
|
+
react_1.default.createElement(LegendX_1.LegendX, { data: p.data, legendData: p.legendData, colours: p.colours, lt: lt, tt: tt, style: style })));
|
|
120
120
|
};
|
|
121
121
|
exports.LineChart = LineChart;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { IVarStyles } from '../../styles/common';
|
|
3
3
|
import type { ILineChartItemRaw } from './types';
|
|
4
|
-
export declare const LegendX: ({ data, lt, tt, colours, style, }: {
|
|
4
|
+
export declare const LegendX: ({ data, legendData, lt, tt, colours, style, }: {
|
|
5
5
|
data: ILineChartItemRaw[];
|
|
6
|
+
legendData?: ILineChartItemRaw[];
|
|
6
7
|
colours: Record<string, string>;
|
|
7
8
|
lt: (a: number) => string;
|
|
8
9
|
tt: (a: number) => string;
|
|
@@ -68,9 +68,10 @@ const Col = styled_1.default.div `
|
|
|
68
68
|
border-radius: 50%;
|
|
69
69
|
margin-right: 0.25rem;
|
|
70
70
|
`;
|
|
71
|
-
const LegendX = ({ data, lt, tt, colours, style, }) => {
|
|
71
|
+
const LegendX = ({ data, legendData, lt, tt, colours, style, }) => {
|
|
72
72
|
const legendItems = (0, getLegendItems_1.getLegendItems)({
|
|
73
73
|
data,
|
|
74
|
+
legendData,
|
|
74
75
|
colours,
|
|
75
76
|
fixed: true,
|
|
76
77
|
lt,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ILineChartTooltip } from './types';
|
|
1
|
+
import type { ILineChartItemRaw, ILineChartTooltip } from './types';
|
|
2
2
|
export interface ILegendItem {
|
|
3
3
|
y: number;
|
|
4
4
|
colour: string;
|
|
@@ -13,4 +13,6 @@ export interface ILegendItems {
|
|
|
13
13
|
export declare const getLegendItems: (p: ILineChartTooltip & {
|
|
14
14
|
/** if true, will only return top items */
|
|
15
15
|
fixed: boolean;
|
|
16
|
+
/** optional dataset used for legend/tooltip computations */
|
|
17
|
+
legendData?: ILineChartItemRaw[];
|
|
16
18
|
}) => ILegendItems;
|
|
@@ -8,12 +8,14 @@ const shownResults = 4;
|
|
|
8
8
|
const getTopItems = ({ data, colours, }) => {
|
|
9
9
|
const val = {};
|
|
10
10
|
data.forEach((d) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const key = (_a = d.legendName) !== null && _a !== void 0 ? _a : d.name;
|
|
11
13
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
12
|
-
if (!val[
|
|
13
|
-
val[
|
|
14
|
+
if (!val[key]) {
|
|
15
|
+
val[key] = { colour: colours[d.name], name: key, value: d.y };
|
|
14
16
|
}
|
|
15
17
|
else {
|
|
16
|
-
val[
|
|
18
|
+
val[key].value += d.y;
|
|
17
19
|
}
|
|
18
20
|
});
|
|
19
21
|
const values = Object.values(val).sort((a, b) => a.value < b.value ? 1 : -1);
|
|
@@ -26,15 +28,38 @@ const getTopItems = ({ data, colours, }) => {
|
|
|
26
28
|
return legendItems;
|
|
27
29
|
};
|
|
28
30
|
const getLegendItems = (p) => {
|
|
29
|
-
var _a
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
var _a;
|
|
32
|
+
const dataSource = (_a = p.legendData) !== null && _a !== void 0 ? _a : p.data;
|
|
33
|
+
let values = [];
|
|
34
|
+
if (p.selectedXs && p.selectedXs.length > 0) {
|
|
35
|
+
const sx = p.selectedXs[0].x;
|
|
36
|
+
const grouped = {};
|
|
37
|
+
dataSource
|
|
38
|
+
.filter((d) => d.x === sx)
|
|
39
|
+
.forEach((d) => {
|
|
40
|
+
var _a;
|
|
41
|
+
const key = (_a = d.legendName) !== null && _a !== void 0 ? _a : d.name;
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
43
|
+
if (!grouped[key]) {
|
|
44
|
+
grouped[key] = {
|
|
45
|
+
value: d.y,
|
|
46
|
+
colour: p.colours[d.name],
|
|
47
|
+
name: key,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
grouped[key].value += d.y;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
values = Object.values(grouped).map((g) => ({
|
|
55
|
+
colour: g.colour,
|
|
56
|
+
name: g.name,
|
|
57
|
+
y: g.value,
|
|
58
|
+
x: sx,
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
36
61
|
if (p.fixed || values.length === 0) {
|
|
37
|
-
values = getTopItems(p);
|
|
62
|
+
values = getTopItems({ data: dataSource, colours: p.colours });
|
|
38
63
|
}
|
|
39
64
|
const total = (0, math_1.sumArray)(values.map((a) => a.y));
|
|
40
65
|
const min = total * 0.1;
|
|
@@ -3,6 +3,8 @@ export type ILineChartItemRaw = {
|
|
|
3
3
|
x: number;
|
|
4
4
|
y: number;
|
|
5
5
|
name: string;
|
|
6
|
+
/** Optional display name used for legend/tooltip grouping */
|
|
7
|
+
legendName?: string;
|
|
6
8
|
};
|
|
7
9
|
export interface ILineChartState {
|
|
8
10
|
selectedPoints?: {
|
|
@@ -19,6 +21,8 @@ export interface ILineChartTooltip extends ILineChartState {
|
|
|
19
21
|
}
|
|
20
22
|
export interface ILineChart {
|
|
21
23
|
data: ILineChartItemRaw[];
|
|
24
|
+
/** Optional dataset used only for legend/tooltip calculations */
|
|
25
|
+
legendData?: ILineChartItemRaw[];
|
|
22
26
|
className?: string;
|
|
23
27
|
/** name -> colour */
|
|
24
28
|
colours: Record<string, string>;
|
|
@@ -32,18 +32,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
36
|
exports.useTooltip = void 0;
|
|
40
|
-
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
41
37
|
const react_1 = __importStar(require("react"));
|
|
42
38
|
const react_dom_1 = require("react-dom");
|
|
43
|
-
const Base = styled_1.default.div `
|
|
44
|
-
position: absolute;
|
|
45
|
-
z-index: 10;
|
|
46
|
-
`;
|
|
47
39
|
const Comp = ({ pos, children, }) => {
|
|
48
40
|
const ref = (0, react_1.createRef)();
|
|
49
41
|
const [size, setSize] = (0, react_1.useState)();
|
|
@@ -100,7 +92,7 @@ const Comp = ({ pos, children, }) => {
|
|
|
100
92
|
top = 0;
|
|
101
93
|
}
|
|
102
94
|
}
|
|
103
|
-
const Content = (react_1.default.createElement(
|
|
95
|
+
const Content = (react_1.default.createElement("div", { "data-type": "tooltip-content", ref: ref, className: "absolute z-10", style: Object.assign(Object.assign({ left,
|
|
104
96
|
right,
|
|
105
97
|
top,
|
|
106
98
|
bottom }, (!pos.hasParent && { position: 'fixed' })), (!size && { zIndex: -1 })) }, children(pos, size)));
|
package/package.json
CHANGED