@semcore/d3-chart 2.2.1 → 2.2.4
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/CHANGELOG.md +21 -0
- package/README.md +2 -2
- package/lib/cjs/Area.js +9 -9
- package/lib/cjs/Area.js.map +1 -1
- package/lib/cjs/Axis.js +19 -17
- package/lib/cjs/Axis.js.map +1 -1
- package/lib/cjs/Bar.js +11 -11
- package/lib/cjs/Bar.js.map +1 -1
- package/lib/cjs/Bubble.js +12 -12
- package/lib/cjs/Bubble.js.map +1 -1
- package/lib/cjs/ClipPath.js +1 -1
- package/lib/cjs/ClipPath.js.map +1 -1
- package/lib/cjs/Donut.js +8 -8
- package/lib/cjs/Donut.js.map +1 -1
- package/lib/cjs/Dots.js +9 -9
- package/lib/cjs/Dots.js.map +1 -1
- package/lib/cjs/GroupBar.js +8 -8
- package/lib/cjs/GroupBar.js.map +1 -1
- package/lib/cjs/HorizontalBar.js +11 -11
- package/lib/cjs/HorizontalBar.js.map +1 -1
- package/lib/cjs/Hover.js +4 -4
- package/lib/cjs/Hover.js.map +1 -1
- package/lib/cjs/Line.js +8 -8
- package/lib/cjs/Line.js.map +1 -1
- package/lib/cjs/Plot.js +4 -4
- package/lib/cjs/Plot.js.map +1 -1
- package/lib/cjs/RadialTree.js +99 -59
- package/lib/cjs/RadialTree.js.map +1 -1
- package/lib/cjs/ReferenceLine.js +10 -10
- package/lib/cjs/ReferenceLine.js.map +1 -1
- package/lib/cjs/ResponsiveContainer.js +1 -1
- package/lib/cjs/ResponsiveContainer.js.map +1 -1
- package/lib/cjs/ScatterPlot.js +7 -7
- package/lib/cjs/ScatterPlot.js.map +1 -1
- package/lib/cjs/StackBar.js +8 -8
- package/lib/cjs/StackBar.js.map +1 -1
- package/lib/cjs/StackedArea.js +8 -8
- package/lib/cjs/StackedArea.js.map +1 -1
- package/lib/cjs/Tooltip.js +15 -11
- package/lib/cjs/Tooltip.js.map +1 -1
- package/lib/cjs/Venn.js +9 -9
- package/lib/cjs/Venn.js.map +1 -1
- package/lib/cjs/color.js.map +1 -1
- package/lib/cjs/createElement.js +3 -2
- package/lib/cjs/createElement.js.map +1 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/style/radial-tree.shadow.css +0 -1
- package/lib/cjs/types/index.d.ts +3 -0
- package/lib/cjs/utils.js.map +1 -1
- package/lib/es6/Area.js +9 -9
- package/lib/es6/Area.js.map +1 -1
- package/lib/es6/Axis.js +19 -17
- package/lib/es6/Axis.js.map +1 -1
- package/lib/es6/Bar.js +11 -11
- package/lib/es6/Bar.js.map +1 -1
- package/lib/es6/Bubble.js +12 -12
- package/lib/es6/Bubble.js.map +1 -1
- package/lib/es6/ClipPath.js +1 -1
- package/lib/es6/ClipPath.js.map +1 -1
- package/lib/es6/Donut.js +8 -8
- package/lib/es6/Donut.js.map +1 -1
- package/lib/es6/Dots.js +9 -9
- package/lib/es6/Dots.js.map +1 -1
- package/lib/es6/GroupBar.js +8 -8
- package/lib/es6/GroupBar.js.map +1 -1
- package/lib/es6/HorizontalBar.js +11 -11
- package/lib/es6/HorizontalBar.js.map +1 -1
- package/lib/es6/Hover.js +4 -4
- package/lib/es6/Hover.js.map +1 -1
- package/lib/es6/Line.js +8 -8
- package/lib/es6/Line.js.map +1 -1
- package/lib/es6/Plot.js +4 -4
- package/lib/es6/Plot.js.map +1 -1
- package/lib/es6/RadialTree.js +99 -59
- package/lib/es6/RadialTree.js.map +1 -1
- package/lib/es6/ReferenceLine.js +10 -10
- package/lib/es6/ReferenceLine.js.map +1 -1
- package/lib/es6/ResponsiveContainer.js +1 -1
- package/lib/es6/ResponsiveContainer.js.map +1 -1
- package/lib/es6/ScatterPlot.js +7 -7
- package/lib/es6/ScatterPlot.js.map +1 -1
- package/lib/es6/StackBar.js +8 -8
- package/lib/es6/StackBar.js.map +1 -1
- package/lib/es6/StackedArea.js +8 -8
- package/lib/es6/StackedArea.js.map +1 -1
- package/lib/es6/Tooltip.js +15 -11
- package/lib/es6/Tooltip.js.map +1 -1
- package/lib/es6/Venn.js +9 -9
- package/lib/es6/Venn.js.map +1 -1
- package/lib/es6/color.js.map +1 -1
- package/lib/es6/createElement.js +3 -2
- package/lib/es6/createElement.js.map +1 -1
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/style/radial-tree.shadow.css +0 -1
- package/lib/es6/types/index.d.ts +3 -0
- package/lib/es6/utils.js.map +1 -1
- package/lib/types/index.d.ts +3 -0
- package/package.json +1 -1
- package/src/Area.jsx +0 -137
- package/src/Axis.jsx +0 -314
- package/src/Bar.jsx +0 -149
- package/src/Bubble.jsx +0 -165
- package/src/ClipPath.jsx +0 -47
- package/src/Donut.jsx +0 -319
- package/src/Dots.jsx +0 -97
- package/src/GroupBar.jsx +0 -76
- package/src/HorizontalBar.jsx +0 -135
- package/src/Hover.jsx +0 -153
- package/src/Line.jsx +0 -89
- package/src/Plot.jsx +0 -79
- package/src/RadialTree.tsx +0 -767
- package/src/ReferenceLine.jsx +0 -146
- package/src/ResponsiveContainer.jsx +0 -84
- package/src/ScatterPlot.jsx +0 -112
- package/src/StackBar.jsx +0 -105
- package/src/StackedArea.jsx +0 -65
- package/src/Tooltip.jsx +0 -145
- package/src/Venn.jsx +0 -114
- package/src/color.js +0 -21
- package/src/createElement.jsx +0 -135
- package/src/index.js +0 -27
- package/src/style/area.shadow.css +0 -37
- package/src/style/axis.shadow.css +0 -85
- package/src/style/bar.shadow.css +0 -21
- package/src/style/bubble.shadow.css +0 -45
- package/src/style/donut.shadow.css +0 -24
- package/src/style/dot.shadow.css +0 -29
- package/src/style/hover.shadow.css +0 -9
- package/src/style/line.shadow.css +0 -29
- package/src/style/plot.shadow.css +0 -6
- package/src/style/radial-tree.shadow.css +0 -34
- package/src/style/reference-line.shadow.css +0 -37
- package/src/style/scatterplot.shadow.css +0 -27
- package/src/style/tooltip.shadow.css +0 -36
- package/src/style/var.css +0 -125
- package/src/style/venn.shadow.css +0 -29
- package/src/types/Area.d.ts +0 -48
- package/src/types/Axis.d.ts +0 -64
- package/src/types/Bar.d.ts +0 -52
- package/src/types/Bubble.d.ts +0 -32
- package/src/types/ClipPath.d.ts +0 -26
- package/src/types/Donut.d.ts +0 -46
- package/src/types/GroupBar.d.ts +0 -20
- package/src/types/HorizontalBar.d.ts +0 -29
- package/src/types/Hover.d.ts +0 -15
- package/src/types/Line.d.ts +0 -50
- package/src/types/Plot.d.ts +0 -16
- package/src/types/ReferenceLine.d.ts +0 -31
- package/src/types/ResponsiveContainer.d.ts +0 -20
- package/src/types/ScatterPlot.d.ts +0 -27
- package/src/types/StackBar.d.ts +0 -26
- package/src/types/StackedArea.d.ts +0 -26
- package/src/types/Tooltip.d.ts +0 -33
- package/src/types/Venn.d.ts +0 -45
- package/src/types/context.d.ts +0 -6
- package/src/types/index.d.ts +0 -56
- package/src/utils.ts +0 -227
package/src/Dots.jsx
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { bisector } from 'd3-array';
|
|
2
|
-
import React, { useCallback, useEffect, useState } from 'react';
|
|
3
|
-
import { sstyled } from '@semcore/core';
|
|
4
|
-
import { eventToPoint, invert } from './utils';
|
|
5
|
-
import createElement from './createElement';
|
|
6
|
-
import trottle from '@semcore/utils/lib/rafTrottle';
|
|
7
|
-
|
|
8
|
-
import style from './style/dot.shadow.css';
|
|
9
|
-
|
|
10
|
-
const EXCLUDE_PROPS = ['data', 'scale', 'value', 'display'];
|
|
11
|
-
|
|
12
|
-
function Dots(props) {
|
|
13
|
-
const {
|
|
14
|
-
Element: SDot,
|
|
15
|
-
styles,
|
|
16
|
-
data,
|
|
17
|
-
color,
|
|
18
|
-
d3,
|
|
19
|
-
x,
|
|
20
|
-
y,
|
|
21
|
-
eventEmitter,
|
|
22
|
-
display,
|
|
23
|
-
hide,
|
|
24
|
-
rootRef,
|
|
25
|
-
scale,
|
|
26
|
-
duration = 500,
|
|
27
|
-
} = props;
|
|
28
|
-
const SDots = 'g';
|
|
29
|
-
const bisect = bisector((d) => d[x]).center;
|
|
30
|
-
const [activeIndex, setActiveIndex] = useState(null);
|
|
31
|
-
|
|
32
|
-
const handlerMouseMoveRoot = useCallback(
|
|
33
|
-
trottle((e) => {
|
|
34
|
-
const [xScale] = scale;
|
|
35
|
-
const [pX] = eventToPoint(e, rootRef.current);
|
|
36
|
-
const vX = invert(xScale, pX);
|
|
37
|
-
setActiveIndex(bisect(data, vX));
|
|
38
|
-
}),
|
|
39
|
-
[scale, data],
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const handlerMouseLeaveRoot = useCallback(
|
|
43
|
-
trottle(() => {
|
|
44
|
-
setActiveIndex(null);
|
|
45
|
-
}),
|
|
46
|
-
[],
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
const unsubscribeMouseMoveRoot = eventEmitter.subscribe('onMouseMoveChart', (e) => {
|
|
51
|
-
e.persist();
|
|
52
|
-
handlerMouseMoveRoot(e);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const unsubscribeMouseLeaveRoot = eventEmitter.subscribe(
|
|
56
|
-
'onMouseLeaveChart',
|
|
57
|
-
handlerMouseLeaveRoot,
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
return () => {
|
|
61
|
-
unsubscribeMouseMoveRoot();
|
|
62
|
-
unsubscribeMouseLeaveRoot();
|
|
63
|
-
};
|
|
64
|
-
}, [eventEmitter, scale, data, x, y]);
|
|
65
|
-
|
|
66
|
-
const dots = data.reduce((acc, d, i) => {
|
|
67
|
-
const isPrev = d3.defined()(data[i - 1] || {});
|
|
68
|
-
const isNext = d3.defined()(data[i + 1] || {});
|
|
69
|
-
const active = i === activeIndex;
|
|
70
|
-
const visible = display || i === activeIndex || (!isPrev && !isNext);
|
|
71
|
-
if (!d3.defined()(d)) return acc;
|
|
72
|
-
if (!visible) return acc;
|
|
73
|
-
acc.push(
|
|
74
|
-
sstyled(styles)(
|
|
75
|
-
<SDot
|
|
76
|
-
key={i}
|
|
77
|
-
render="circle"
|
|
78
|
-
visible={visible}
|
|
79
|
-
__excludeProps={EXCLUDE_PROPS}
|
|
80
|
-
value={d}
|
|
81
|
-
index={i}
|
|
82
|
-
cx={d3.x()(d)}
|
|
83
|
-
cy={d3.y()(d)}
|
|
84
|
-
active={active}
|
|
85
|
-
hide={hide}
|
|
86
|
-
color={color}
|
|
87
|
-
/>,
|
|
88
|
-
),
|
|
89
|
-
);
|
|
90
|
-
return acc;
|
|
91
|
-
}, []);
|
|
92
|
-
return sstyled(styles)(<SDots use:duration={`${duration}ms`}>{dots}</SDots>);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
Dots.style = style;
|
|
96
|
-
|
|
97
|
-
export default createElement(Dots);
|
package/src/GroupBar.jsx
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Component } from '@semcore/core';
|
|
3
|
-
import getOriginChildren from '@semcore/utils/lib/getOriginChildren';
|
|
4
|
-
import createElement from './createElement';
|
|
5
|
-
import Bar from './Bar';
|
|
6
|
-
import HorizontalBar from './HorizontalBar';
|
|
7
|
-
|
|
8
|
-
import style from './style/bar.shadow.css';
|
|
9
|
-
|
|
10
|
-
class GroupBarRoot extends Component {
|
|
11
|
-
static displayName = 'GroupBar';
|
|
12
|
-
|
|
13
|
-
static style = style;
|
|
14
|
-
|
|
15
|
-
getScaleGroup() {
|
|
16
|
-
const { Children, scale, scaleGroup, x } = this.asProps;
|
|
17
|
-
// TODO: love that hack (by lsroman)
|
|
18
|
-
const xyScale = x ? scale[0] : scale[1];
|
|
19
|
-
|
|
20
|
-
if (scaleGroup) return scaleGroup;
|
|
21
|
-
|
|
22
|
-
const domain = React.Children.toArray(getOriginChildren(Children)).reduce((acc, child) => {
|
|
23
|
-
if (React.isValidElement(child) && child.type === GroupBar.Bar && !child.props.hide) {
|
|
24
|
-
acc.push(child.props.y);
|
|
25
|
-
}
|
|
26
|
-
if (
|
|
27
|
-
React.isValidElement(child) &&
|
|
28
|
-
child.type === GroupBar.HorizontalBar &&
|
|
29
|
-
!child.props.hide
|
|
30
|
-
) {
|
|
31
|
-
acc.push(child.props.x);
|
|
32
|
-
}
|
|
33
|
-
return acc;
|
|
34
|
-
}, []);
|
|
35
|
-
|
|
36
|
-
return xyScale
|
|
37
|
-
.copy()
|
|
38
|
-
.range([0, xyScale.bandwidth()])
|
|
39
|
-
.domain(domain)
|
|
40
|
-
.paddingInner(xyScale.paddingOuter())
|
|
41
|
-
.paddingOuter(0);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
getBarProps({ y }) {
|
|
45
|
-
const { x } = this.asProps;
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
offset: [this.scaleGroup(y), 0],
|
|
49
|
-
width: this.scaleGroup.bandwidth(),
|
|
50
|
-
x,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
getHorizontalBarProps({ x }) {
|
|
55
|
-
const { y } = this.asProps;
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
offset: [0, this.scaleGroup(x)],
|
|
59
|
-
height: this.scaleGroup.bandwidth(),
|
|
60
|
-
y,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
render() {
|
|
65
|
-
const Element = this.Element;
|
|
66
|
-
this.scaleGroup = this.getScaleGroup();
|
|
67
|
-
return <Element render="g" childrenPosition="inside" scaleGroup={this.scaleGroup} />;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const GroupBar = createElement(GroupBarRoot, {
|
|
72
|
-
Bar,
|
|
73
|
-
HorizontalBar,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
export default GroupBar;
|
package/src/HorizontalBar.jsx
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Component, sstyled } from '@semcore/core';
|
|
3
|
-
import uniqueIDEnhancement from '@semcore/utils/lib/uniqueID';
|
|
4
|
-
import createElement from './createElement';
|
|
5
|
-
import ClipPath from './ClipPath';
|
|
6
|
-
import { getBandwidth, roundedPath } from './utils';
|
|
7
|
-
|
|
8
|
-
import style from './style/bar.shadow.css';
|
|
9
|
-
|
|
10
|
-
class HorizontalBarRoot extends Component {
|
|
11
|
-
static displayName = 'HorizontalBar';
|
|
12
|
-
static enhance = [uniqueIDEnhancement()];
|
|
13
|
-
static style = style;
|
|
14
|
-
|
|
15
|
-
static defaultProps = {
|
|
16
|
-
offset: [0, 0],
|
|
17
|
-
duration: 500,
|
|
18
|
-
r: 2,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
getBackgroundProps(props, index) {
|
|
22
|
-
const { data, y } = this.asProps;
|
|
23
|
-
return {
|
|
24
|
-
value: data[index][y],
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
renderBar(d, i) {
|
|
29
|
-
const SBar = this.Element;
|
|
30
|
-
const {
|
|
31
|
-
styles,
|
|
32
|
-
color,
|
|
33
|
-
x,
|
|
34
|
-
x0,
|
|
35
|
-
y,
|
|
36
|
-
scale,
|
|
37
|
-
hide,
|
|
38
|
-
offset,
|
|
39
|
-
uid,
|
|
40
|
-
duration,
|
|
41
|
-
r,
|
|
42
|
-
height: heightProps,
|
|
43
|
-
onMouseMove,
|
|
44
|
-
onMouseLeave,
|
|
45
|
-
} = this.asProps;
|
|
46
|
-
|
|
47
|
-
const [xScale, yScale] = scale;
|
|
48
|
-
const barY = yScale(d[y]) + offset[1];
|
|
49
|
-
const barX = xScale(Math.min(d[x0] ?? 0, d[x])) + offset[0];
|
|
50
|
-
const height = heightProps || getBandwidth(yScale);
|
|
51
|
-
const width = Math.abs(xScale(d[x]) - Math.max(xScale(xScale.domain()[0]), xScale(d[x0] ?? 0)));
|
|
52
|
-
const dSvg = getHorizontalRect({
|
|
53
|
-
x: barX,
|
|
54
|
-
y: barY,
|
|
55
|
-
width,
|
|
56
|
-
height,
|
|
57
|
-
radius: Array.isArray(r) ? r[i] : r,
|
|
58
|
-
position: d[x] > 0 ? 'right' : 'left',
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
return sstyled(styles)(
|
|
62
|
-
<SBar
|
|
63
|
-
key={`horizontal-bar-${i}`}
|
|
64
|
-
render="path"
|
|
65
|
-
clipPath={`url(#${uid})`}
|
|
66
|
-
__excludeProps={['data', 'scale', 'value']}
|
|
67
|
-
childrenPosition="above"
|
|
68
|
-
value={d}
|
|
69
|
-
index={i}
|
|
70
|
-
hide={hide}
|
|
71
|
-
color={color}
|
|
72
|
-
x={barX}
|
|
73
|
-
y={barY}
|
|
74
|
-
width={width}
|
|
75
|
-
height={height}
|
|
76
|
-
d={dSvg}
|
|
77
|
-
use:duration={`${duration}ms`}
|
|
78
|
-
onMouseMove={onMouseMove}
|
|
79
|
-
onMouseLeave={onMouseLeave}
|
|
80
|
-
/>,
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
render() {
|
|
85
|
-
const { data, uid, size, duration } = this.asProps;
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<>
|
|
89
|
-
{data.map(this.renderBar.bind(this))}
|
|
90
|
-
{duration && (
|
|
91
|
-
<ClipPath
|
|
92
|
-
setAttributeTag={(rect) => {
|
|
93
|
-
rect.setAttribute('width', size[0]);
|
|
94
|
-
}}
|
|
95
|
-
id={uid}
|
|
96
|
-
x="0"
|
|
97
|
-
y="0"
|
|
98
|
-
width={0}
|
|
99
|
-
height={size[1]}
|
|
100
|
-
transition={`width ${duration}ms ease-in-out`}
|
|
101
|
-
/>
|
|
102
|
-
)}
|
|
103
|
-
</>
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function Background(props) {
|
|
109
|
-
const { Element: SBackground, styles, scale, value } = props;
|
|
110
|
-
const [xScale, yScale] = scale;
|
|
111
|
-
const xRange = xScale.range();
|
|
112
|
-
|
|
113
|
-
return sstyled(styles)(
|
|
114
|
-
<SBackground
|
|
115
|
-
render="rect"
|
|
116
|
-
childrenPosition="above"
|
|
117
|
-
width={xRange[1] - xRange[0]}
|
|
118
|
-
height={yScale.bandwidth()}
|
|
119
|
-
x={xRange[0]}
|
|
120
|
-
y={yScale(value)}
|
|
121
|
-
/>,
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function getHorizontalRect({ x, y, width, height, radius, position }) {
|
|
126
|
-
if (width <= radius) return '';
|
|
127
|
-
if (radius) {
|
|
128
|
-
if (position === 'right')
|
|
129
|
-
return roundedPath(x, y, width, height, radius, false, true, false, true);
|
|
130
|
-
return roundedPath(x, y, width, height, radius, true, false, true, false);
|
|
131
|
-
}
|
|
132
|
-
return roundedPath(x, y, width, height, radius);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export default createElement(HorizontalBarRoot, { Background });
|
package/src/Hover.jsx
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Component, sstyled } from '@semcore/core';
|
|
3
|
-
import createElement from './createElement';
|
|
4
|
-
import canUseDOM from '@semcore/utils/lib/canUseDOM';
|
|
5
|
-
import { scaleOfBandwidth, getIndexFromData, eventToPoint, invert, CONSTANT } from './utils';
|
|
6
|
-
import trottle from '@semcore/utils/lib/rafTrottle';
|
|
7
|
-
|
|
8
|
-
import style from './style/hover.shadow.css';
|
|
9
|
-
|
|
10
|
-
class Hover extends Component {
|
|
11
|
-
static style = style;
|
|
12
|
-
|
|
13
|
-
state = {
|
|
14
|
-
xIndex: null,
|
|
15
|
-
yIndex: null,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
virtualElement = canUseDOM() ? document.createElement('div') : {};
|
|
19
|
-
|
|
20
|
-
generateGetBoundingClientRect(x = 0, y = 0) {
|
|
21
|
-
return () => ({ width: 0, height: 0, top: y, right: x, bottom: y, left: x });
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
handlerMouseMoveRoot = trottle((e) => {
|
|
25
|
-
const { eventEmitter, data, scale, x, y, rootRef } = this.asProps;
|
|
26
|
-
const { clientX, clientY } = e;
|
|
27
|
-
const [xScale, yScale] = scale;
|
|
28
|
-
const [pX, pY] = eventToPoint(e, rootRef.current);
|
|
29
|
-
const vX = invert(xScale, pX);
|
|
30
|
-
const vY = invert(yScale, pY);
|
|
31
|
-
const xIndex =
|
|
32
|
-
x === undefined || vX === undefined ? null : getIndexFromData(data, xScale, x, vX);
|
|
33
|
-
const yIndex =
|
|
34
|
-
y === undefined || vY === undefined ? null : getIndexFromData(data, yScale, y, vY);
|
|
35
|
-
const state = { xIndex, yIndex };
|
|
36
|
-
this.virtualElement.getBoundingClientRect = this.generateGetBoundingClientRect(
|
|
37
|
-
clientX,
|
|
38
|
-
clientY,
|
|
39
|
-
);
|
|
40
|
-
this.virtualElement[CONSTANT.VIRTUAL_ELEMENT] = true;
|
|
41
|
-
|
|
42
|
-
this.setState(state, () => {
|
|
43
|
-
eventEmitter.emit(
|
|
44
|
-
'onTooltipVisible',
|
|
45
|
-
xIndex !== null || yIndex !== null,
|
|
46
|
-
state,
|
|
47
|
-
this.virtualElement,
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
handlerMouseLeaveRoot = trottle(() => {
|
|
53
|
-
const state = {
|
|
54
|
-
xIndex: null,
|
|
55
|
-
yIndex: null,
|
|
56
|
-
};
|
|
57
|
-
this.setState(state, () => {
|
|
58
|
-
this.asProps.eventEmitter.emit('onTooltipVisible', false, state);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
componentDidMount() {
|
|
63
|
-
const { eventEmitter } = this.asProps;
|
|
64
|
-
this.unsubscribeMouseMoveRoot = eventEmitter.subscribe('onMouseMoveChart', (e) => {
|
|
65
|
-
e.persist();
|
|
66
|
-
this.handlerMouseMoveRoot(e);
|
|
67
|
-
});
|
|
68
|
-
this.unsubscribeMouseLeaveRoot = eventEmitter.subscribe(
|
|
69
|
-
'onMouseLeaveChart',
|
|
70
|
-
this.handlerMouseLeaveRoot,
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
componentWillUnmount() {
|
|
75
|
-
if (this.unsubscribeMouseMoveRoot) {
|
|
76
|
-
this.unsubscribeMouseMoveRoot();
|
|
77
|
-
}
|
|
78
|
-
if (this.unsubscribeMouseLeaveRoot) {
|
|
79
|
-
this.unsubscribeMouseLeaveRoot();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
class HoverLineRoot extends Hover {
|
|
85
|
-
static displayName = 'HoverLine';
|
|
86
|
-
|
|
87
|
-
render() {
|
|
88
|
-
const SHoverLine = this.Element;
|
|
89
|
-
const { styles, x, y, data, scale } = this.asProps;
|
|
90
|
-
const { xIndex, yIndex } = this.state;
|
|
91
|
-
const [xScale, yScale] = scale;
|
|
92
|
-
|
|
93
|
-
const xRange = xScale.range();
|
|
94
|
-
const yRange = yScale.range();
|
|
95
|
-
const x1 = xIndex !== null ? scaleOfBandwidth(xScale, data[xIndex][x]) : undefined;
|
|
96
|
-
const y1 = yIndex !== null ? scaleOfBandwidth(yScale, data[yIndex][y]) : undefined;
|
|
97
|
-
|
|
98
|
-
return sstyled(styles)(
|
|
99
|
-
<>
|
|
100
|
-
{xIndex !== null ? (
|
|
101
|
-
<SHoverLine render="line" index={xIndex} x1={x1} y1={yRange[0]} x2={x1} y2={yRange[1]} />
|
|
102
|
-
) : null}
|
|
103
|
-
{yIndex !== null ? (
|
|
104
|
-
<SHoverLine render="line" index={yIndex} x1={xRange[0]} y1={y1} x2={xRange[1]} y2={y1} />
|
|
105
|
-
) : null}
|
|
106
|
-
</>,
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
class HoverRectRoot extends Hover {
|
|
112
|
-
static displayName = 'HoverRect';
|
|
113
|
-
|
|
114
|
-
render() {
|
|
115
|
-
const SHoverRect = this.Element;
|
|
116
|
-
const { styles, x, y, data, scale } = this.asProps;
|
|
117
|
-
const { xIndex, yIndex } = this.state;
|
|
118
|
-
const [xScale, yScale] = scale;
|
|
119
|
-
|
|
120
|
-
const xRange = xScale.range();
|
|
121
|
-
const yRange = yScale.range();
|
|
122
|
-
|
|
123
|
-
return sstyled(styles)(
|
|
124
|
-
<>
|
|
125
|
-
{xIndex !== null ? (
|
|
126
|
-
<SHoverRect
|
|
127
|
-
render="rect"
|
|
128
|
-
index={xIndex}
|
|
129
|
-
width={xScale.step() - xScale.paddingInner() / 2}
|
|
130
|
-
height={yRange[0] - yRange[1]}
|
|
131
|
-
x={xScale(data[xIndex][x]) - (xScale.step() * xScale.paddingInner()) / 2}
|
|
132
|
-
y={yRange[1]}
|
|
133
|
-
/>
|
|
134
|
-
) : null}
|
|
135
|
-
{yIndex !== null ? (
|
|
136
|
-
<SHoverRect
|
|
137
|
-
render="rect"
|
|
138
|
-
index={yIndex}
|
|
139
|
-
width={xRange[1] - xRange[0]}
|
|
140
|
-
height={yScale.step() - yScale.paddingInner() / 2}
|
|
141
|
-
x={xRange[0]}
|
|
142
|
-
y={yScale(data[yIndex][y]) - (yScale.step() * yScale.paddingInner()) / 2}
|
|
143
|
-
/>
|
|
144
|
-
) : null}
|
|
145
|
-
</>,
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const HoverLine = createElement(HoverLineRoot);
|
|
151
|
-
const HoverRect = createElement(HoverRectRoot);
|
|
152
|
-
|
|
153
|
-
export { HoverLine, HoverRect };
|
package/src/Line.jsx
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { curveLinear, line as d3Line } from 'd3-shape';
|
|
3
|
-
import { Component, sstyled } from '@semcore/core';
|
|
4
|
-
import createElement from './createElement';
|
|
5
|
-
import { definedData, definedNullData, scaleOfBandwidth, getNullData } from './utils';
|
|
6
|
-
import Dots from './Dots';
|
|
7
|
-
import ClipPath from './ClipPath';
|
|
8
|
-
import uniqueIDEnhancement from '@semcore/utils/lib/uniqueID';
|
|
9
|
-
|
|
10
|
-
import style from './style/line.shadow.css';
|
|
11
|
-
|
|
12
|
-
class LineRoot extends Component {
|
|
13
|
-
static displayName = 'Line';
|
|
14
|
-
static style = style;
|
|
15
|
-
static enhance = [uniqueIDEnhancement()];
|
|
16
|
-
|
|
17
|
-
static defaultProps = ({ x, y, $rootProps, curve = curveLinear, scale }) => {
|
|
18
|
-
const [xScale, yScale] = scale || $rootProps.scale;
|
|
19
|
-
return {
|
|
20
|
-
d3: d3Line()
|
|
21
|
-
.defined(definedData(x, y))
|
|
22
|
-
.curve(curve)
|
|
23
|
-
.x((p) => scaleOfBandwidth(xScale, p[x]))
|
|
24
|
-
.y((p) => scaleOfBandwidth(yScale, p[y])),
|
|
25
|
-
duration: 500,
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
getDotsProps() {
|
|
30
|
-
const { x, y, d3, color, duration } = this.asProps;
|
|
31
|
-
return {
|
|
32
|
-
x,
|
|
33
|
-
y,
|
|
34
|
-
d3,
|
|
35
|
-
color,
|
|
36
|
-
duration,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
getNullProps() {
|
|
41
|
-
const { x, y, d3, color, data } = this.asProps;
|
|
42
|
-
return {
|
|
43
|
-
d3,
|
|
44
|
-
// TODO: vertical
|
|
45
|
-
data: getNullData(data, definedNullData(x, y), y),
|
|
46
|
-
color,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
render() {
|
|
51
|
-
const SLine = this.Element;
|
|
52
|
-
const { styles, hide, color, uid, size, d3, data, duration } = this.asProps;
|
|
53
|
-
return sstyled(styles)(
|
|
54
|
-
<>
|
|
55
|
-
<SLine
|
|
56
|
-
clipPath={`url(#${uid})`}
|
|
57
|
-
render="path"
|
|
58
|
-
hide={hide}
|
|
59
|
-
color={color}
|
|
60
|
-
d={d3(data)}
|
|
61
|
-
use:duration={`${duration}ms`}
|
|
62
|
-
/>
|
|
63
|
-
{duration && (
|
|
64
|
-
<ClipPath
|
|
65
|
-
setAttributeTag={(rect) => {
|
|
66
|
-
rect.setAttribute('width', size[0]);
|
|
67
|
-
}}
|
|
68
|
-
id={uid}
|
|
69
|
-
x="0"
|
|
70
|
-
y="0"
|
|
71
|
-
width={0}
|
|
72
|
-
height={size[1]}
|
|
73
|
-
transition={`width ${duration}ms ease-in-out`}
|
|
74
|
-
/>
|
|
75
|
-
)}
|
|
76
|
-
</>,
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function Null(props) {
|
|
82
|
-
const { Element: SNull, styles, d3, data, hide } = props;
|
|
83
|
-
return sstyled(styles)(<SNull render="path" d={d3(data)} hide={hide} />);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export default createElement(LineRoot, {
|
|
87
|
-
Dots,
|
|
88
|
-
Null,
|
|
89
|
-
});
|
package/src/Plot.jsx
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import createComponent, { Component, Root, sstyled } from '@semcore/core';
|
|
3
|
-
import { Box } from '@semcore/flex-box';
|
|
4
|
-
import EventEmitter from '@semcore/utils/lib/eventEmitter';
|
|
5
|
-
import { eventToPoint } from './utils';
|
|
6
|
-
import style from './style/plot.shadow.css';
|
|
7
|
-
|
|
8
|
-
class PlotRoot extends Component {
|
|
9
|
-
static displayName = 'Plot';
|
|
10
|
-
static style = style;
|
|
11
|
-
|
|
12
|
-
constructor(props) {
|
|
13
|
-
super(props);
|
|
14
|
-
this.eventEmitter = props.eventEmitter || new EventEmitter();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
static defaultProps = () => ({
|
|
18
|
-
width: 0,
|
|
19
|
-
height: 0,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
rootRef = React.createRef();
|
|
23
|
-
|
|
24
|
-
handlerMouseMove = (e) => {
|
|
25
|
-
const { scale } = this.asProps;
|
|
26
|
-
this.eventEmitter.emit(`onMouseMoveRoot`, e);
|
|
27
|
-
|
|
28
|
-
if (scale) {
|
|
29
|
-
const [xScale, yScale] = scale;
|
|
30
|
-
const [pX, pY] = eventToPoint(e, this.rootRef.current);
|
|
31
|
-
const [minX, maxX] = xScale.range();
|
|
32
|
-
const [maxY, minY] = yScale.range();
|
|
33
|
-
|
|
34
|
-
if (pX >= minX && pX <= maxX && pY >= minY && pY <= maxY) {
|
|
35
|
-
this.eventEmitter.emit('onMouseMoveChart', e);
|
|
36
|
-
} else {
|
|
37
|
-
this.eventEmitter.emit('onMouseLeaveChart', e);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
handlerMouseLeave = (e) => {
|
|
43
|
-
this.eventEmitter.emit(`onMouseLeaveRoot`, e);
|
|
44
|
-
this.eventEmitter.emit('onMouseLeaveChart', e);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
setContext() {
|
|
48
|
-
const { scale, data, width, height } = this.asProps;
|
|
49
|
-
return {
|
|
50
|
-
$rootProps: {
|
|
51
|
-
size: [width, height],
|
|
52
|
-
data: data,
|
|
53
|
-
scale: scale,
|
|
54
|
-
eventEmitter: this.eventEmitter,
|
|
55
|
-
rootRef: this.rootRef,
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
render() {
|
|
61
|
-
const SPlot = Root;
|
|
62
|
-
const { styles, width, height } = this.asProps;
|
|
63
|
-
|
|
64
|
-
if (!width || !height) return null;
|
|
65
|
-
|
|
66
|
-
return sstyled(styles)(
|
|
67
|
-
<SPlot
|
|
68
|
-
render={Box}
|
|
69
|
-
tag="svg"
|
|
70
|
-
__excludeProps={['data', 'scale']}
|
|
71
|
-
ref={this.rootRef}
|
|
72
|
-
onMouseMove={this.handlerMouseMove}
|
|
73
|
-
onMouseLeave={this.handlerMouseLeave}
|
|
74
|
-
/>,
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export default createComponent(PlotRoot);
|