@semcore/d3-chart 1.0.0-8 → 1.2.0
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 +62 -0
- package/lib/cjs/Area.js +71 -49
- package/lib/cjs/Area.js.map +1 -1
- package/lib/cjs/Axis.js +148 -142
- package/lib/cjs/Axis.js.map +1 -1
- package/lib/cjs/Bar.js +101 -54
- package/lib/cjs/Bar.js.map +1 -1
- package/lib/cjs/ClipPath.js +110 -0
- package/lib/cjs/ClipPath.js.map +1 -0
- package/lib/cjs/Donut.js +169 -68
- package/lib/cjs/Donut.js.map +1 -1
- package/lib/cjs/Dots.js +55 -21
- package/lib/cjs/Dots.js.map +1 -1
- package/lib/cjs/GroupBar.js +7 -6
- package/lib/cjs/GroupBar.js.map +1 -1
- package/lib/cjs/HorizontalBar.js +72 -45
- package/lib/cjs/HorizontalBar.js.map +1 -1
- package/lib/cjs/Hover.js +46 -47
- package/lib/cjs/Hover.js.map +1 -1
- package/lib/cjs/Line.js +63 -41
- package/lib/cjs/Line.js.map +1 -1
- package/lib/cjs/Plot.js +16 -29
- package/lib/cjs/Plot.js.map +1 -1
- package/lib/cjs/ResponsiveContainer.js +13 -9
- package/lib/cjs/ResponsiveContainer.js.map +1 -1
- package/lib/cjs/StackBar.js +6 -6
- package/lib/cjs/StackBar.js.map +1 -1
- package/lib/cjs/StackedArea.js +8 -9
- package/lib/cjs/StackedArea.js.map +1 -1
- package/lib/cjs/Tooltip.js +49 -75
- package/lib/cjs/Tooltip.js.map +1 -1
- package/lib/cjs/Venn.js +235 -0
- package/lib/cjs/Venn.js.map +1 -0
- package/lib/cjs/index.js +8 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/style/area.shadow.css +11 -10
- package/lib/cjs/style/bar.shadow.css +4 -0
- package/lib/cjs/style/donut.shadow.css +1 -0
- package/lib/cjs/style/dot.shadow.css +19 -0
- package/lib/cjs/style/line.shadow.css +4 -15
- package/lib/cjs/style/tooltip.shadow.css +1 -0
- package/lib/cjs/style/venn.shadow.css +23 -0
- package/lib/cjs/utils.js +8 -1
- package/lib/cjs/utils.js.map +1 -1
- package/lib/es6/Area.js +72 -50
- package/lib/es6/Area.js.map +1 -1
- package/lib/es6/Axis.js +149 -143
- package/lib/es6/Axis.js.map +1 -1
- package/lib/es6/Bar.js +100 -54
- package/lib/es6/Bar.js.map +1 -1
- package/lib/es6/ClipPath.js +91 -0
- package/lib/es6/ClipPath.js.map +1 -0
- package/lib/es6/Donut.js +167 -67
- package/lib/es6/Donut.js.map +1 -1
- package/lib/es6/Dots.js +51 -20
- package/lib/es6/Dots.js.map +1 -1
- package/lib/es6/GroupBar.js +7 -6
- package/lib/es6/GroupBar.js.map +1 -1
- package/lib/es6/HorizontalBar.js +72 -45
- package/lib/es6/HorizontalBar.js.map +1 -1
- package/lib/es6/Hover.js +47 -48
- package/lib/es6/Hover.js.map +1 -1
- package/lib/es6/Line.js +65 -43
- package/lib/es6/Line.js.map +1 -1
- package/lib/es6/Plot.js +17 -29
- package/lib/es6/Plot.js.map +1 -1
- package/lib/es6/ResponsiveContainer.js +13 -7
- package/lib/es6/ResponsiveContainer.js.map +1 -1
- package/lib/es6/StackBar.js +6 -6
- package/lib/es6/StackBar.js.map +1 -1
- package/lib/es6/StackedArea.js +8 -9
- package/lib/es6/StackedArea.js.map +1 -1
- package/lib/es6/Tooltip.js +52 -76
- package/lib/es6/Tooltip.js.map +1 -1
- package/lib/es6/Venn.js +217 -0
- package/lib/es6/Venn.js.map +1 -0
- package/lib/es6/index.js +1 -0
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/style/area.shadow.css +11 -10
- package/lib/es6/style/bar.shadow.css +4 -0
- package/lib/es6/style/donut.shadow.css +1 -0
- package/lib/es6/style/dot.shadow.css +19 -0
- package/lib/es6/style/line.shadow.css +4 -15
- package/lib/es6/style/tooltip.shadow.css +1 -0
- package/lib/es6/style/venn.shadow.css +23 -0
- package/lib/es6/utils.js +6 -1
- package/lib/es6/utils.js.map +1 -1
- package/lib/types/Area.d.ts +7 -8
- package/lib/types/Axis.d.ts +6 -6
- package/lib/types/Bar.d.ts +7 -3
- package/lib/types/ClipPath.d.ts +26 -0
- package/lib/types/Donut.d.ts +12 -2
- package/lib/types/GroupBar.d.ts +2 -2
- package/lib/types/HorizontalBar.d.ts +7 -3
- package/lib/types/Hover.d.ts +2 -2
- package/lib/types/Line.d.ts +9 -4
- package/{src/types/Plot.ts → lib/types/Plot.d.ts} +2 -2
- package/lib/types/ResponsiveContainer.d.ts +1 -1
- package/lib/types/StackBar.d.ts +3 -11
- package/lib/types/StackedArea.d.ts +7 -6
- package/lib/types/Tooltip.d.ts +4 -4
- package/lib/types/Venn.d.ts +45 -0
- package/lib/types/context.d.ts +1 -1
- package/lib/types/index.d.ts +6 -0
- package/package.json +10 -5
- package/src/Area.js +43 -14
- package/src/Axis.js +24 -22
- package/src/Bar.js +69 -24
- package/src/ClipPath.js +36 -0
- package/src/Donut.js +84 -12
- package/src/Dots.js +36 -20
- package/src/GroupBar.js +1 -0
- package/src/HorizontalBar.js +49 -22
- package/src/Hover.js +3 -3
- package/src/Line.js +41 -13
- package/src/Plot.js +3 -7
- package/src/ResponsiveContainer.js +3 -3
- package/src/StackBar.js +1 -1
- package/src/StackedArea.js +3 -2
- package/src/Tooltip.js +11 -12
- package/src/Venn.js +112 -0
- package/src/index.js +1 -0
- package/src/style/area.shadow.css +11 -10
- package/src/style/bar.shadow.css +4 -0
- package/src/style/donut.shadow.css +1 -0
- package/src/style/dot.shadow.css +19 -0
- package/src/style/line.shadow.css +4 -15
- package/src/style/tooltip.shadow.css +1 -0
- package/src/style/venn.shadow.css +23 -0
- package/src/types/Area.d.ts +7 -8
- package/src/types/Axis.d.ts +6 -6
- package/src/types/Bar.d.ts +7 -3
- package/src/types/ClipPath.d.ts +26 -0
- package/src/types/Donut.d.ts +12 -2
- package/src/types/GroupBar.d.ts +2 -2
- package/src/types/HorizontalBar.d.ts +7 -3
- package/src/types/Hover.d.ts +2 -2
- package/src/types/Line.d.ts +9 -4
- package/src/types/Plot.d.ts +16 -0
- package/src/types/ResponsiveContainer.d.ts +1 -1
- package/src/types/StackBar.d.ts +3 -11
- package/src/types/StackedArea.d.ts +7 -6
- package/src/types/Tooltip.d.ts +4 -4
- package/src/types/Venn.d.ts +45 -0
- package/src/types/context.d.ts +1 -1
- package/src/types/index.d.ts +6 -0
- package/src/utils.js +7 -1
- package/lib/cjs/style/chart.shadow.css +0 -4
- package/lib/cjs/types/Plot.js +0 -2
- package/lib/cjs/types/Plot.js.map +0 -1
- package/lib/es6/style/chart.shadow.css +0 -4
- package/lib/es6/types/Plot.js +0 -2
- package/lib/es6/types/Plot.js.map +0 -1
- package/src/style/chart.shadow.css +0 -4
package/src/Donut.js
CHANGED
|
@@ -1,18 +1,52 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { arc, pie } from 'd3-shape';
|
|
3
|
-
import { Component,
|
|
3
|
+
import { Component, sstyled } from '@semcore/core';
|
|
4
4
|
import canUseDOM from '@semcore/utils/lib/canUseDOM';
|
|
5
5
|
import getOriginChildren from '@semcore/utils/lib/getOriginChildren';
|
|
6
6
|
import { CONSTANT } from './utils';
|
|
7
7
|
import createElement from './createElement';
|
|
8
|
+
import uniqueIDEnhancement from '@semcore/utils/lib/uniqueID';
|
|
9
|
+
import { interpolate } from 'd3-interpolate';
|
|
10
|
+
import { transition } from 'd3-transition';
|
|
8
11
|
|
|
9
12
|
import style from './style/donut.shadow.css';
|
|
10
13
|
|
|
11
14
|
const DEFAULT_INSTANCE = Symbol('DEFAULT_INSTANCE');
|
|
12
15
|
|
|
16
|
+
function animationInitialPie({ halfsize, d3Arc, arcs }) {
|
|
17
|
+
return function(_, ind) {
|
|
18
|
+
const d = arcs[ind];
|
|
19
|
+
if (!d) return () => '';
|
|
20
|
+
const iStart = interpolate(halfsize ? -Math.PI / 2 : 0, d.startAngle);
|
|
21
|
+
const iEnd = interpolate(halfsize ? -Math.PI / 2 : 0, d.endAngle);
|
|
22
|
+
return function(t) {
|
|
23
|
+
d.startAngle = iStart(t);
|
|
24
|
+
d.endAngle = iEnd(t);
|
|
25
|
+
return d3Arc(d);
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function animationUpdatePie({ halfsize, arcs, d3Arc }) {
|
|
31
|
+
return function(_, ind) {
|
|
32
|
+
const d = arcs[ind];
|
|
33
|
+
if (this._current) {
|
|
34
|
+
const i = interpolate(this._current, d);
|
|
35
|
+
this._current = i(0);
|
|
36
|
+
return function(t) {
|
|
37
|
+
return d3Arc(i(t));
|
|
38
|
+
};
|
|
39
|
+
} else {
|
|
40
|
+
this._current = d;
|
|
41
|
+
return animationInitialPie({ halfsize, arcs, d3Arc })(_, ind);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
13
46
|
class DonutRoot extends Component {
|
|
14
47
|
static displayName = 'Donut';
|
|
15
48
|
static style = style;
|
|
49
|
+
static enhance = [uniqueIDEnhancement()];
|
|
16
50
|
|
|
17
51
|
static defaultProps = ({ innerRadius = 0, halfsize = false, $rootProps: { size } }) => {
|
|
18
52
|
const [width, height] = size;
|
|
@@ -31,20 +65,19 @@ class DonutRoot extends Component {
|
|
|
31
65
|
return {
|
|
32
66
|
d3Pie,
|
|
33
67
|
d3Arc,
|
|
68
|
+
duration: 500,
|
|
34
69
|
};
|
|
35
70
|
};
|
|
36
71
|
|
|
72
|
+
get id() {
|
|
73
|
+
const { uid, id } = this.asProps;
|
|
74
|
+
return id || uid;
|
|
75
|
+
}
|
|
76
|
+
|
|
37
77
|
virtualElement = canUseDOM() ? document.createElement('div') : {};
|
|
38
78
|
|
|
39
79
|
generateGetBoundingClientRect(x = 0, y = 0) {
|
|
40
|
-
return () => ({
|
|
41
|
-
width: 0,
|
|
42
|
-
height: 0,
|
|
43
|
-
top: y,
|
|
44
|
-
right: x,
|
|
45
|
-
bottom: y,
|
|
46
|
-
left: x,
|
|
47
|
-
});
|
|
80
|
+
return () => ({ width: 0, height: 0, top: y, right: x, bottom: y, left: x });
|
|
48
81
|
}
|
|
49
82
|
|
|
50
83
|
getArcs() {
|
|
@@ -62,6 +95,15 @@ class DonutRoot extends Component {
|
|
|
62
95
|
.filter(([key]) => keys.includes(key))
|
|
63
96
|
.sort(([a], [b]) => (keys.indexOf(a) > keys.indexOf(b) ? 1 : -1));
|
|
64
97
|
}
|
|
98
|
+
const minValue =
|
|
99
|
+
pieData.reduce((acc, cur) => {
|
|
100
|
+
if (cur[1]) acc += cur[1];
|
|
101
|
+
return acc;
|
|
102
|
+
}, 0) / 100;
|
|
103
|
+
pieData = pieData.map((d) => {
|
|
104
|
+
if (d[1] && d[1] < minValue) d[1] = minValue;
|
|
105
|
+
return d;
|
|
106
|
+
});
|
|
65
107
|
return d3Pie(pieData);
|
|
66
108
|
}
|
|
67
109
|
|
|
@@ -75,7 +117,7 @@ class DonutRoot extends Component {
|
|
|
75
117
|
getPieProps(props) {
|
|
76
118
|
const { d3Arc } = this.asProps;
|
|
77
119
|
return {
|
|
78
|
-
data: this.arcs.find((arc) => arc.data[0]
|
|
120
|
+
data: this.arcs.find((arc) => arc.data[0] === props.dataKey),
|
|
79
121
|
d3Arc,
|
|
80
122
|
onMouseMove: this.bindHandlerTooltip(true, props),
|
|
81
123
|
onMouseLeave: this.bindHandlerTooltip(false, props),
|
|
@@ -94,6 +136,35 @@ class DonutRoot extends Component {
|
|
|
94
136
|
};
|
|
95
137
|
}
|
|
96
138
|
|
|
139
|
+
componentDidUpdate(prevProps) {
|
|
140
|
+
const { data, duration, d3Arc, halfsize } = this.asProps;
|
|
141
|
+
const arcs = this.arcs;
|
|
142
|
+
if (prevProps.$rootProps.data !== data && duration > 0) {
|
|
143
|
+
transition()
|
|
144
|
+
.selection()
|
|
145
|
+
.selectAll(`#${this.id} [data-ui-name="Donut.Pie"]`)
|
|
146
|
+
.transition()
|
|
147
|
+
.duration(duration)
|
|
148
|
+
.attrTween('d', animationUpdatePie({ d3Arc, arcs, halfsize }));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
componentDidMount() {
|
|
153
|
+
const { duration, d3Arc, halfsize } = this.asProps;
|
|
154
|
+
const arcs = this.arcs;
|
|
155
|
+
if (duration > 0) {
|
|
156
|
+
transition()
|
|
157
|
+
.selection()
|
|
158
|
+
.selectAll(`#${this.id} [data-ui-name="Donut.Pie"]`)
|
|
159
|
+
.each(function(_, ind) {
|
|
160
|
+
this._current = arcs[ind];
|
|
161
|
+
})
|
|
162
|
+
.transition()
|
|
163
|
+
.duration(duration)
|
|
164
|
+
.attrTween('d', animationInitialPie({ halfsize, d3Arc, arcs }));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
97
168
|
render() {
|
|
98
169
|
const { halfsize, size } = this.asProps;
|
|
99
170
|
const [width, height] = size;
|
|
@@ -102,6 +173,7 @@ class DonutRoot extends Component {
|
|
|
102
173
|
this.arcs = this.getArcs();
|
|
103
174
|
return (
|
|
104
175
|
<Element
|
|
176
|
+
id={this.id}
|
|
105
177
|
render="g"
|
|
106
178
|
childrenPosition="inside"
|
|
107
179
|
transform={`translate(${width / 2},${height / k})`}
|
|
@@ -111,11 +183,11 @@ class DonutRoot extends Component {
|
|
|
111
183
|
}
|
|
112
184
|
|
|
113
185
|
function Pie({ Element: SPie, styles, d3Arc, data, color = '#50aef4' }) {
|
|
114
|
-
return
|
|
186
|
+
return sstyled(styles)(<SPie render="path" color={color} d={d3Arc(data)} />);
|
|
115
187
|
}
|
|
116
188
|
|
|
117
189
|
function Label({ Element: SLabel, styles, Children }) {
|
|
118
|
-
return
|
|
190
|
+
return sstyled(styles)(
|
|
119
191
|
<SLabel render="text" x="0" y="0">
|
|
120
192
|
<Children />
|
|
121
193
|
</SLabel>,
|
package/src/Dots.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { bisector } from 'd3-array';
|
|
2
2
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { sstyled } from '@semcore/core';
|
|
4
4
|
import trottle from '@semcore/utils/lib/rafTrottle';
|
|
5
5
|
import { eventToPoint, invert } from './utils';
|
|
6
|
+
import createElement from './createElement';
|
|
7
|
+
import { FadeInOut } from '@semcore/animation';
|
|
8
|
+
|
|
9
|
+
import style from './style/dot.shadow.css';
|
|
6
10
|
|
|
7
11
|
function Dots(props) {
|
|
8
12
|
const {
|
|
9
13
|
Element: SDot,
|
|
10
14
|
styles,
|
|
11
15
|
data,
|
|
16
|
+
color,
|
|
12
17
|
d3,
|
|
13
18
|
x,
|
|
14
19
|
y,
|
|
@@ -17,9 +22,10 @@ function Dots(props) {
|
|
|
17
22
|
hide,
|
|
18
23
|
rootRef,
|
|
19
24
|
scale,
|
|
25
|
+
duration = 500,
|
|
20
26
|
} = props;
|
|
21
27
|
const bisect = bisector((d) => d[x]).center;
|
|
22
|
-
const [activeIndex, setActiveIndex] = useState(
|
|
28
|
+
const [activeIndex, setActiveIndex] = useState(null);
|
|
23
29
|
|
|
24
30
|
const handlerMouseMoveRoot = useCallback(
|
|
25
31
|
trottle((e) => {
|
|
@@ -55,30 +61,40 @@ function Dots(props) {
|
|
|
55
61
|
};
|
|
56
62
|
}, [eventEmitter, data, x, y]);
|
|
57
63
|
|
|
64
|
+
const renderCircle = useCallback(
|
|
65
|
+
React.forwardRef((props, ref) => {
|
|
66
|
+
return <FadeInOut ref={ref} tag="circle" {...props} />;
|
|
67
|
+
}),
|
|
68
|
+
[props],
|
|
69
|
+
);
|
|
70
|
+
|
|
58
71
|
return data.reduce((acc, d, i) => {
|
|
59
72
|
const isPrev = d3.defined()(data[i - 1] || {});
|
|
60
73
|
const isNext = d3.defined()(data[i + 1] || {});
|
|
61
74
|
const active = i === activeIndex;
|
|
62
75
|
if (!d3.defined()(d)) return acc;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
acc.push(
|
|
77
|
+
sstyled(styles)(
|
|
78
|
+
<SDot
|
|
79
|
+
key={i}
|
|
80
|
+
render={renderCircle}
|
|
81
|
+
visible={display || i === activeIndex || (!isPrev && !isNext)}
|
|
82
|
+
__excludeProps={['data', 'scale', 'value', 'display']}
|
|
83
|
+
value={d}
|
|
84
|
+
index={i}
|
|
85
|
+
cx={d3.x()(d)}
|
|
86
|
+
cy={d3.y()(d)}
|
|
87
|
+
active={active}
|
|
88
|
+
hide={hide}
|
|
89
|
+
color={color}
|
|
90
|
+
use:duration={`${duration}ms`}
|
|
91
|
+
/>,
|
|
92
|
+
),
|
|
93
|
+
);
|
|
80
94
|
return acc;
|
|
81
95
|
}, []);
|
|
82
96
|
}
|
|
83
97
|
|
|
84
|
-
|
|
98
|
+
Dots.style = style;
|
|
99
|
+
|
|
100
|
+
export default createElement(Dots);
|
package/src/GroupBar.js
CHANGED
package/src/HorizontalBar.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Component,
|
|
2
|
+
import { Component, sstyled } from '@semcore/core';
|
|
3
3
|
import createElement from './createElement';
|
|
4
|
+
import ClipPath from './ClipPath';
|
|
5
|
+
import uniqueIDEnhancement from '@semcore/utils/lib/uniqueID';
|
|
4
6
|
|
|
5
7
|
import style from './style/bar.shadow.css';
|
|
6
8
|
|
|
7
9
|
class HorizontalBarRoot extends Component {
|
|
8
10
|
static displayName = 'HorizontalBar';
|
|
9
|
-
|
|
11
|
+
static enhance = [uniqueIDEnhancement()];
|
|
10
12
|
static style = style;
|
|
11
13
|
|
|
12
14
|
static defaultProps = {
|
|
13
15
|
color: '#50aef4',
|
|
14
16
|
offset: [0, 0],
|
|
17
|
+
duration: 500,
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
getBackgroundProps(props, index) {
|
|
@@ -21,28 +24,52 @@ class HorizontalBarRoot extends Component {
|
|
|
21
24
|
};
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
renderBar(d, i) {
|
|
25
28
|
const SBar = this.Element;
|
|
26
|
-
const { styles, color, x, x0, y,
|
|
29
|
+
const { styles, color, x, x0, y, scale, hide, offset, uid, duration } = this.asProps;
|
|
27
30
|
const [xScale, yScale] = scale;
|
|
28
31
|
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
return sstyled(styles)(
|
|
33
|
+
<SBar
|
|
34
|
+
key={`horizontal-bar-${i}`}
|
|
35
|
+
render="rect"
|
|
36
|
+
clipPath={`url(#${uid})`}
|
|
37
|
+
__excludeProps={['data', 'scale', 'value']}
|
|
38
|
+
childrenPosition="above"
|
|
39
|
+
value={d}
|
|
40
|
+
index={i}
|
|
41
|
+
hide={hide}
|
|
42
|
+
color={color}
|
|
43
|
+
width={Math.abs(xScale(d[x]) - Math.max(xScale(xScale.domain()[0]), xScale(d[x0] ?? 0)))}
|
|
44
|
+
height={yScale.bandwidth()}
|
|
45
|
+
x={xScale(Math.min(d[x0] ?? 0, d[x])) + offset[0]}
|
|
46
|
+
y={yScale(d[y]) + offset[1]}
|
|
47
|
+
use:duration={`${duration}ms`}
|
|
48
|
+
/>,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
render() {
|
|
53
|
+
const { data, uid, size, duration } = this.asProps;
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<>
|
|
57
|
+
{data.map(this.renderBar.bind(this))}
|
|
58
|
+
{duration && (
|
|
59
|
+
<ClipPath
|
|
60
|
+
setAttributeTag={(rect) => {
|
|
61
|
+
rect.setAttribute('width', size[0]);
|
|
62
|
+
}}
|
|
63
|
+
id={uid}
|
|
64
|
+
x="0"
|
|
65
|
+
y="0"
|
|
66
|
+
width={0}
|
|
67
|
+
height={size[1]}
|
|
68
|
+
transition={`width ${duration}ms ease-in-out`}
|
|
69
|
+
/>
|
|
70
|
+
)}
|
|
71
|
+
</>
|
|
72
|
+
);
|
|
46
73
|
}
|
|
47
74
|
}
|
|
48
75
|
|
|
@@ -51,7 +78,7 @@ function Background(props) {
|
|
|
51
78
|
const [xScale, yScale] = scale;
|
|
52
79
|
const xRange = xScale.range();
|
|
53
80
|
|
|
54
|
-
return
|
|
81
|
+
return sstyled(styles)(
|
|
55
82
|
<SBackground
|
|
56
83
|
render="rect"
|
|
57
84
|
childrenPosition="above"
|
package/src/Hover.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Component,
|
|
2
|
+
import { Component, sstyled } from '@semcore/core';
|
|
3
3
|
import createElement from './createElement';
|
|
4
4
|
import trottle from '@semcore/utils/lib/rafTrottle';
|
|
5
5
|
import { scaleOfBandwidth, getIndexFromData, eventToPoint, invert } from './utils';
|
|
@@ -83,7 +83,7 @@ class HoverLineRoot extends Hover {
|
|
|
83
83
|
const x1 = xIndex !== null ? scaleOfBandwidth(xScale, data[xIndex][x]) : undefined;
|
|
84
84
|
const y1 = yIndex !== null ? scaleOfBandwidth(yScale, data[yIndex][y]) : undefined;
|
|
85
85
|
|
|
86
|
-
return
|
|
86
|
+
return sstyled(styles)(
|
|
87
87
|
<>
|
|
88
88
|
{xIndex !== null ? (
|
|
89
89
|
<SHoverLine
|
|
@@ -124,7 +124,7 @@ class HoverRectRoot extends Hover {
|
|
|
124
124
|
const xRange = xScale.range();
|
|
125
125
|
const yRange = yScale.range();
|
|
126
126
|
|
|
127
|
-
return
|
|
127
|
+
return sstyled(styles)(
|
|
128
128
|
<>
|
|
129
129
|
{xIndex !== null ? (
|
|
130
130
|
<SHoverRect
|
package/src/Line.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { curveLinear, line as d3Line } from 'd3-shape';
|
|
3
|
-
import { Component,
|
|
3
|
+
import { Component, sstyled } from '@semcore/core';
|
|
4
4
|
import createElement from './createElement';
|
|
5
|
-
import { definedData, scaleOfBandwidth, getNullData } from './utils';
|
|
5
|
+
import { definedData, definedNullData, scaleOfBandwidth, getNullData } from './utils';
|
|
6
6
|
import Dots from './Dots';
|
|
7
|
+
import ClipPath from './ClipPath';
|
|
8
|
+
import uniqueIDEnhancement from '@semcore/utils/lib/uniqueID';
|
|
7
9
|
|
|
8
10
|
import style from './style/line.shadow.css';
|
|
9
11
|
|
|
10
12
|
class LineRoot extends Component {
|
|
11
13
|
static displayName = 'Line';
|
|
14
|
+
static style = style;
|
|
15
|
+
static enhance = [uniqueIDEnhancement()];
|
|
16
|
+
|
|
12
17
|
static defaultProps = ({ x, y, $rootProps, curve = curveLinear }) => {
|
|
13
18
|
const [xScale, yScale] = $rootProps.scale;
|
|
14
19
|
return {
|
|
@@ -18,42 +23,65 @@ class LineRoot extends Component {
|
|
|
18
23
|
.x((p) => scaleOfBandwidth(xScale, p[x]))
|
|
19
24
|
.y((p) => scaleOfBandwidth(yScale, p[y])),
|
|
20
25
|
color: '#50aef4',
|
|
26
|
+
duration: 500,
|
|
21
27
|
};
|
|
22
28
|
};
|
|
23
29
|
|
|
24
|
-
static style = style;
|
|
25
|
-
|
|
26
30
|
getDotsProps() {
|
|
27
|
-
const { x, y, d3, color } = this.asProps;
|
|
31
|
+
const { x, y, d3, color, duration } = this.asProps;
|
|
28
32
|
return {
|
|
29
33
|
x,
|
|
30
34
|
y,
|
|
31
35
|
d3,
|
|
32
|
-
|
|
36
|
+
color,
|
|
37
|
+
delay: duration,
|
|
33
38
|
};
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
getNullProps() {
|
|
37
|
-
const { y, d3, color, data } = this.asProps;
|
|
42
|
+
const { x, y, d3, color, data } = this.asProps;
|
|
38
43
|
return {
|
|
39
44
|
d3,
|
|
40
45
|
// TODO: vertical
|
|
41
|
-
data: getNullData(data,
|
|
42
|
-
|
|
46
|
+
data: getNullData(data, definedNullData(x, y), y),
|
|
47
|
+
color,
|
|
43
48
|
};
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
render() {
|
|
47
52
|
const SLine = this.Element;
|
|
48
|
-
const { styles, hide, color, d3, data } = this.asProps;
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
const { styles, hide, color, uid, size, d3, data, duration } = this.asProps;
|
|
54
|
+
return sstyled(styles)(
|
|
55
|
+
<>
|
|
56
|
+
<SLine
|
|
57
|
+
clipPath={`url(#${uid})`}
|
|
58
|
+
render="path"
|
|
59
|
+
hide={hide}
|
|
60
|
+
color={color}
|
|
61
|
+
d={d3(data)}
|
|
62
|
+
use:duration={`${duration}ms`}
|
|
63
|
+
/>
|
|
64
|
+
{duration && (
|
|
65
|
+
<ClipPath
|
|
66
|
+
setAttributeTag={(rect) => {
|
|
67
|
+
rect.setAttribute('width', size[0]);
|
|
68
|
+
}}
|
|
69
|
+
id={uid}
|
|
70
|
+
x="0"
|
|
71
|
+
y="0"
|
|
72
|
+
width={0}
|
|
73
|
+
height={size[1]}
|
|
74
|
+
transition={`width ${duration}ms ease-in-out`}
|
|
75
|
+
/>
|
|
76
|
+
)}
|
|
77
|
+
</>,
|
|
78
|
+
);
|
|
51
79
|
}
|
|
52
80
|
}
|
|
53
81
|
|
|
54
82
|
function Null(props) {
|
|
55
83
|
const { Element: SNull, styles, d3, data, hide } = props;
|
|
56
|
-
return
|
|
84
|
+
return sstyled(styles)(<SNull render="path" d={d3(data)} hide={hide} />);
|
|
57
85
|
}
|
|
58
86
|
|
|
59
87
|
export default createElement(LineRoot, {
|
package/src/Plot.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import createComponent, { Component,
|
|
2
|
+
import createComponent, { Component, Root, sstyled } from '@semcore/core';
|
|
3
3
|
import { Box } from '@semcore/flex-box';
|
|
4
4
|
import EventEmitter from '@semcore/utils/lib/eventEmitter';
|
|
5
5
|
|
|
6
|
-
import style from './style/chart.shadow.css';
|
|
7
|
-
|
|
8
6
|
class PlotRoot extends Component {
|
|
9
7
|
static displayName = 'Plot';
|
|
10
8
|
|
|
11
|
-
static style = style;
|
|
12
|
-
|
|
13
9
|
constructor(props) {
|
|
14
10
|
super(props);
|
|
15
11
|
this.eventEmitter = props.eventEmitter || new EventEmitter();
|
|
@@ -44,12 +40,12 @@ class PlotRoot extends Component {
|
|
|
44
40
|
}
|
|
45
41
|
|
|
46
42
|
render() {
|
|
47
|
-
const SPlot =
|
|
43
|
+
const SPlot = Root;
|
|
48
44
|
const { styles, width, height } = this.asProps;
|
|
49
45
|
|
|
50
46
|
if (!width || !height) return null;
|
|
51
47
|
|
|
52
|
-
return
|
|
48
|
+
return sstyled(styles)(
|
|
53
49
|
<SPlot
|
|
54
50
|
render={Box}
|
|
55
51
|
tag="svg"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import ResizeObserver from 'resize-observer-polyfill';
|
|
3
3
|
|
|
4
|
-
import createComponent, { Component,
|
|
4
|
+
import createComponent, { Component, Root, sstyled } from '@semcore/core';
|
|
5
5
|
import { Box } from '@semcore/flex-box';
|
|
6
6
|
import trottle from '@semcore/utils/lib/rafTrottle';
|
|
7
7
|
import fire from '@semcore/utils/lib/fire';
|
|
@@ -73,9 +73,9 @@ class ResponsiveContainerRoot extends Component {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
render() {
|
|
76
|
-
const SResponsiveContainer =
|
|
76
|
+
const SResponsiveContainer = Root;
|
|
77
77
|
const { styles } = this.asProps;
|
|
78
|
-
return
|
|
78
|
+
return sstyled(styles)(<SResponsiveContainer render={Box} ref={this.containerRef} />);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
package/src/StackBar.js
CHANGED
package/src/StackedArea.js
CHANGED
|
@@ -31,7 +31,7 @@ class StackedAreaRoot extends Component {
|
|
|
31
31
|
}
|
|
32
32
|
return acc;
|
|
33
33
|
}, []);
|
|
34
|
-
stack.keys(keys);
|
|
34
|
+
stack.keys(keys.reverse());
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
return stack(data);
|
|
@@ -43,7 +43,8 @@ class StackedAreaRoot extends Component {
|
|
|
43
43
|
return {
|
|
44
44
|
data: series.map((s) => ({
|
|
45
45
|
...s.data,
|
|
46
|
-
|
|
46
|
+
// if null is passed in the data, then we pass it, because d3 null leads to 0
|
|
47
|
+
[y]: s.data[y] === null ? null : s[1],
|
|
47
48
|
[Y0]: s[0],
|
|
48
49
|
})),
|
|
49
50
|
y0: Y0,
|
package/src/Tooltip.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
|
-
import { Component,
|
|
2
|
+
import { Component, Root, sstyled } from '@semcore/core';
|
|
3
3
|
import Popper from '@semcore/popper';
|
|
4
4
|
import { Box } from '@semcore/flex-box';
|
|
5
5
|
import findComponent from '@semcore/utils/lib/findComponent';
|
|
6
|
+
import resolveColor from '@semcore/utils/lib/color';
|
|
6
7
|
import { CONSTANT } from './utils';
|
|
7
8
|
import createElement from './createElement';
|
|
8
9
|
|
|
@@ -38,6 +39,7 @@ class TooltipRoot extends Component {
|
|
|
38
39
|
(visible, data, node) => {
|
|
39
40
|
this.setState(
|
|
40
41
|
{
|
|
42
|
+
// TODO: тут бага если одно поля нету,то оно не перезапишет стейт
|
|
41
43
|
...data,
|
|
42
44
|
$visible: visible,
|
|
43
45
|
},
|
|
@@ -59,7 +61,6 @@ class TooltipRoot extends Component {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
render() {
|
|
62
|
-
const Root = this.Root;
|
|
63
64
|
const { Children, children, tag, ...other } = this.asProps;
|
|
64
65
|
|
|
65
66
|
const advanceMode = !!findComponent(Children, [
|
|
@@ -101,26 +102,24 @@ function PopperPopper(props) {
|
|
|
101
102
|
|
|
102
103
|
if (!$visible) return null;
|
|
103
104
|
|
|
104
|
-
return
|
|
105
|
+
return sstyled(styles)(
|
|
105
106
|
<STooltip render={Popper.Popper} childrenPosition="inside" onMouseMove={handlerCancel} />,
|
|
106
107
|
);
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
function Title(props) {
|
|
110
|
-
const
|
|
111
|
-
|
|
111
|
+
const STitle = Root;
|
|
112
|
+
const { styles } = props;
|
|
113
|
+
return sstyled(styles)(<STitle render={Box} __excludeProps={['data', 'scale']} />);
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
function Dot(props) {
|
|
115
|
-
const {
|
|
117
|
+
const { styles, color = '#50aef4', Children } = props;
|
|
118
|
+
const SDotGroup = Root;
|
|
116
119
|
const SDot = Box;
|
|
117
|
-
return
|
|
118
|
-
SDot {
|
|
119
|
-
background: ${color};
|
|
120
|
-
}
|
|
121
|
-
`(
|
|
120
|
+
return sstyled(styles)(
|
|
122
121
|
<SDotGroup render={Box}>
|
|
123
|
-
<SDot __excludeProps={['data', 'scale']} />
|
|
122
|
+
<SDot __excludeProps={['data', 'scale']} color={resolveColor(color)} />
|
|
124
123
|
<Children />
|
|
125
124
|
</SDotGroup>,
|
|
126
125
|
);
|