@semcore/d3-chart 1.5.4 → 1.6.1
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 +23 -1
- package/lib/cjs/Area.js +9 -9
- package/lib/cjs/Area.js.map +1 -1
- package/lib/cjs/Axis.js +12 -12
- package/lib/cjs/Bar.js +11 -14
- package/lib/cjs/Bar.js.map +1 -1
- package/lib/cjs/Bubble.js +276 -0
- package/lib/cjs/Bubble.js.map +1 -0
- package/lib/cjs/Donut.js +77 -64
- package/lib/cjs/Donut.js.map +1 -1
- package/lib/cjs/Dots.js +8 -7
- package/lib/cjs/Dots.js.map +1 -1
- package/lib/cjs/GroupBar.js +8 -7
- package/lib/cjs/GroupBar.js.map +1 -1
- package/lib/cjs/HorizontalBar.js +11 -14
- package/lib/cjs/HorizontalBar.js.map +1 -1
- package/lib/cjs/Hover.js +3 -3
- package/lib/cjs/Line.js +8 -8
- package/lib/cjs/Line.js.map +1 -1
- package/lib/cjs/ScatterPlot.js +224 -0
- package/lib/cjs/ScatterPlot.js.map +1 -0
- package/lib/cjs/StackBar.js +39 -14
- package/lib/cjs/StackBar.js.map +1 -1
- package/lib/cjs/StackedArea.js +11 -9
- package/lib/cjs/StackedArea.js.map +1 -1
- package/lib/cjs/Tooltip.js +17 -13
- package/lib/cjs/Tooltip.js.map +1 -1
- package/lib/cjs/Venn.js +8 -8
- package/lib/cjs/Venn.js.map +1 -1
- package/lib/cjs/color.js +32 -30
- package/lib/cjs/color.js.map +1 -1
- package/lib/cjs/index.js +16 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/style/area.shadow.css +12 -2
- package/lib/cjs/style/bar.shadow.css +7 -2
- package/lib/cjs/style/bubble.shadow.css +45 -0
- package/lib/cjs/style/donut.shadow.css +15 -0
- package/lib/cjs/style/dot.shadow.css +6 -1
- package/lib/cjs/style/line.shadow.css +6 -1
- package/lib/cjs/style/scatterplot.shadow.css +27 -0
- package/lib/cjs/style/tooltip.shadow.css +7 -2
- package/lib/cjs/style/var.css +32 -0
- package/lib/cjs/style/venn.shadow.css +7 -1
- package/lib/es6/Area.js +9 -9
- package/lib/es6/Area.js.map +1 -1
- package/lib/es6/Axis.js +12 -12
- package/lib/es6/Bar.js +11 -14
- package/lib/es6/Bar.js.map +1 -1
- package/lib/es6/Bubble.js +259 -0
- package/lib/es6/Bubble.js.map +1 -0
- package/lib/es6/Donut.js +77 -64
- package/lib/es6/Donut.js.map +1 -1
- package/lib/es6/Dots.js +8 -7
- package/lib/es6/Dots.js.map +1 -1
- package/lib/es6/GroupBar.js +8 -7
- package/lib/es6/GroupBar.js.map +1 -1
- package/lib/es6/HorizontalBar.js +11 -14
- package/lib/es6/HorizontalBar.js.map +1 -1
- package/lib/es6/Hover.js +3 -3
- package/lib/es6/Line.js +8 -8
- package/lib/es6/Line.js.map +1 -1
- package/lib/es6/ScatterPlot.js +209 -0
- package/lib/es6/ScatterPlot.js.map +1 -0
- package/lib/es6/StackBar.js +39 -14
- package/lib/es6/StackBar.js.map +1 -1
- package/lib/es6/StackedArea.js +11 -9
- package/lib/es6/StackedArea.js.map +1 -1
- package/lib/es6/Tooltip.js +16 -12
- package/lib/es6/Tooltip.js.map +1 -1
- package/lib/es6/Venn.js +8 -8
- package/lib/es6/Venn.js.map +1 -1
- package/lib/es6/color.js +33 -31
- package/lib/es6/color.js.map +1 -1
- package/lib/es6/index.js +2 -0
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/style/area.shadow.css +12 -2
- package/lib/es6/style/bar.shadow.css +7 -2
- package/lib/es6/style/bubble.shadow.css +45 -0
- package/lib/es6/style/donut.shadow.css +15 -0
- package/lib/es6/style/dot.shadow.css +6 -1
- package/lib/es6/style/line.shadow.css +6 -1
- package/lib/es6/style/scatterplot.shadow.css +27 -0
- package/lib/es6/style/tooltip.shadow.css +7 -2
- package/lib/es6/style/var.css +32 -0
- package/lib/es6/style/venn.shadow.css +7 -1
- package/lib/types/Bar.d.ts +1 -1
- package/lib/types/Bubble.d.ts +27 -0
- package/lib/types/HorizontalBar.d.ts +1 -1
- package/lib/types/ScatterPlot.d.ts +27 -0
- package/lib/types/index.d.ts +6 -0
- package/package.json +1 -1
- package/src/Area.js +0 -1
- package/src/Bar.js +6 -8
- package/src/Bubble.js +189 -0
- package/src/Donut.js +8 -7
- package/src/GroupBar.js +6 -2
- package/src/HorizontalBar.js +5 -8
- package/src/Line.js +0 -1
- package/src/ScatterPlot.js +130 -0
- package/src/StackBar.js +24 -7
- package/src/StackedArea.js +3 -2
- package/src/Tooltip.js +10 -4
- package/src/Venn.js +1 -1
- package/src/color.js +6 -32
- package/src/index.js +2 -0
- package/src/style/area.shadow.css +12 -2
- package/src/style/bar.shadow.css +7 -2
- package/src/style/bubble.shadow.css +45 -0
- package/src/style/donut.shadow.css +15 -0
- package/src/style/dot.shadow.css +6 -1
- package/src/style/line.shadow.css +6 -1
- package/src/style/scatterplot.shadow.css +27 -0
- package/src/style/tooltip.shadow.css +7 -2
- package/src/style/var.css +32 -0
- package/src/style/venn.shadow.css +7 -1
- package/src/types/Bar.d.ts +1 -1
- package/src/types/Bubble.d.ts +27 -0
- package/src/types/HorizontalBar.d.ts +1 -1
- package/src/types/ScatterPlot.d.ts +27 -0
- package/src/types/index.d.ts +6 -0
package/src/Bubble.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Component, sstyled } from '@semcore/core';
|
|
3
|
+
import canUseDOM from '@semcore/utils/lib/canUseDOM';
|
|
4
|
+
import { CONSTANT } from './utils';
|
|
5
|
+
import createElement from './createElement';
|
|
6
|
+
import uniqueIDEnhancement from '@semcore/utils/lib/uniqueID';
|
|
7
|
+
import { transition } from 'd3-transition';
|
|
8
|
+
import style from './style/bubble.shadow.css';
|
|
9
|
+
import ClipPath from './ClipPath';
|
|
10
|
+
import { scaleSqrt } from 'd3-scale';
|
|
11
|
+
|
|
12
|
+
const memoize = (func) => {
|
|
13
|
+
const results = {};
|
|
14
|
+
return (argsKey) => {
|
|
15
|
+
if (!results[argsKey]) {
|
|
16
|
+
results[argsKey] = func(argsKey);
|
|
17
|
+
}
|
|
18
|
+
return results[argsKey];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const measureText = memoize((text) => {
|
|
23
|
+
let span = document.createElement('span');
|
|
24
|
+
span.append(document.createTextNode(text));
|
|
25
|
+
span.style.display = 'inline-block';
|
|
26
|
+
document.body.append(span);
|
|
27
|
+
const textLength = span.offsetWidth;
|
|
28
|
+
span.remove();
|
|
29
|
+
return textLength;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
class BubbleRoot extends Component {
|
|
33
|
+
static displayName = 'Bubble';
|
|
34
|
+
static style = style;
|
|
35
|
+
static enhance = [uniqueIDEnhancement()];
|
|
36
|
+
|
|
37
|
+
static defaultProps = {
|
|
38
|
+
offset: [0, 0],
|
|
39
|
+
duration: 500,
|
|
40
|
+
markedCross: true,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
virtualElement = canUseDOM() ? document.createElement('div') : {};
|
|
44
|
+
|
|
45
|
+
generateGetBoundingClientRect(x = 0, y = 0) {
|
|
46
|
+
return () => ({ width: 0, height: 0, top: y, right: x, bottom: y, left: x });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
bindHandlerTooltip = (visible, props) => ({ clientX: x, clientY: y }) => {
|
|
50
|
+
const { eventEmitter } = this.asProps;
|
|
51
|
+
this.virtualElement.getBoundingClientRect = this.generateGetBoundingClientRect(x, y);
|
|
52
|
+
this.virtualElement[CONSTANT.VIRTUAL_ELEMENT] = true;
|
|
53
|
+
eventEmitter.emit('onTooltipVisible', visible, props, this.virtualElement);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
animationCircle() {
|
|
57
|
+
const { duration, uid, data, value } = this.asProps;
|
|
58
|
+
const z = scaleSqrt()
|
|
59
|
+
.domain([0, Math.max(...data.map((el) => el[value]))])
|
|
60
|
+
.range([5.5, 50.5]);
|
|
61
|
+
|
|
62
|
+
const selectRect = transition()
|
|
63
|
+
.selection()
|
|
64
|
+
.selectAll(`[id^=${uid}${uid}]`)
|
|
65
|
+
.attr('r', 0);
|
|
66
|
+
|
|
67
|
+
const selectRectNode = selectRect.node();
|
|
68
|
+
if (duration > 0 && selectRectNode) {
|
|
69
|
+
selectRect
|
|
70
|
+
.transition()
|
|
71
|
+
.duration(duration)
|
|
72
|
+
.attr('r', function(_, ind) {
|
|
73
|
+
return z(data[ind][value]);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
componentDidUpdate() {
|
|
79
|
+
this.animationCircle();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
componentDidMount() {
|
|
83
|
+
this.animationCircle();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
renderCircle(d, i) {
|
|
87
|
+
const {
|
|
88
|
+
color,
|
|
89
|
+
scale,
|
|
90
|
+
x,
|
|
91
|
+
y,
|
|
92
|
+
offset,
|
|
93
|
+
styles,
|
|
94
|
+
uid,
|
|
95
|
+
duration,
|
|
96
|
+
value,
|
|
97
|
+
label,
|
|
98
|
+
markedCross,
|
|
99
|
+
size,
|
|
100
|
+
data,
|
|
101
|
+
} = this.asProps;
|
|
102
|
+
const [xScale, yScale] = scale;
|
|
103
|
+
|
|
104
|
+
const SBubble = this.Element;
|
|
105
|
+
const SCenter = 'text';
|
|
106
|
+
const SLabel = 'text';
|
|
107
|
+
const z = scaleSqrt()
|
|
108
|
+
.domain([0, Math.max(...data.map((el) => el[value]))])
|
|
109
|
+
.range([5.5, 50.5]);
|
|
110
|
+
|
|
111
|
+
const margin = Math.min(xScale.range()[0], xScale.range()[1]);
|
|
112
|
+
|
|
113
|
+
const labelPosition =
|
|
114
|
+
size[0] - 2 * margin - (xScale(d[x]) + offset[0] + z(d[value])) < measureText(d[label])
|
|
115
|
+
? 'right'
|
|
116
|
+
: 'left';
|
|
117
|
+
const labelDistance = {
|
|
118
|
+
right: xScale(d[x]) + offset[0] - z(d[value]),
|
|
119
|
+
left: xScale(d[x]) + offset[0] + z(d[value]),
|
|
120
|
+
}[labelPosition];
|
|
121
|
+
|
|
122
|
+
return sstyled(styles)(
|
|
123
|
+
<g
|
|
124
|
+
key={`circle(#${i})`}
|
|
125
|
+
onMouseMove={this.bindHandlerTooltip(true, { ...this.props, xIndex: i })}
|
|
126
|
+
onMouseLeave={this.bindHandlerTooltip(false, { ...this.props, xIndex: i })}
|
|
127
|
+
>
|
|
128
|
+
{markedCross && (
|
|
129
|
+
<SCenter
|
|
130
|
+
x={xScale(d[x]) + offset[0]}
|
|
131
|
+
y={yScale(d[y]) + offset[1]}
|
|
132
|
+
dy=".3em"
|
|
133
|
+
clipPath={`url(#${uid})`}
|
|
134
|
+
color={d[color] ?? color}
|
|
135
|
+
>
|
|
136
|
+
+
|
|
137
|
+
</SCenter>
|
|
138
|
+
)}
|
|
139
|
+
<SBubble
|
|
140
|
+
id={`${uid}${uid}`}
|
|
141
|
+
render="circle"
|
|
142
|
+
clipPath={`url(#${uid})`}
|
|
143
|
+
cx={xScale(d[x]) + offset[0]}
|
|
144
|
+
cy={yScale(d[y]) + offset[1]}
|
|
145
|
+
color={d[color]}
|
|
146
|
+
r={z(d[value])}
|
|
147
|
+
use:duration={`${duration}ms`}
|
|
148
|
+
/>
|
|
149
|
+
{d[label] && (
|
|
150
|
+
<SLabel
|
|
151
|
+
x={labelDistance}
|
|
152
|
+
y={yScale(d[y]) + offset[1]}
|
|
153
|
+
dy=".3em"
|
|
154
|
+
clipPath={`url(#${uid})`}
|
|
155
|
+
position={labelPosition}
|
|
156
|
+
color={d[color]}
|
|
157
|
+
>
|
|
158
|
+
{d[label]}
|
|
159
|
+
</SLabel>
|
|
160
|
+
)}
|
|
161
|
+
</g>,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
render() {
|
|
166
|
+
const { data, uid, size, scale } = this.asProps;
|
|
167
|
+
const [xScale, yScale] = scale;
|
|
168
|
+
const marginX = Math.min(xScale.range()[0], xScale.range()[1]);
|
|
169
|
+
const marginY = Math.min(yScale.range()[0], yScale.range()[1]);
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<>
|
|
173
|
+
{data.map(this.renderCircle.bind(this))}
|
|
174
|
+
{data.map(this.animationCircle.bind(this))}
|
|
175
|
+
<ClipPath
|
|
176
|
+
id={uid}
|
|
177
|
+
x={marginX}
|
|
178
|
+
y={marginY}
|
|
179
|
+
width={`${size[0] - 2 * marginX}px`}
|
|
180
|
+
height={`${size[1] - 2 * marginY}px`}
|
|
181
|
+
/>
|
|
182
|
+
</>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const Bubble = createElement(BubbleRoot);
|
|
188
|
+
|
|
189
|
+
export default Bubble;
|
package/src/Donut.js
CHANGED
|
@@ -181,12 +181,7 @@ class DonutRoot extends Component {
|
|
|
181
181
|
getEmptyDataProps() {
|
|
182
182
|
const { d3Arc } = this.asProps;
|
|
183
183
|
return {
|
|
184
|
-
data: {
|
|
185
|
-
endAngle: Math.PI * 2,
|
|
186
|
-
startAngle: 0,
|
|
187
|
-
},
|
|
188
184
|
d3Arc,
|
|
189
|
-
color: '#E4ECF1',
|
|
190
185
|
};
|
|
191
186
|
}
|
|
192
187
|
|
|
@@ -236,10 +231,16 @@ class DonutRoot extends Component {
|
|
|
236
231
|
}
|
|
237
232
|
}
|
|
238
233
|
|
|
239
|
-
function Pie({ Element: SPie, styles, d3Arc, data, color
|
|
234
|
+
function Pie({ Element: SPie, styles, d3Arc, data, color }) {
|
|
240
235
|
return sstyled(styles)(<SPie render="path" color={color} d={d3Arc(data)} />);
|
|
241
236
|
}
|
|
242
237
|
|
|
238
|
+
function EmptyData({ Element: SEmptyData, styles, d3Arc, color }) {
|
|
239
|
+
return sstyled(styles)(
|
|
240
|
+
<SEmptyData render="path" color={color} d={d3Arc({ endAngle: Math.PI * 2, startAngle: 0 })} />,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
243
244
|
function Label({ Element: SLabel, styles, Children }) {
|
|
244
245
|
return sstyled(styles)(
|
|
245
246
|
<SLabel render="text" x="0" y="0">
|
|
@@ -248,6 +249,6 @@ function Label({ Element: SLabel, styles, Children }) {
|
|
|
248
249
|
);
|
|
249
250
|
}
|
|
250
251
|
|
|
251
|
-
const Donut = createElement(DonutRoot, { Pie, Label, EmptyData
|
|
252
|
+
const Donut = createElement(DonutRoot, { Pie, Label, EmptyData });
|
|
252
253
|
|
|
253
254
|
export default Donut;
|
package/src/GroupBar.js
CHANGED
|
@@ -20,10 +20,14 @@ class GroupBarRoot extends Component {
|
|
|
20
20
|
if (scaleGroup) return scaleGroup;
|
|
21
21
|
|
|
22
22
|
const domain = React.Children.toArray(getOriginChildren(Children)).reduce((acc, child) => {
|
|
23
|
-
if (React.isValidElement(child) && child.type === GroupBar.Bar) {
|
|
23
|
+
if (React.isValidElement(child) && child.type === GroupBar.Bar && !child.props.hide) {
|
|
24
24
|
acc.push(child.props.y);
|
|
25
25
|
}
|
|
26
|
-
if (
|
|
26
|
+
if (
|
|
27
|
+
React.isValidElement(child) &&
|
|
28
|
+
child.type === GroupBar.HorizontalBar &&
|
|
29
|
+
!child.props.hide
|
|
30
|
+
) {
|
|
27
31
|
acc.push(child.props.x);
|
|
28
32
|
}
|
|
29
33
|
return acc;
|
package/src/HorizontalBar.js
CHANGED
|
@@ -13,7 +13,6 @@ class HorizontalBarRoot extends Component {
|
|
|
13
13
|
static style = style;
|
|
14
14
|
|
|
15
15
|
static defaultProps = {
|
|
16
|
-
color: '#50aef4',
|
|
17
16
|
offset: [0, 0],
|
|
18
17
|
duration: 500,
|
|
19
18
|
r: 2,
|
|
@@ -44,20 +43,18 @@ class HorizontalBarRoot extends Component {
|
|
|
44
43
|
onMouseMove,
|
|
45
44
|
onMouseLeave,
|
|
46
45
|
} = this.asProps;
|
|
46
|
+
|
|
47
47
|
const [xScale, yScale] = scale;
|
|
48
48
|
const barY = yScale(d[y]) + offset[1];
|
|
49
49
|
const barX = xScale(Math.min(d[x0] ?? 0, d[x])) + offset[0];
|
|
50
50
|
const height = heightProps || getBandwidth(yScale);
|
|
51
|
-
|
|
52
|
-
width = isRounded ? width + r : width;
|
|
53
|
-
const isRounded = r !== 0;
|
|
54
|
-
const xValue = isRounded ? (d[x] > 0 ? barX : barX - r) : barX;
|
|
51
|
+
const width = Math.abs(xScale(d[x]) - Math.max(xScale(xScale.domain()[0]), xScale(d[x0] ?? 0)));
|
|
55
52
|
const dSvg = getHorizontalRect({
|
|
56
|
-
x:
|
|
53
|
+
x: barX,
|
|
57
54
|
y: barY,
|
|
58
55
|
width,
|
|
59
56
|
height,
|
|
60
|
-
radius: r,
|
|
57
|
+
radius: Array.isArray(r) ? r[i] : r,
|
|
61
58
|
position: d[x] > 0 ? 'right' : 'left',
|
|
62
59
|
});
|
|
63
60
|
|
|
@@ -72,7 +69,7 @@ class HorizontalBarRoot extends Component {
|
|
|
72
69
|
index={i}
|
|
73
70
|
hide={hide}
|
|
74
71
|
color={color}
|
|
75
|
-
x={
|
|
72
|
+
x={barX}
|
|
76
73
|
y={barY}
|
|
77
74
|
width={width}
|
|
78
75
|
height={height}
|
package/src/Line.js
CHANGED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Component, sstyled } from '@semcore/core';
|
|
3
|
+
import canUseDOM from '@semcore/utils/lib/canUseDOM';
|
|
4
|
+
import { CONSTANT } from './utils';
|
|
5
|
+
import createElement from './createElement';
|
|
6
|
+
import uniqueIDEnhancement from '@semcore/utils/lib/uniqueID';
|
|
7
|
+
import { transition } from 'd3-transition';
|
|
8
|
+
import style from './style/scatterplot.shadow.css';
|
|
9
|
+
import ClipPath from './ClipPath';
|
|
10
|
+
|
|
11
|
+
class ScatterPlotRoot extends Component {
|
|
12
|
+
static displayName = 'ScatterPlot';
|
|
13
|
+
static style = style;
|
|
14
|
+
static enhance = [uniqueIDEnhancement()];
|
|
15
|
+
|
|
16
|
+
static defaultProps = {
|
|
17
|
+
offset: [0, 0],
|
|
18
|
+
duration: 500,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
virtualElement = canUseDOM() ? document.createElement('div') : {};
|
|
22
|
+
|
|
23
|
+
generateGetBoundingClientRect(x = 0, y = 0) {
|
|
24
|
+
return () => ({ width: 0, height: 0, top: y, right: x, bottom: y, left: x });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
bindHandlerTooltip = (visible, props) => ({ clientX: x, clientY: y }) => {
|
|
28
|
+
const { eventEmitter } = this.asProps;
|
|
29
|
+
this.virtualElement.getBoundingClientRect = this.generateGetBoundingClientRect(x, y);
|
|
30
|
+
this.virtualElement[CONSTANT.VIRTUAL_ELEMENT] = true;
|
|
31
|
+
eventEmitter.emit('onTooltipVisible', visible, props, this.virtualElement);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
animationCircle() {
|
|
35
|
+
const { duration, uid, r, value } = this.asProps;
|
|
36
|
+
const radius = r ? r : value ? 12 : 5.5;
|
|
37
|
+
const selectRect = transition()
|
|
38
|
+
.selection()
|
|
39
|
+
.selectAll(`[id^=${uid}]`)
|
|
40
|
+
.attr('r', 0);
|
|
41
|
+
const selectRectNode = selectRect.node();
|
|
42
|
+
|
|
43
|
+
if (duration > 0 && selectRectNode) {
|
|
44
|
+
selectRect
|
|
45
|
+
.transition()
|
|
46
|
+
.duration(duration)
|
|
47
|
+
.attr('r', radius);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
componentDidUpdate() {
|
|
52
|
+
this.animationCircle();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
componentDidMount() {
|
|
56
|
+
this.animationCircle();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
renderCircle(d, i) {
|
|
60
|
+
const {
|
|
61
|
+
color,
|
|
62
|
+
scale,
|
|
63
|
+
x,
|
|
64
|
+
y,
|
|
65
|
+
r,
|
|
66
|
+
offset,
|
|
67
|
+
styles,
|
|
68
|
+
uid,
|
|
69
|
+
duration,
|
|
70
|
+
value,
|
|
71
|
+
valueColor,
|
|
72
|
+
} = this.asProps;
|
|
73
|
+
const [xScale, yScale] = scale;
|
|
74
|
+
const SScatterPlot = this.Element;
|
|
75
|
+
const SValue = 'text';
|
|
76
|
+
return sstyled(styles)(
|
|
77
|
+
<g
|
|
78
|
+
key={`circle(#${i})`}
|
|
79
|
+
onMouseMove={this.bindHandlerTooltip(true, { ...this.props, xIndex: i })}
|
|
80
|
+
onMouseLeave={this.bindHandlerTooltip(false, { ...this.props, xIndex: i })}
|
|
81
|
+
>
|
|
82
|
+
<SScatterPlot
|
|
83
|
+
id={`${uid}${i}`}
|
|
84
|
+
render="circle"
|
|
85
|
+
clipPath={`url(#${uid})`}
|
|
86
|
+
cx={xScale(d[x]) + offset[0]}
|
|
87
|
+
cy={yScale(d[y]) + offset[1]}
|
|
88
|
+
color={color}
|
|
89
|
+
r={r}
|
|
90
|
+
use:duration={`${duration}ms`}
|
|
91
|
+
/>
|
|
92
|
+
{d[value] && (
|
|
93
|
+
<SValue
|
|
94
|
+
x={xScale(d[x]) + offset[0]}
|
|
95
|
+
y={yScale(d[y]) + offset[1]}
|
|
96
|
+
dy=".3em"
|
|
97
|
+
clipPath={`url(#${uid})`}
|
|
98
|
+
color={valueColor}
|
|
99
|
+
>
|
|
100
|
+
{d[value]}
|
|
101
|
+
</SValue>
|
|
102
|
+
)}
|
|
103
|
+
</g>,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
render() {
|
|
108
|
+
const { data, uid, size, scale } = this.asProps;
|
|
109
|
+
const [xScale, yScale] = scale;
|
|
110
|
+
const marginX = Math.min(xScale.range()[0], xScale.range()[1]);
|
|
111
|
+
const marginY = Math.min(yScale.range()[0], yScale.range()[1]);
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<>
|
|
115
|
+
{data.map(this.renderCircle.bind(this))}
|
|
116
|
+
<ClipPath
|
|
117
|
+
id={uid}
|
|
118
|
+
x={marginX}
|
|
119
|
+
y={marginY}
|
|
120
|
+
width={`${size[0] - 2 * marginX}px`}
|
|
121
|
+
height={`${size[1] - 2 * marginY}px`}
|
|
122
|
+
/>
|
|
123
|
+
</>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const ScatterPlot = createElement(ScatterPlotRoot);
|
|
129
|
+
|
|
130
|
+
export default ScatterPlot;
|
package/src/StackBar.js
CHANGED
|
@@ -19,7 +19,7 @@ class StackBarRoot extends Component {
|
|
|
19
19
|
static defaultProps = () => {
|
|
20
20
|
const stack = d3Stack();
|
|
21
21
|
stack[DEFAULT_INSTANCE] = true;
|
|
22
|
-
return { stack };
|
|
22
|
+
return { stack, r: 2 };
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
getSeries() {
|
|
@@ -27,10 +27,14 @@ class StackBarRoot extends Component {
|
|
|
27
27
|
|
|
28
28
|
if (stack[DEFAULT_INSTANCE]) {
|
|
29
29
|
const keys = React.Children.toArray(getOriginChildren(Children)).reduce((acc, child) => {
|
|
30
|
-
if (React.isValidElement(child) && child.type === StackBar.Bar) {
|
|
30
|
+
if (React.isValidElement(child) && child.type === StackBar.Bar && !child.props.hide) {
|
|
31
31
|
acc.push(child.props.y);
|
|
32
32
|
}
|
|
33
|
-
if (
|
|
33
|
+
if (
|
|
34
|
+
React.isValidElement(child) &&
|
|
35
|
+
child.type === StackBar.HorizontalBar &&
|
|
36
|
+
!child.props.hide
|
|
37
|
+
) {
|
|
34
38
|
acc.push(child.props.x);
|
|
35
39
|
}
|
|
36
40
|
return acc;
|
|
@@ -42,9 +46,15 @@ class StackBarRoot extends Component {
|
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
getBarProps({ y }) {
|
|
45
|
-
const { x } = this.asProps;
|
|
49
|
+
const { x, r } = this.asProps;
|
|
46
50
|
|
|
47
|
-
const
|
|
51
|
+
const seriesIndex = this.series.findIndex((s) => s.key === y);
|
|
52
|
+
// or [] if hide bar
|
|
53
|
+
const series = this.series[seriesIndex] || [];
|
|
54
|
+
|
|
55
|
+
const rBar = series.map((s, i) =>
|
|
56
|
+
this.series.slice(seriesIndex + 1).some((bar) => bar[i][0] !== bar[i][1]) ? 0 : r,
|
|
57
|
+
);
|
|
48
58
|
|
|
49
59
|
return {
|
|
50
60
|
data: series.map((s) => ({
|
|
@@ -54,13 +64,19 @@ class StackBarRoot extends Component {
|
|
|
54
64
|
})),
|
|
55
65
|
y0: XY0,
|
|
56
66
|
x,
|
|
67
|
+
r: rBar,
|
|
57
68
|
};
|
|
58
69
|
}
|
|
59
70
|
|
|
60
71
|
getHorizontalBarProps({ x }) {
|
|
61
|
-
const { y } = this.asProps;
|
|
72
|
+
const { y, r } = this.asProps;
|
|
73
|
+
|
|
74
|
+
const seriesIndex = this.series.findIndex((s) => s.key === x);
|
|
75
|
+
const series = this.series[seriesIndex];
|
|
62
76
|
|
|
63
|
-
const
|
|
77
|
+
const rBar = series.map((s, i) =>
|
|
78
|
+
this.series.slice(seriesIndex + 1).some((bar) => bar[i][0] !== bar[i][1]) ? 0 : r,
|
|
79
|
+
);
|
|
64
80
|
|
|
65
81
|
return {
|
|
66
82
|
data: series.map((s) => ({
|
|
@@ -70,6 +86,7 @@ class StackBarRoot extends Component {
|
|
|
70
86
|
})),
|
|
71
87
|
x0: XY0,
|
|
72
88
|
y,
|
|
89
|
+
r: rBar,
|
|
73
90
|
};
|
|
74
91
|
}
|
|
75
92
|
|
package/src/StackedArea.js
CHANGED
|
@@ -26,7 +26,7 @@ class StackedAreaRoot extends Component {
|
|
|
26
26
|
|
|
27
27
|
if (stack[DEFAULT_INSTANCE]) {
|
|
28
28
|
const keys = React.Children.toArray(getOriginChildren(Children)).reduce((acc, child) => {
|
|
29
|
-
if (React.isValidElement(child) && child.type === StackedArea.Area) {
|
|
29
|
+
if (React.isValidElement(child) && child.type === StackedArea.Area && !child.props.hide) {
|
|
30
30
|
acc.push(child.props.y);
|
|
31
31
|
}
|
|
32
32
|
return acc;
|
|
@@ -39,7 +39,8 @@ class StackedAreaRoot extends Component {
|
|
|
39
39
|
|
|
40
40
|
getAreaProps({ y }) {
|
|
41
41
|
const { x } = this.asProps;
|
|
42
|
-
|
|
42
|
+
// or [] if hide area
|
|
43
|
+
const series = this.series.find((s) => s.key === y) || [];
|
|
43
44
|
return {
|
|
44
45
|
data: series.map((s) => ({
|
|
45
46
|
...s.data,
|
package/src/Tooltip.js
CHANGED
|
@@ -3,9 +3,9 @@ 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';
|
|
7
6
|
import { CONSTANT } from './utils';
|
|
8
7
|
import createElement from './createElement';
|
|
8
|
+
import resolveColor from '@semcore/utils/lib/color';
|
|
9
9
|
|
|
10
10
|
import style from './style/tooltip.shadow.css';
|
|
11
11
|
|
|
@@ -96,14 +96,20 @@ class TooltipRoot extends Component {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
function PopperPopper(props) {
|
|
99
|
-
const { Element: STooltip, styles, $visible } = props;
|
|
99
|
+
const { Element: STooltip, styles, $visible, x, y } = props;
|
|
100
100
|
|
|
101
101
|
const handlerCancel = useCallback(() => false, []);
|
|
102
102
|
|
|
103
103
|
if (!$visible) return null;
|
|
104
104
|
|
|
105
105
|
return sstyled(styles)(
|
|
106
|
-
<STooltip
|
|
106
|
+
<STooltip
|
|
107
|
+
render={Popper.Popper}
|
|
108
|
+
childrenPosition="inside"
|
|
109
|
+
onMouseMove={handlerCancel}
|
|
110
|
+
x={x}
|
|
111
|
+
y={y}
|
|
112
|
+
/>,
|
|
107
113
|
);
|
|
108
114
|
}
|
|
109
115
|
|
|
@@ -114,7 +120,7 @@ function Title(props) {
|
|
|
114
120
|
}
|
|
115
121
|
|
|
116
122
|
function Dot(props) {
|
|
117
|
-
const { styles, color
|
|
123
|
+
const { styles, color, Children } = props;
|
|
118
124
|
const SDotGroup = Root;
|
|
119
125
|
const SDot = Box;
|
|
120
126
|
return sstyled(styles)(
|
package/src/Venn.js
CHANGED
|
@@ -81,7 +81,7 @@ class VennRoot extends Component {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
function Circle({ Element: SCircle, styles, color
|
|
84
|
+
function Circle({ Element: SCircle, styles, color, data, duration }) {
|
|
85
85
|
return sstyled(styles)(
|
|
86
86
|
<SCircle
|
|
87
87
|
render="circle"
|
package/src/color.js
CHANGED
|
@@ -1,35 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
'
|
|
5
|
-
|
|
6
|
-
'blue-05': '#084c80',
|
|
7
|
-
'green-01': '#3ab011',
|
|
8
|
-
'green-02': '#91d27b',
|
|
9
|
-
'green-03': '#278707',
|
|
10
|
-
'green-04': '#d1edc8',
|
|
11
|
-
'green-05': '#1a6700',
|
|
12
|
-
'orange-01': '#ff8e29',
|
|
13
|
-
'orange-02': '#fec089',
|
|
14
|
-
'orange-03': '#da6905',
|
|
15
|
-
'orange-04': '#ffe5cd',
|
|
16
|
-
'orange-05': '#a14e03',
|
|
17
|
-
'violet-01': '#890c85',
|
|
18
|
-
'violet-02': '#c783c5',
|
|
19
|
-
'violet-03': '#6e026b',
|
|
20
|
-
'violet-04': '#e7cbe6',
|
|
21
|
-
'violet-05': '#4d024b',
|
|
22
|
-
'red-01': '#e91e25',
|
|
23
|
-
'red-02': '#f69498',
|
|
24
|
-
'red-03': '#bd0000',
|
|
25
|
-
'red-04': '#fbd2d3',
|
|
26
|
-
'red-05': '#830005',
|
|
27
|
-
'yellow-01': '#ffc83f',
|
|
28
|
-
'yellow-02': '#ffdb82',
|
|
29
|
-
'yellow-03': '#e4aa18',
|
|
30
|
-
'yellow-04': '#ffebb9',
|
|
31
|
-
'yellow-05': '#b3840c',
|
|
32
|
-
};
|
|
1
|
+
/*__semcore-vars__:"./style/var.css"*/
|
|
2
|
+
const colors = preval`
|
|
3
|
+
const path = require('path');
|
|
4
|
+
module.exports = require('@semcore/babel-plugin-react-semcore/utils/vars')(path.resolve(__dirname, './style/var.css'));
|
|
5
|
+
`;
|
|
33
6
|
|
|
34
7
|
let componentRenderIndex = 0;
|
|
35
8
|
const cache = {};
|
|
@@ -37,6 +10,7 @@ const colorValues = Object.keys(colors).sort((a, b) => {
|
|
|
37
10
|
return parseInt(a.match(/[0-9]/g).join(''), 10) - parseInt(b.match(/[0-9]/g).join(''), 10);
|
|
38
11
|
});
|
|
39
12
|
|
|
13
|
+
export { colors };
|
|
40
14
|
export default function getColor(key) {
|
|
41
15
|
if (cache[key]) {
|
|
42
16
|
return cache[key];
|
package/src/index.js
CHANGED
|
@@ -10,6 +10,8 @@ export { default as GroupBar } from './GroupBar';
|
|
|
10
10
|
export { default as StackBar } from './StackBar';
|
|
11
11
|
export { default as Area } from './Area';
|
|
12
12
|
export { default as StackedArea } from './StackedArea';
|
|
13
|
+
export { default as ScatterPlot } from './ScatterPlot';
|
|
14
|
+
export { default as Bubble } from './Bubble';
|
|
13
15
|
export { default as Donut } from './Donut';
|
|
14
16
|
export { default as Venn } from './Venn';
|
|
15
17
|
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
@import '@semcore/d3-chart/src/style/var.css';
|
|
2
|
+
|
|
1
3
|
SArea {
|
|
2
|
-
fill: var(--
|
|
4
|
+
fill: var(--blue-01);
|
|
3
5
|
fill-opacity: 0.4;
|
|
4
6
|
}
|
|
5
7
|
|
|
8
|
+
SArea[color] {
|
|
9
|
+
fill: var(--color);
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
SAreaLine {
|
|
7
|
-
stroke: var(--
|
|
13
|
+
stroke: var(--blue-01);
|
|
8
14
|
stroke-width: 3;
|
|
9
15
|
fill: transparent;
|
|
10
16
|
}
|
|
11
17
|
|
|
18
|
+
SAreaLine[color] {
|
|
19
|
+
stroke: var(--color);
|
|
20
|
+
}
|
|
21
|
+
|
|
12
22
|
SArea,
|
|
13
23
|
SAreaLine {
|
|
14
24
|
transition-property: d;
|
package/src/style/bar.shadow.css
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
@import '@semcore/utils/style/var.css';
|
|
2
|
+
@import '@semcore/d3-chart/src/style/var.css';
|
|
2
3
|
|
|
3
4
|
SBar {
|
|
4
|
-
fill: var(--
|
|
5
|
+
fill: var(--blue-01);
|
|
5
6
|
transition-property: height, width, y;
|
|
6
7
|
transition-duration: var(--duration);
|
|
7
8
|
transition-timing-function: ease-in-out;
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
SBar[color] {
|
|
12
|
+
fill: var(--color);
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
SBar[hide] {
|
|
11
16
|
display: none;
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
SBackground {
|
|
15
|
-
fill:
|
|
20
|
+
fill: var(--mystic);
|
|
16
21
|
}
|