ag-common 0.0.649 → 0.0.651
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 +57 -46
- package/dist/ui/components/LineChart/{Legend.d.ts → LegendX.d.ts} +2 -1
- package/dist/ui/components/LineChart/{Legend.js → LegendX.js} +27 -26
- package/dist/ui/components/LineChart/LegendY.d.ts +5 -0
- package/dist/ui/components/LineChart/LegendY.js +43 -0
- package/dist/ui/components/LineChart/getLegendItems.d.ts +4 -1
- package/dist/ui/components/LineChart/getLegendItems.js +24 -2
- package/package.json +1 -1
|
@@ -10,15 +10,18 @@ const react_1 = __importDefault(require("react"));
|
|
|
10
10
|
const array_1 = require("../../../common/helpers/array");
|
|
11
11
|
const math_1 = require("../../../common/helpers/math");
|
|
12
12
|
const useTooltip_1 = require("../../helpers/useTooltip");
|
|
13
|
+
const FlexRow_1 = require("../FlexRow");
|
|
13
14
|
const dateHelpers_1 = require("./dateHelpers");
|
|
14
15
|
const getLegendItems_1 = require("./getLegendItems");
|
|
15
16
|
const interpolate_1 = require("./interpolate");
|
|
16
|
-
const
|
|
17
|
+
const LegendX_1 = require("./LegendX");
|
|
18
|
+
const LegendY_1 = require("./LegendY");
|
|
17
19
|
const TooltipContent_1 = require("./TooltipContent");
|
|
18
20
|
const Base = styled_1.default.div `
|
|
19
|
-
width: calc(100% - 1px);
|
|
20
|
-
height: calc(100% - 1px);
|
|
21
21
|
padding: 0.5rem;
|
|
22
|
+
width: calc(100% - 1rem);
|
|
23
|
+
height: calc(100% - 1rem);
|
|
24
|
+
|
|
22
25
|
display: flex;
|
|
23
26
|
flex-flow: column;
|
|
24
27
|
justify-content: center;
|
|
@@ -26,6 +29,13 @@ const Base = styled_1.default.div `
|
|
|
26
29
|
overflow: hidden;
|
|
27
30
|
position: relative;
|
|
28
31
|
`;
|
|
32
|
+
const Svg = styled_1.default.svg `
|
|
33
|
+
padding: 2px;
|
|
34
|
+
border-left: solid 1px var(--main-fg);
|
|
35
|
+
border-top: solid 1px var(--main-fg);
|
|
36
|
+
width: calc(100% - 5px);
|
|
37
|
+
height: calc(100% - 5px);
|
|
38
|
+
`;
|
|
29
39
|
const LineChart = (p) => {
|
|
30
40
|
var _a;
|
|
31
41
|
const UT = (0, useTooltip_1.useTooltip)();
|
|
@@ -46,50 +56,51 @@ const LineChart = (p) => {
|
|
|
46
56
|
}
|
|
47
57
|
const lt2 = lt;
|
|
48
58
|
const tt2 = tt;
|
|
49
|
-
const legendItems = (0, getLegendItems_1.getLegendItems)(Object.assign({ colours: p.colours, data: p.data, tt: tt2, lt: lt2 }, (_a = UT.pos) === null || _a === void 0 ? void 0 : _a.data));
|
|
59
|
+
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 }));
|
|
60
|
+
const SvgC = (react_1.default.createElement(Svg, { transform: "scale(-1,1) scale(-1,-1)", strokeWidth: '3px', fillOpacity: 1, preserveAspectRatio: "none", onMouseMove: (element) => {
|
|
61
|
+
const parent = element.currentTarget.closest("[data-type='lcb']");
|
|
62
|
+
const bb = parent === null || parent === void 0 ? void 0 : parent.getBoundingClientRect();
|
|
63
|
+
if (!bb) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const relativeX = (0, math_1.rangePercentage)({
|
|
67
|
+
value: element.pageX,
|
|
68
|
+
min: bb.left,
|
|
69
|
+
max: bb.left + bb.width,
|
|
70
|
+
}) * 100;
|
|
71
|
+
let selectedPoints = points.filter((p) => relativeX >= p.x1 && relativeX < p.x2);
|
|
72
|
+
//if there are just single dots on the graph, choose the ones that are closest (share the smallest gap distance)
|
|
73
|
+
if (selectedPoints.length === 0) {
|
|
74
|
+
const sp1 = points
|
|
75
|
+
.map((p) => (Object.assign(Object.assign({}, p), { gap: Math.abs(p.x1 - relativeX) })))
|
|
76
|
+
.sort((a, b) => (a.gap < b.gap ? -1 : 1));
|
|
77
|
+
const mingap = sp1 === null || sp1 === void 0 ? void 0 : sp1[0].gap;
|
|
78
|
+
selectedPoints = sp1.filter((r) => r.gap === mingap);
|
|
79
|
+
}
|
|
80
|
+
const selectedXs = (0, array_1.distinctBy)(p.data.filter(({ x, y }) => selectedPoints === null || selectedPoints === void 0 ? void 0 : selectedPoints.find((a) => a.origX === x && a.origY === y)), (s) => JSON.stringify(s));
|
|
81
|
+
UT.setPos({
|
|
82
|
+
element,
|
|
83
|
+
parent,
|
|
84
|
+
data: {
|
|
85
|
+
selectedPoints: selectedPoints.map((a) => ({
|
|
86
|
+
x: a.origX,
|
|
87
|
+
y: a.origY,
|
|
88
|
+
})),
|
|
89
|
+
selectedXs,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
} }, points.map((p2) => {
|
|
93
|
+
var _a, _b, _c;
|
|
94
|
+
return (react_1.default.createElement(react_1.default.Fragment, { key: JSON.stringify(p2) },
|
|
95
|
+
(p2.origX === ((_c = (_b = (_a = UT.pos) === null || _a === void 0 ? void 0 : _a.data.selectedXs) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.x) ||
|
|
96
|
+
p2.x1 === p2.x2) && (react_1.default.createElement("circle", { cx: `${p2.x2}%`, cy: `${p2.y2}%`, r: "8px", fill: p.colours[p2.name] })),
|
|
97
|
+
p2.x1 !== p2.x2 && (react_1.default.createElement("line", { strokeOpacity: legendItems.part.find((f) => f.name === p2.name) ? 1 : 0.3, x1: `${p2.x1}%`, x2: `${p2.x2}%`, y1: `${p2.y1}%`, y2: `${p2.y2}%`, style: { stroke: p.colours[p2.name] } }))));
|
|
98
|
+
})));
|
|
50
99
|
return (react_1.default.createElement(Base, { className: p.className, "data-type": "lcb", onMouseLeave: () => UT.setPos(undefined) },
|
|
51
100
|
react_1.default.createElement(UT.Comp, { pos: UT.pos }, (p2) => (react_1.default.createElement(TooltipContent_1.TooltipContent, Object.assign({}, p2, { colours: p.colours, data: p.data, lt: lt2, tt: tt2, legendItems: legendItems })))),
|
|
52
|
-
react_1.default.createElement(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const bb = parent === null || parent === void 0 ? void 0 : parent.getBoundingClientRect();
|
|
57
|
-
if (!bb) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const relativeX = (0, math_1.rangePercentage)({
|
|
61
|
-
value: element.pageX,
|
|
62
|
-
min: bb.left,
|
|
63
|
-
max: bb.left + bb.width,
|
|
64
|
-
}) * 100;
|
|
65
|
-
let selectedPoints = points.filter((p) => relativeX >= p.x1 && relativeX < p.x2);
|
|
66
|
-
//if there are just single dots on the graph, choose the ones that are closest (share the smallest gap distance)
|
|
67
|
-
if (selectedPoints.length === 0) {
|
|
68
|
-
const sp1 = points
|
|
69
|
-
.map((p) => (Object.assign(Object.assign({}, p), { gap: Math.abs(p.x1 - relativeX) })))
|
|
70
|
-
.sort((a, b) => (a.gap < b.gap ? -1 : 1));
|
|
71
|
-
const mingap = sp1 === null || sp1 === void 0 ? void 0 : sp1[0].gap;
|
|
72
|
-
selectedPoints = sp1.filter((r) => r.gap === mingap);
|
|
73
|
-
}
|
|
74
|
-
const selectedXs = (0, array_1.distinctBy)(p.data.filter(({ x, y }) => selectedPoints === null || selectedPoints === void 0 ? void 0 : selectedPoints.find((a) => a.origX === x && a.origY === y)), (s) => JSON.stringify(s));
|
|
75
|
-
UT.setPos({
|
|
76
|
-
element,
|
|
77
|
-
parent,
|
|
78
|
-
data: {
|
|
79
|
-
selectedPoints: selectedPoints.map((a) => ({
|
|
80
|
-
x: a.origX,
|
|
81
|
-
y: a.origY,
|
|
82
|
-
})),
|
|
83
|
-
selectedXs,
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
} }, points.map((p2) => {
|
|
87
|
-
var _a, _b, _c;
|
|
88
|
-
return (react_1.default.createElement(react_1.default.Fragment, { key: JSON.stringify(p2) },
|
|
89
|
-
(p2.origX === ((_c = (_b = (_a = UT.pos) === null || _a === void 0 ? void 0 : _a.data.selectedXs) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.x) ||
|
|
90
|
-
p2.x1 === p2.x2) && (react_1.default.createElement("circle", { cx: p2.x2, cy: p2.y2, r: 1, fill: p.colours[p2.name] })),
|
|
91
|
-
p2.x1 !== p2.x2 && (react_1.default.createElement("line", { strokeOpacity: legendItems.part.find((f) => f.name === p2.name) ? 1 : 0.3, x1: p2.x1, x2: p2.x2, y1: p2.y1, y2: p2.y2, style: { stroke: p.colours[p2.name] } }))));
|
|
92
|
-
})),
|
|
93
|
-
react_1.default.createElement(Legend_1.Legend, { data: p.data, colours: p.colours, lt: lt })));
|
|
101
|
+
react_1.default.createElement(FlexRow_1.FlexRow, { noWrap: true },
|
|
102
|
+
react_1.default.createElement(LegendY_1.LegendY, { data: p.data }),
|
|
103
|
+
SvgC),
|
|
104
|
+
react_1.default.createElement(LegendX_1.LegendX, { data: p.data, colours: p.colours, lt: lt, tt: tt })));
|
|
94
105
|
};
|
|
95
106
|
exports.LineChart = LineChart;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ILineChartItemRaw } from './types';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const LegendX: ({ data, lt, tt, colours, }: {
|
|
4
4
|
data: ILineChartItemRaw[];
|
|
5
5
|
colours: Record<string, string>;
|
|
6
6
|
lt: (a: number) => string;
|
|
7
|
+
tt: (a: number) => string;
|
|
7
8
|
}) => React.JSX.Element;
|
|
@@ -3,15 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.LegendX = void 0;
|
|
7
7
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
8
8
|
const react_1 = __importDefault(require("react"));
|
|
9
9
|
const common_1 = require("../../../common");
|
|
10
|
-
const
|
|
10
|
+
const getLegendItems_1 = require("./getLegendItems");
|
|
11
11
|
const Base = styled_1.default.div `
|
|
12
12
|
display: flex;
|
|
13
13
|
flex-flow: column;
|
|
14
14
|
width: 100%;
|
|
15
|
+
color: var(--main-fg);
|
|
15
16
|
`;
|
|
16
17
|
const Bar = styled_1.default.div `
|
|
17
18
|
width: 100%;
|
|
@@ -34,6 +35,7 @@ const Numbers = styled_1.default.div `
|
|
|
34
35
|
flex-flow: row;
|
|
35
36
|
justify-content: space-between;
|
|
36
37
|
z-index: 1;
|
|
38
|
+
|
|
37
39
|
> span {
|
|
38
40
|
background-color: var(--main-bg);
|
|
39
41
|
}
|
|
@@ -44,13 +46,19 @@ const Items = styled_1.default.div `
|
|
|
44
46
|
flex-flow: row wrap;
|
|
45
47
|
position: relative;
|
|
46
48
|
justify-content: space-between;
|
|
49
|
+
margin-top: 0.5rem;
|
|
47
50
|
`;
|
|
48
51
|
const Item = styled_1.default.div `
|
|
49
52
|
display: flex;
|
|
50
53
|
flex-flow: row;
|
|
51
54
|
position: relative;
|
|
52
55
|
align-items: center;
|
|
53
|
-
|
|
56
|
+
&:not(:first-of-type) {
|
|
57
|
+
padding-left: 0.5rem;
|
|
58
|
+
}
|
|
59
|
+
&:not(:last-of-type) {
|
|
60
|
+
padding-right: 0.5rem;
|
|
61
|
+
}
|
|
54
62
|
`;
|
|
55
63
|
const Col = styled_1.default.div `
|
|
56
64
|
width: 1rem;
|
|
@@ -58,38 +66,31 @@ const Col = styled_1.default.div `
|
|
|
58
66
|
border-radius: 50%;
|
|
59
67
|
margin-right: 0.25rem;
|
|
60
68
|
`;
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
const values = Object.values(val);
|
|
72
|
-
const legendItems = (0, array_1.take)(values, 3).part.map((v) => ({
|
|
73
|
-
colour: v.colour,
|
|
74
|
-
name: v.name,
|
|
75
|
-
}));
|
|
76
|
-
return legendItems;
|
|
77
|
-
};
|
|
78
|
-
const Legend = ({ data, lt, colours, }) => {
|
|
79
|
-
const legendItems = legendItemsKeys({ data, colours });
|
|
69
|
+
const LegendX = ({ data, lt, tt, colours, }) => {
|
|
70
|
+
const legendItems = (0, getLegendItems_1.getLegendItems)({
|
|
71
|
+
data,
|
|
72
|
+
colours,
|
|
73
|
+
fixed: true,
|
|
74
|
+
lt,
|
|
75
|
+
tt,
|
|
76
|
+
}).part;
|
|
80
77
|
const xs = data.map((a) => a.x);
|
|
78
|
+
const ys = data.map((a) => a.y);
|
|
81
79
|
const minX = Math.min(...xs);
|
|
82
80
|
const maxX = Math.max(...xs);
|
|
81
|
+
const maxY = Math.max(...ys);
|
|
83
82
|
const itemsRaw = [minX];
|
|
84
|
-
const
|
|
83
|
+
const gc = 8;
|
|
84
|
+
const gap = (maxX - minX) / gc;
|
|
85
85
|
if (gap > common_1.twelveHMs) {
|
|
86
|
-
for (let a = 1; a <
|
|
86
|
+
for (let a = 1; a < gc; a += 1) {
|
|
87
87
|
itemsRaw.push(itemsRaw[a - 1] + gap);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
itemsRaw.push(maxX);
|
|
91
91
|
const items = itemsRaw.map((d) => { var _a; return (_a = lt(d)) !== null && _a !== void 0 ? _a : d; });
|
|
92
|
-
|
|
92
|
+
const ch = maxY.toString().length + 1;
|
|
93
|
+
return (react_1.default.createElement(Base, { style: { marginLeft: 'auto', width: `calc(100% - ${ch}ch)` } },
|
|
93
94
|
react_1.default.createElement(Bar, null,
|
|
94
95
|
react_1.default.createElement(Line, null),
|
|
95
96
|
react_1.default.createElement(Numbers, null, items.map((i, i2) => (
|
|
@@ -99,4 +100,4 @@ const Legend = ({ data, lt, colours, }) => {
|
|
|
99
100
|
react_1.default.createElement(Col, { style: { backgroundColor: k.colour } }),
|
|
100
101
|
k.name)))))));
|
|
101
102
|
};
|
|
102
|
-
exports.
|
|
103
|
+
exports.LegendX = LegendX;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LegendY = void 0;
|
|
7
|
+
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const Base = styled_1.default.div `
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-flow: row;
|
|
12
|
+
width: 100%;
|
|
13
|
+
`;
|
|
14
|
+
const Numbers = styled_1.default.div `
|
|
15
|
+
width: 100%;
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-flow: column-reverse;
|
|
18
|
+
justify-content: space-between;
|
|
19
|
+
z-index: 1;
|
|
20
|
+
> span {
|
|
21
|
+
color: var(--main-fg);
|
|
22
|
+
background-color: var(--main-bg);
|
|
23
|
+
text-align: right;
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
const LegendY = ({ data }) => {
|
|
27
|
+
const ys = data.map((a) => a.y);
|
|
28
|
+
const minY = Math.min(...ys);
|
|
29
|
+
const maxY = Math.max(...ys);
|
|
30
|
+
const items = [minY];
|
|
31
|
+
const gc = 3;
|
|
32
|
+
const gap = (maxY - minY) / gc;
|
|
33
|
+
for (let a = 1; a < gc; a += 1) {
|
|
34
|
+
items.push(Math.floor(items[a - 1] + gap));
|
|
35
|
+
}
|
|
36
|
+
items.push(maxY);
|
|
37
|
+
const ch = maxY.toString().length;
|
|
38
|
+
return (react_1.default.createElement(Base, { style: { maxWidth: `${ch}ch`, paddingRight: '1ch' } },
|
|
39
|
+
react_1.default.createElement(Numbers, null, items.map((i, i2) => (
|
|
40
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
41
|
+
react_1.default.createElement("span", { key: i + i2 }, i))))));
|
|
42
|
+
};
|
|
43
|
+
exports.LegendY = LegendY;
|
|
@@ -10,4 +10,7 @@ export interface ILegendItems {
|
|
|
10
10
|
restTotal: number;
|
|
11
11
|
total: number;
|
|
12
12
|
}
|
|
13
|
-
export declare const getLegendItems: (p: ILineChartTooltip
|
|
13
|
+
export declare const getLegendItems: (p: ILineChartTooltip & {
|
|
14
|
+
/** if true, will only return top items */
|
|
15
|
+
fixed: boolean;
|
|
16
|
+
}) => ILegendItems;
|
|
@@ -3,17 +3,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getLegendItems = void 0;
|
|
4
4
|
const array_1 = require("../../../common/helpers/array");
|
|
5
5
|
const math_1 = require("../../../common/helpers/math");
|
|
6
|
+
const shownResults = 4;
|
|
7
|
+
const getTopItems = ({ data, colours, }) => {
|
|
8
|
+
const val = {};
|
|
9
|
+
data.forEach((d) => {
|
|
10
|
+
if (!val[d.name]) {
|
|
11
|
+
val[d.name] = { colour: colours[d.name], name: d.name, value: d.y };
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
val[d.name].value += d.y;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const values = Object.values(val).sort((a, b) => a.value < b.value ? 1 : -1);
|
|
18
|
+
const legendItems = (0, array_1.take)(values, shownResults).part.map((v) => ({
|
|
19
|
+
colour: v.colour,
|
|
20
|
+
name: v.name,
|
|
21
|
+
y: v.value,
|
|
22
|
+
x: 0,
|
|
23
|
+
}));
|
|
24
|
+
return legendItems;
|
|
25
|
+
};
|
|
6
26
|
const getLegendItems = (p) => {
|
|
7
27
|
var _a, _b;
|
|
8
|
-
|
|
28
|
+
let values = (_b = (_a = p.selectedXs) === null || _a === void 0 ? void 0 : _a.map((a) => ({
|
|
9
29
|
colour: p.colours[a.name],
|
|
10
30
|
name: a.name,
|
|
11
31
|
y: a.y,
|
|
12
32
|
x: a.x,
|
|
13
33
|
}))) !== null && _b !== void 0 ? _b : [];
|
|
34
|
+
if (p.fixed || values.length === 0) {
|
|
35
|
+
values = getTopItems(p);
|
|
36
|
+
}
|
|
14
37
|
const total = (0, math_1.sumArray)(values.map((a) => a.y));
|
|
15
38
|
const min = total * 0.1;
|
|
16
|
-
const shownResults = 4;
|
|
17
39
|
let part = values.sort((a, b) => (a.y < b.y ? 1 : -1));
|
|
18
40
|
let rest = [];
|
|
19
41
|
if (part.length > shownResults) {
|
package/package.json
CHANGED