ag-common 0.0.698 → 0.0.700
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/BarChart/Base.js +1 -1
- package/dist/ui/components/Modal/Modal.d.ts +1 -1
- package/dist/ui/components/Modal/Modal.js +4 -2
- package/dist/ui/components/TreeChart/TooltipContent.d.ts +7 -0
- package/dist/ui/components/TreeChart/TooltipContent.js +33 -0
- package/dist/ui/components/TreeChart/base.js +35 -13
- package/dist/ui/components/TreeChart/helpers.d.ts +1 -11
- package/dist/ui/components/TreeChart/helpers.js +10 -20
- package/dist/ui/components/TreeChart/types.d.ts +4 -1
- package/dist/ui/helpers/useTooltip.d.ts +13 -9
- package/dist/ui/helpers/useTooltip.js +27 -18
- package/package.json +1 -1
|
@@ -31,7 +31,7 @@ const BarChart = ({ data: dataRaw, style: sRaw, className, }) => {
|
|
|
31
31
|
const UT = (0, useTooltip_1.useTooltip)();
|
|
32
32
|
const maxWidth = Math.max(...dataRaw.map((a) => a.total));
|
|
33
33
|
return (react_1.default.createElement(BarChartBase, { "data-type": "bcb", style: style, className: className },
|
|
34
|
-
react_1.default.createElement(UT.Comp, { pos: UT.pos }, (
|
|
34
|
+
react_1.default.createElement(UT.Comp, { pos: UT.pos }, ({ data }) => react_1.default.createElement(TooltipContent_1.TooltipContent, Object.assign({}, data, { style: style }))),
|
|
35
35
|
dataRaw.map((data) => (react_1.default.createElement(ItemStyled, { style: style, key: data.name, data: data, maxWidth: maxWidth, onMouseLeave: () => UT.setPos(undefined), onMouseMove: (element) => {
|
|
36
36
|
var _a, _b;
|
|
37
37
|
const selectedKey = (_b = (_a = document
|
|
@@ -4,4 +4,4 @@ export declare const ModalItem: import("@emotion/styled").StyledComponent<{
|
|
|
4
4
|
theme?: import("@emotion/react").Theme | undefined;
|
|
5
5
|
as?: React.ElementType<any, keyof React.JSX.IntrinsicElements> | undefined;
|
|
6
6
|
}, React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
7
|
-
export declare const Modal: (
|
|
7
|
+
export declare const Modal: (p: IModal) => React.JSX.Element | null;
|
|
@@ -31,6 +31,7 @@ exports.Modal = exports.ModalItem = void 0;
|
|
|
31
31
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
32
32
|
const react_1 = __importStar(require("react"));
|
|
33
33
|
const react_dom_1 = require("react-dom");
|
|
34
|
+
const dom_1 = require("../../helpers/dom");
|
|
34
35
|
const useOnClickOutside_1 = require("../../helpers/useOnClickOutside");
|
|
35
36
|
const styles_1 = require("../../styles");
|
|
36
37
|
const Close_1 = require("../Close");
|
|
@@ -85,7 +86,8 @@ exports.ModalItem = styled_1.default.div `
|
|
|
85
86
|
const CloseStyled = (0, styled_1.default)(Close_1.Close) `
|
|
86
87
|
z-index: 1;
|
|
87
88
|
`;
|
|
88
|
-
const Modal = (
|
|
89
|
+
const Modal = (p) => {
|
|
90
|
+
const { open, setOpen, children, position = 'left', topPosition = 'top', showCloseButton = true, closeOnMoveMouseOutside = false, className, closeOnClickOutside = true, portalId: pidraw, style, } = p;
|
|
89
91
|
let portalId = pidraw;
|
|
90
92
|
if (portalId === undefined) {
|
|
91
93
|
portalId = globalId;
|
|
@@ -158,7 +160,7 @@ const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top'
|
|
|
158
160
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
159
161
|
}
|
|
160
162
|
const Content = (react_1.default.createElement(FixedBackground, null,
|
|
161
|
-
react_1.default.createElement(ModalBase, { "data-bounced": bounced, "data-position": position, "data-topposition": topPosition, ref: ref, className: className, style: style },
|
|
163
|
+
react_1.default.createElement(ModalBase, Object.assign({}, (0, dom_1.filterDataProps)(p), { "data-bounced": bounced, "data-position": position, "data-topposition": topPosition, ref: ref, className: className, style: style }),
|
|
162
164
|
showCloseButton && (react_1.default.createElement(CloseStyled, { "data-type": "modal-close", onClick: (e) => setOpen(false, e) })),
|
|
163
165
|
children)));
|
|
164
166
|
if (portalId && portalElem === undefined) {
|
|
@@ -0,0 +1,33 @@
|
|
|
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.TooltipContent = 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
|
+
padding: 0.5rem;
|
|
11
|
+
border: solid 1px black;
|
|
12
|
+
background-color: white;
|
|
13
|
+
`;
|
|
14
|
+
const Title = styled_1.default.div `
|
|
15
|
+
font-weight: bold;
|
|
16
|
+
`;
|
|
17
|
+
const TooltipContent = ({ data, node, head, }) => {
|
|
18
|
+
var _a;
|
|
19
|
+
let rows = [];
|
|
20
|
+
let n = node;
|
|
21
|
+
while (n) {
|
|
22
|
+
const t = ((_a = data.titleFn) === null || _a === void 0 ? void 0 : _a.call(data, {
|
|
23
|
+
path: n.name,
|
|
24
|
+
pathCount: n.size,
|
|
25
|
+
fullCount: head.size,
|
|
26
|
+
})) || `${n.name} (${n.size}/${head.size})`;
|
|
27
|
+
rows = [t, ...rows];
|
|
28
|
+
n = n.parent;
|
|
29
|
+
}
|
|
30
|
+
return (react_1.default.createElement(Base, null,
|
|
31
|
+
react_1.default.createElement(Title, null, rows.map((r, i) => (react_1.default.createElement("div", { key: r, style: { marginLeft: `${i * 2}px` } }, r))))));
|
|
32
|
+
};
|
|
33
|
+
exports.TooltipContent = TooltipContent;
|
|
@@ -31,9 +31,11 @@ exports.TreeChart = void 0;
|
|
|
31
31
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
32
32
|
const react_1 = __importStar(require("react"));
|
|
33
33
|
const useResize_1 = require("../../helpers/useResize");
|
|
34
|
+
const useTooltip_1 = require("../../helpers/useTooltip");
|
|
34
35
|
const styles_1 = require("../../styles");
|
|
35
36
|
const common_1 = require("../../styles/common");
|
|
36
37
|
const helpers_1 = require("./helpers");
|
|
38
|
+
const TooltipContent_1 = require("./TooltipContent");
|
|
37
39
|
const Base = styled_1.default.div `
|
|
38
40
|
border: solid 1px #ccc;
|
|
39
41
|
max-height: 100%;
|
|
@@ -68,28 +70,38 @@ const Title = styled_1.default.div `
|
|
|
68
70
|
min-height: 1rem;
|
|
69
71
|
line-height: 1rem;
|
|
70
72
|
`;
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
const leaf =
|
|
73
|
+
const Render = ({ n, depth, head, headDim, tnd, UT, }) => {
|
|
74
|
+
const children = Object.values(n.children);
|
|
75
|
+
const leaf = children.length === 0;
|
|
74
76
|
const sizeMult = n.size / head.size;
|
|
75
77
|
const biggerDim = Math.max(headDim.width, headDim.height);
|
|
76
78
|
const nodeSize = Math.floor(biggerDim * sizeMult).toString();
|
|
77
|
-
const title = ((_a = tnd.titleFn) === null || _a === void 0 ? void 0 : _a.call(tnd, {
|
|
78
|
-
path: n.name,
|
|
79
|
-
pathCount: n.size,
|
|
80
|
-
fullCount: head.size,
|
|
81
|
-
})) || `${n.name} (${n.size}/${head.size})`;
|
|
82
79
|
return (react_1.default.createElement(Node, { "data-treenode": true, "data-leaf": leaf.toString(), style: Object.assign({ backgroundColor: (0, styles_1.getColourWheel)(depth) }, (leaf &&
|
|
83
80
|
nodeSize && {
|
|
84
81
|
width: nodeSize + 'px',
|
|
85
82
|
height: nodeSize + 'px',
|
|
86
|
-
})), key: n.name, "data-ch": n.children.length, "data-size": n.size,
|
|
83
|
+
})), key: n.name, "data-ch": n.children.length, "data-size": n.size, onMouseLeave: () => UT.setPos(undefined), onMouseMove: (element) => {
|
|
84
|
+
UT.setPos({
|
|
85
|
+
element,
|
|
86
|
+
parent: null,
|
|
87
|
+
data: { data: tnd, node: n, head },
|
|
88
|
+
});
|
|
89
|
+
element.preventDefault();
|
|
90
|
+
element.stopPropagation();
|
|
91
|
+
} },
|
|
87
92
|
n.name && react_1.default.createElement(Title, null, n.name),
|
|
88
|
-
|
|
93
|
+
children.length > 0 && (react_1.default.createElement(NodeChildren, { "data-type": "nc" }, children.map((c) => Render({
|
|
94
|
+
UT,
|
|
95
|
+
n: c,
|
|
96
|
+
depth: depth + 1,
|
|
97
|
+
head,
|
|
98
|
+
headDim,
|
|
99
|
+
tnd,
|
|
100
|
+
}))))));
|
|
89
101
|
};
|
|
90
102
|
const TreeChart = (tnd) => {
|
|
91
|
-
const
|
|
92
|
-
const head = (0, helpers_1.
|
|
103
|
+
const UT = (0, useTooltip_1.useTooltip)();
|
|
104
|
+
const head = (0, helpers_1.convertToRaw)({ tnd });
|
|
93
105
|
const pd = (0, useResize_1.useResize)();
|
|
94
106
|
const [headDim, setHeadDim] = (0, react_1.useState)();
|
|
95
107
|
const r = (0, react_1.useRef)(null);
|
|
@@ -107,6 +119,16 @@ const TreeChart = (tnd) => {
|
|
|
107
119
|
if (head.size === 0) {
|
|
108
120
|
return react_1.default.createElement("div", null);
|
|
109
121
|
}
|
|
110
|
-
return (react_1.default.createElement(Base, { ref: r, className: tnd.className, style: tnd.style },
|
|
122
|
+
return (react_1.default.createElement(Base, { ref: r, className: tnd.className, style: tnd.style },
|
|
123
|
+
react_1.default.createElement(UT.Comp, { pos: UT.pos }, ({ data }) => react_1.default.createElement(TooltipContent_1.TooltipContent, Object.assign({}, data))),
|
|
124
|
+
headDim &&
|
|
125
|
+
Render({
|
|
126
|
+
UT,
|
|
127
|
+
tnd,
|
|
128
|
+
n: head,
|
|
129
|
+
depth: 0,
|
|
130
|
+
head,
|
|
131
|
+
headDim,
|
|
132
|
+
})));
|
|
111
133
|
};
|
|
112
134
|
exports.TreeChart = TreeChart;
|
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
import type { TreeNodeData, TreeNodeOut } from './types';
|
|
2
|
-
interface TreeNodeRaw {
|
|
3
|
-
name: string;
|
|
4
|
-
size: number;
|
|
5
|
-
depth: number;
|
|
6
|
-
children: {
|
|
7
|
-
[P in string]: TreeNodeRaw;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
2
|
export declare const convertToRaw: ({ tnd: { data, pathDelimiter }, }: {
|
|
11
3
|
tnd: TreeNodeData;
|
|
12
|
-
}) =>
|
|
13
|
-
export declare const toArray: (name: string, raw: TreeNodeRaw) => TreeNodeOut;
|
|
14
|
-
export {};
|
|
4
|
+
}) => TreeNodeOut;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.convertToRaw = void 0;
|
|
4
4
|
const convertToRaw = ({ tnd: { data, pathDelimiter }, }) => {
|
|
5
5
|
if (data.length === 0) {
|
|
6
|
-
return { children: {}, size: 0, name: '', depth: 0 };
|
|
6
|
+
return { children: {}, size: 0, name: '', depth: 0, parent: undefined };
|
|
7
7
|
}
|
|
8
|
-
const dm = {
|
|
8
|
+
const dm = {
|
|
9
|
+
size: 0,
|
|
10
|
+
children: {},
|
|
11
|
+
name: '',
|
|
12
|
+
depth: 0,
|
|
13
|
+
parent: undefined,
|
|
14
|
+
};
|
|
9
15
|
data.forEach((line) => {
|
|
10
16
|
const names = line.path.split(pathDelimiter || '/');
|
|
11
17
|
let node = dm;
|
|
@@ -23,6 +29,7 @@ const convertToRaw = ({ tnd: { data, pathDelimiter }, }) => {
|
|
|
23
29
|
size: 0,
|
|
24
30
|
name: names[a],
|
|
25
31
|
depth: a,
|
|
32
|
+
parent: node,
|
|
26
33
|
};
|
|
27
34
|
}
|
|
28
35
|
node = node.children[names[a]];
|
|
@@ -32,20 +39,3 @@ const convertToRaw = ({ tnd: { data, pathDelimiter }, }) => {
|
|
|
32
39
|
return dm;
|
|
33
40
|
};
|
|
34
41
|
exports.convertToRaw = convertToRaw;
|
|
35
|
-
const toArrayAux = (name, n) => ({
|
|
36
|
-
name,
|
|
37
|
-
size: n.size,
|
|
38
|
-
depth: n.depth,
|
|
39
|
-
children: Object.entries(n.children).map(([cn, cv]) => toArrayAux(cn, cv)),
|
|
40
|
-
});
|
|
41
|
-
const toArray = (name, raw) => {
|
|
42
|
-
const arr = toArrayAux(name, {
|
|
43
|
-
children: raw.children,
|
|
44
|
-
size: 0,
|
|
45
|
-
name: '',
|
|
46
|
-
depth: 0,
|
|
47
|
-
});
|
|
48
|
-
arr.size = arr.children.map((d) => d.size).reduce((a, b) => a + b, 0);
|
|
49
|
-
return arr;
|
|
50
|
-
};
|
|
51
|
-
exports.toArray = toArray;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { MouseEvent } from 'react';
|
|
2
|
-
import React from 'react';
|
|
3
2
|
interface IPos<T> {
|
|
4
3
|
cursor: MouseEvent;
|
|
5
4
|
data: T;
|
|
@@ -10,20 +9,25 @@ interface IPos<T> {
|
|
|
10
9
|
x: number;
|
|
11
10
|
y: number;
|
|
12
11
|
}
|
|
13
|
-
|
|
12
|
+
interface IPosSize {
|
|
13
|
+
tooltipWidth: number;
|
|
14
|
+
tooltipHeight: number;
|
|
15
|
+
}
|
|
16
|
+
type ITooltipProps = {
|
|
14
17
|
/** default 'ag-tooltip-portal' */
|
|
15
18
|
portalId: string;
|
|
16
19
|
};
|
|
17
|
-
export
|
|
18
|
-
Comp: <
|
|
19
|
-
pos: IPos<
|
|
20
|
-
children: (
|
|
21
|
-
}) =>
|
|
20
|
+
export interface IUseTooltip<T> {
|
|
21
|
+
Comp: <T>({ pos, children, }: {
|
|
22
|
+
pos: IPos<T> | undefined;
|
|
23
|
+
children: (pos: IPos<T>, size?: IPosSize) => JSX.Element;
|
|
24
|
+
}) => JSX.Element | null;
|
|
22
25
|
setPos: (p?: {
|
|
23
26
|
element: MouseEvent;
|
|
24
27
|
parent: Element | null;
|
|
25
28
|
data: T;
|
|
26
|
-
}) => void;
|
|
29
|
+
} | undefined) => void;
|
|
27
30
|
pos: IPos<T> | undefined;
|
|
28
|
-
}
|
|
31
|
+
}
|
|
32
|
+
export declare const useTooltip: <T>(p?: ITooltipProps) => IUseTooltip<T>;
|
|
29
33
|
export {};
|
|
@@ -38,23 +38,20 @@ const Comp = ({ pos, children, }) => {
|
|
|
38
38
|
const ref = (0, react_1.createRef)();
|
|
39
39
|
const [size, setSize] = (0, react_1.useState)();
|
|
40
40
|
(0, react_1.useEffect)(() => {
|
|
41
|
-
var _a, _b;
|
|
42
41
|
if (!ref.current) {
|
|
43
42
|
return;
|
|
44
43
|
}
|
|
45
44
|
const tooltipWidth = Math.max(ref.current.clientWidth, ref.current.scrollWidth);
|
|
46
45
|
const tooltipHeight = Math.max(ref.current.clientHeight, ref.current.scrollHeight);
|
|
47
|
-
if (tooltipHeight === (
|
|
48
|
-
tooltipWidth === (
|
|
46
|
+
if (tooltipHeight === (size === null || size === void 0 ? void 0 : size.tooltipHeight) ||
|
|
47
|
+
tooltipWidth === (size === null || size === void 0 ? void 0 : size.tooltipWidth) ||
|
|
49
48
|
tooltipHeight === 0 ||
|
|
50
49
|
tooltipWidth === 0) {
|
|
51
50
|
return;
|
|
52
51
|
}
|
|
53
52
|
setSize({
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
tooltipHeight,
|
|
57
|
-
},
|
|
53
|
+
tooltipWidth,
|
|
54
|
+
tooltipHeight,
|
|
58
55
|
});
|
|
59
56
|
}, [ref, size]);
|
|
60
57
|
if (!pos) {
|
|
@@ -65,32 +62,36 @@ const Comp = ({ pos, children, }) => {
|
|
|
65
62
|
let top;
|
|
66
63
|
let bottom;
|
|
67
64
|
const gap = 5;
|
|
68
|
-
if (size
|
|
65
|
+
if (size) {
|
|
69
66
|
left = pos.x + gap;
|
|
70
67
|
const newRight = pos.parentWidth - pos.x + gap;
|
|
71
|
-
if (pos.x + gap + size.
|
|
68
|
+
if (pos.x + gap + size.tooltipWidth > pos.parentWidth) {
|
|
72
69
|
left = undefined;
|
|
73
70
|
right = newRight;
|
|
74
71
|
}
|
|
75
72
|
//
|
|
76
73
|
top = pos.y + gap;
|
|
77
|
-
if (top + size.
|
|
74
|
+
if (top + size.tooltipHeight > pos.parentHeight) {
|
|
78
75
|
top = undefined;
|
|
79
76
|
bottom = pos.parentHeight - pos.y;
|
|
80
77
|
}
|
|
81
|
-
if (right && right + size.
|
|
82
|
-
|
|
78
|
+
if (right && right + size.tooltipWidth > pos.parentWidth) {
|
|
79
|
+
if (!pos.usePortal) {
|
|
80
|
+
right = undefined;
|
|
81
|
+
}
|
|
83
82
|
left = 0;
|
|
84
83
|
}
|
|
85
|
-
if (bottom && bottom + size.
|
|
86
|
-
|
|
84
|
+
if (bottom && bottom + size.tooltipHeight > pos.parentHeight) {
|
|
85
|
+
if (!pos.usePortal) {
|
|
86
|
+
bottom = undefined;
|
|
87
|
+
}
|
|
87
88
|
top = 0;
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
|
-
const Content = (react_1.default.createElement(Base, { ref: ref, style: Object.assign(Object.assign({ left,
|
|
91
|
+
const Content = (react_1.default.createElement(Base, { "data-type": "tooltip-content", ref: ref, style: Object.assign(Object.assign({ left,
|
|
91
92
|
right,
|
|
92
93
|
top,
|
|
93
|
-
bottom, zIndex: 10 }, (pos.usePortal && { position: 'fixed' })), (!
|
|
94
|
+
bottom, zIndex: 10, overflow: 'hidden' }, (pos.usePortal && { position: 'fixed' })), (!size && { zIndex: -1 })) }, children(pos, size)));
|
|
94
95
|
const e = document.querySelector(`#${pos.portalId}`);
|
|
95
96
|
if (pos.usePortal && e) {
|
|
96
97
|
return (0, react_dom_1.createPortal)(Content, e);
|
|
@@ -127,6 +128,8 @@ const useTooltip = (p) => {
|
|
|
127
128
|
let parentLeft = 0;
|
|
128
129
|
let parentWidth = document.body.clientWidth;
|
|
129
130
|
let parentHeight = document.body.clientHeight;
|
|
131
|
+
let x = 0;
|
|
132
|
+
let y = 0;
|
|
130
133
|
if (p.parent) {
|
|
131
134
|
({
|
|
132
135
|
top: parentTop,
|
|
@@ -134,9 +137,15 @@ const useTooltip = (p) => {
|
|
|
134
137
|
width: parentWidth,
|
|
135
138
|
height: parentHeight,
|
|
136
139
|
} = p.parent.getBoundingClientRect());
|
|
140
|
+
x = p.element.pageX - parentLeft;
|
|
141
|
+
y = p.element.pageY - parentTop;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
parentWidth = window.innerWidth;
|
|
145
|
+
parentHeight = window.innerHeight;
|
|
146
|
+
x = p.element.clientX;
|
|
147
|
+
y = p.element.clientY;
|
|
137
148
|
}
|
|
138
|
-
const x = p.element.pageX - parentLeft;
|
|
139
|
-
const y = p.element.pageY - parentTop;
|
|
140
149
|
const p2 = {
|
|
141
150
|
cursor: p.element,
|
|
142
151
|
data: p.data,
|
package/package.json
CHANGED