@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/ReferenceLine.jsx
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Component, sstyled } from '@semcore/core';
|
|
3
|
-
import createElement from './createElement';
|
|
4
|
-
import { scaleOfBandwidth } from './utils';
|
|
5
|
-
|
|
6
|
-
import style from './style/reference-line.shadow.css';
|
|
7
|
-
|
|
8
|
-
const MAP_ORIENTATION = {
|
|
9
|
-
left: 'vertical',
|
|
10
|
-
right: 'vertical',
|
|
11
|
-
top: 'horizontal',
|
|
12
|
-
bottom: 'horizontal',
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const MAP_POSITION_LINE = {
|
|
16
|
-
vertical: ([xScale, yScale], value) => {
|
|
17
|
-
const yRange = yScale.range();
|
|
18
|
-
const x = scaleOfBandwidth(xScale, value);
|
|
19
|
-
return {
|
|
20
|
-
x: x,
|
|
21
|
-
y: yRange[1],
|
|
22
|
-
width: 0.1,
|
|
23
|
-
height: yRange[0] - yRange[1],
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
horizontal: ([xScale, yScale], value) => {
|
|
27
|
-
const xRange = xScale.range();
|
|
28
|
-
const y = scaleOfBandwidth(yScale, value);
|
|
29
|
-
return {
|
|
30
|
-
x: xRange[0],
|
|
31
|
-
y: y,
|
|
32
|
-
width: xRange[1] - xRange[0],
|
|
33
|
-
height: 0.1,
|
|
34
|
-
};
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const OFFSET_TITLE = 10;
|
|
39
|
-
const MAP_POSITION_TITlE = {
|
|
40
|
-
left: ([xScale, yScale], value) => {
|
|
41
|
-
const yRange = yScale.range();
|
|
42
|
-
const x = scaleOfBandwidth(xScale, value);
|
|
43
|
-
return {
|
|
44
|
-
x: x - OFFSET_TITLE,
|
|
45
|
-
y: (yRange[0] + yRange[1]) / 2,
|
|
46
|
-
};
|
|
47
|
-
},
|
|
48
|
-
right: ([xScale, yScale], value) => {
|
|
49
|
-
const yRange = yScale.range();
|
|
50
|
-
const x = scaleOfBandwidth(xScale, value);
|
|
51
|
-
return {
|
|
52
|
-
x: x + OFFSET_TITLE,
|
|
53
|
-
y: (yRange[0] + yRange[1]) / 2,
|
|
54
|
-
};
|
|
55
|
-
},
|
|
56
|
-
top: ([xScale, yScale], value) => {
|
|
57
|
-
const xRange = xScale.range();
|
|
58
|
-
const y = scaleOfBandwidth(yScale, value);
|
|
59
|
-
return {
|
|
60
|
-
x: (xRange[1] + xRange[0]) / 2,
|
|
61
|
-
y: y - OFFSET_TITLE,
|
|
62
|
-
};
|
|
63
|
-
},
|
|
64
|
-
bottom: ([xScale, yScale], value) => {
|
|
65
|
-
const xRange = xScale.range();
|
|
66
|
-
const y = scaleOfBandwidth(yScale, value);
|
|
67
|
-
return {
|
|
68
|
-
x: (xRange[1] + xRange[0]) / 2,
|
|
69
|
-
y: y + OFFSET_TITLE,
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
class ReferenceLineRoot extends Component {
|
|
75
|
-
static displayName = 'ReferenceLine';
|
|
76
|
-
static style = style;
|
|
77
|
-
static defaultProps = {
|
|
78
|
-
position: 'left',
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
getTitleProps() {
|
|
82
|
-
const { position, value } = this.asProps;
|
|
83
|
-
return { position, value };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
getBackgroundProps() {
|
|
87
|
-
const { position, value } = this.asProps;
|
|
88
|
-
return { position, value };
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
render() {
|
|
92
|
-
const SReferenceLine = this.Element;
|
|
93
|
-
const { title, scale, position, value, color, styles } = this.asProps;
|
|
94
|
-
const pos = MAP_POSITION_LINE[MAP_ORIENTATION[position]];
|
|
95
|
-
|
|
96
|
-
return sstyled(styles)(
|
|
97
|
-
<>
|
|
98
|
-
<SReferenceLine
|
|
99
|
-
render="rect"
|
|
100
|
-
__excludeProps={['data', 'scale', 'format', 'value', 'color']}
|
|
101
|
-
stroke={color}
|
|
102
|
-
{...pos(scale, value)}
|
|
103
|
-
/>
|
|
104
|
-
{title && <ReferenceLine.Title>{title}</ReferenceLine.Title>}
|
|
105
|
-
</>,
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function Title(props) {
|
|
111
|
-
const { Element: STitle, styles, scale, position, value } = props;
|
|
112
|
-
const { x, y } = MAP_POSITION_TITlE[position](scale, value);
|
|
113
|
-
|
|
114
|
-
const sstyles = sstyled(styles);
|
|
115
|
-
const sTitleStyles = sstyles.cn('STitle', {
|
|
116
|
-
'transform-origin': `${x.toFixed(2)}px ${y.toFixed(2)}px`,
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
return sstyled(styles)(
|
|
120
|
-
<STitle
|
|
121
|
-
render="text"
|
|
122
|
-
childrenPosition="inside"
|
|
123
|
-
className={sTitleStyles.className}
|
|
124
|
-
style={sTitleStyles.style}
|
|
125
|
-
position={position}
|
|
126
|
-
x={x}
|
|
127
|
-
y={y}
|
|
128
|
-
/>,
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function Background(props) {
|
|
133
|
-
const { Element: SBackground, styles, scale, position, value } = props;
|
|
134
|
-
const pos = MAP_POSITION_LINE[MAP_ORIENTATION[position]];
|
|
135
|
-
|
|
136
|
-
return sstyled(styles)(
|
|
137
|
-
<SBackground render="rect" childrenPosition="inside" {...pos(scale, value)} />,
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const ReferenceLine = createElement(ReferenceLineRoot, {
|
|
142
|
-
Title,
|
|
143
|
-
Background,
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
export default ReferenceLine;
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import ResizeObserver from 'resize-observer-polyfill';
|
|
3
|
-
|
|
4
|
-
import createComponent, { Component, Root, sstyled } from '@semcore/core';
|
|
5
|
-
import { Box } from '@semcore/flex-box';
|
|
6
|
-
import trottle from '@semcore/utils/lib/rafTrottle';
|
|
7
|
-
import fire from '@semcore/utils/lib/fire';
|
|
8
|
-
import getOriginChildren from '@semcore/utils/lib/getOriginChildren';
|
|
9
|
-
|
|
10
|
-
class ResponsiveContainerRoot extends Component {
|
|
11
|
-
static displayName = 'ResponsiveContainer';
|
|
12
|
-
|
|
13
|
-
containerRef = React.createRef();
|
|
14
|
-
size = [0, 0];
|
|
15
|
-
|
|
16
|
-
constructor(props) {
|
|
17
|
-
super(props);
|
|
18
|
-
this.observer = new ResizeObserver(this.handleResize);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get $container() {
|
|
22
|
-
return this.containerRef.current;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
handleResize = trottle((entries) => {
|
|
26
|
-
const { Children, aspect } = this.asProps;
|
|
27
|
-
let { clientWidth: width, clientHeight: height } = this.$container;
|
|
28
|
-
|
|
29
|
-
if (aspect) {
|
|
30
|
-
const style = window.getComputedStyle(this.$container);
|
|
31
|
-
const minHeight = Number.parseInt(style.getPropertyValue('min-height'));
|
|
32
|
-
const maxHeight = Number.parseInt(style.getPropertyValue('max-height'));
|
|
33
|
-
height = width * aspect;
|
|
34
|
-
|
|
35
|
-
if (height < minHeight) {
|
|
36
|
-
height = minHeight;
|
|
37
|
-
}
|
|
38
|
-
if (height > maxHeight) {
|
|
39
|
-
height = maxHeight;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (this.size[0] === width && this.size[1] === height) return;
|
|
44
|
-
|
|
45
|
-
this.size = [width, height];
|
|
46
|
-
|
|
47
|
-
fire(this, 'onResize', this.size, entries);
|
|
48
|
-
|
|
49
|
-
if (typeof getOriginChildren(Children) === 'function') {
|
|
50
|
-
this.forceUpdate();
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
setContext() {
|
|
55
|
-
const [width, height] = this.size;
|
|
56
|
-
return {
|
|
57
|
-
width,
|
|
58
|
-
height,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
componentDidMount() {
|
|
63
|
-
if (this.$container) {
|
|
64
|
-
// TODO: may be we can increase perfomance here? (by lsroman)
|
|
65
|
-
this.observer.observe(this.$container);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// TODO component did update ref?
|
|
70
|
-
|
|
71
|
-
componentWillUnmount() {
|
|
72
|
-
this.observer.disconnect();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
render() {
|
|
76
|
-
const SResponsiveContainer = Root;
|
|
77
|
-
const { styles } = this.asProps;
|
|
78
|
-
return sstyled(styles)(<SResponsiveContainer render={Box} ref={this.containerRef} />);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const ResponsiveContainer = createComponent(ResponsiveContainerRoot);
|
|
83
|
-
|
|
84
|
-
export default ResponsiveContainer;
|
package/src/ScatterPlot.jsx
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
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 =
|
|
28
|
-
(visible, props) =>
|
|
29
|
-
({ clientX: x, clientY: y }) => {
|
|
30
|
-
const { eventEmitter } = this.asProps;
|
|
31
|
-
this.virtualElement.getBoundingClientRect = this.generateGetBoundingClientRect(x, y);
|
|
32
|
-
this.virtualElement[CONSTANT.VIRTUAL_ELEMENT] = true;
|
|
33
|
-
eventEmitter.emit('onTooltipVisible', visible, props, this.virtualElement);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
animationCircle() {
|
|
37
|
-
const { duration, uid, r, value } = this.asProps;
|
|
38
|
-
const radius = r ? r : value ? 12 : 5.5;
|
|
39
|
-
const selectRect = transition().selection().selectAll(`[id^=${uid}]`).attr('r', 0);
|
|
40
|
-
const selectRectNode = selectRect.node();
|
|
41
|
-
|
|
42
|
-
if (duration > 0 && selectRectNode) {
|
|
43
|
-
selectRect.transition().duration(duration).attr('r', radius);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
componentDidUpdate() {
|
|
48
|
-
this.animationCircle();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
componentDidMount() {
|
|
52
|
-
this.animationCircle();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
renderCircle(d, i) {
|
|
56
|
-
const { color, scale, x, y, r, offset, styles, uid, duration, value, valueColor } =
|
|
57
|
-
this.asProps;
|
|
58
|
-
const [xScale, yScale] = scale;
|
|
59
|
-
const SScatterPlot = this.Element;
|
|
60
|
-
const SValue = 'text';
|
|
61
|
-
return sstyled(styles)(
|
|
62
|
-
<g
|
|
63
|
-
key={`circle(#${i})`}
|
|
64
|
-
onMouseMove={this.bindHandlerTooltip(true, { ...this.props, xIndex: i })}
|
|
65
|
-
onMouseLeave={this.bindHandlerTooltip(false, { ...this.props, xIndex: i })}
|
|
66
|
-
>
|
|
67
|
-
<SScatterPlot
|
|
68
|
-
id={`${uid}${i}`}
|
|
69
|
-
index={i}
|
|
70
|
-
render="circle"
|
|
71
|
-
clipPath={`url(#${uid})`}
|
|
72
|
-
cx={xScale(d[x]) + offset[0]}
|
|
73
|
-
cy={yScale(d[y]) + offset[1]}
|
|
74
|
-
color={color}
|
|
75
|
-
r={r}
|
|
76
|
-
use:duration={`${duration}ms`}
|
|
77
|
-
/>
|
|
78
|
-
{d[value] && (
|
|
79
|
-
<SValue
|
|
80
|
-
x={xScale(d[x]) + offset[0]}
|
|
81
|
-
y={yScale(d[y]) + offset[1]}
|
|
82
|
-
dy=".3em"
|
|
83
|
-
clipPath={`url(#${uid})`}
|
|
84
|
-
color={valueColor}
|
|
85
|
-
>
|
|
86
|
-
{d[value]}
|
|
87
|
-
</SValue>
|
|
88
|
-
)}
|
|
89
|
-
</g>,
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
render() {
|
|
94
|
-
const { data, uid, scale } = this.asProps;
|
|
95
|
-
const [xScale, yScale] = scale;
|
|
96
|
-
const xSize = Math.abs(xScale.range()[0] - xScale.range()[1]);
|
|
97
|
-
const ySize = Math.abs(yScale.range()[0] - yScale.range()[1]);
|
|
98
|
-
const xMargin = Math.min(xScale.range()[0], xScale.range()[1]);
|
|
99
|
-
const yMargin = Math.min(yScale.range()[0], yScale.range()[1]);
|
|
100
|
-
|
|
101
|
-
return (
|
|
102
|
-
<>
|
|
103
|
-
{data.map(this.renderCircle.bind(this))}
|
|
104
|
-
<ClipPath id={uid} x={xMargin} y={yMargin} width={`${xSize}px`} height={`${ySize}px`} />
|
|
105
|
-
</>
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const ScatterPlot = createElement(ScatterPlotRoot);
|
|
111
|
-
|
|
112
|
-
export default ScatterPlot;
|
package/src/StackBar.jsx
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { stack as d3Stack } from 'd3-shape';
|
|
3
|
-
import { Component } from '@semcore/core';
|
|
4
|
-
import getOriginChildren from '@semcore/utils/lib/getOriginChildren';
|
|
5
|
-
import createElement from './createElement';
|
|
6
|
-
import Bar from './Bar';
|
|
7
|
-
import HorizontalBar from './HorizontalBar';
|
|
8
|
-
|
|
9
|
-
import style from './style/bar.shadow.css';
|
|
10
|
-
|
|
11
|
-
const DEFAULT_INSTANCE = Symbol('DEFAULT_INSTANCE');
|
|
12
|
-
const XY0 = Symbol('XY0');
|
|
13
|
-
|
|
14
|
-
class StackBarRoot extends Component {
|
|
15
|
-
static displayName = 'StackBar';
|
|
16
|
-
|
|
17
|
-
static style = style;
|
|
18
|
-
|
|
19
|
-
static defaultProps = () => {
|
|
20
|
-
const stack = d3Stack();
|
|
21
|
-
stack[DEFAULT_INSTANCE] = true;
|
|
22
|
-
return { stack, r: 2 };
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
getSeries() {
|
|
26
|
-
const { Children, data, stack } = this.asProps;
|
|
27
|
-
|
|
28
|
-
if (stack[DEFAULT_INSTANCE]) {
|
|
29
|
-
const keys = React.Children.toArray(getOriginChildren(Children)).reduce((acc, child) => {
|
|
30
|
-
if (React.isValidElement(child) && child.type === StackBar.Bar && !child.props.hide) {
|
|
31
|
-
acc.push(child.props.y);
|
|
32
|
-
}
|
|
33
|
-
if (
|
|
34
|
-
React.isValidElement(child) &&
|
|
35
|
-
child.type === StackBar.HorizontalBar &&
|
|
36
|
-
!child.props.hide
|
|
37
|
-
) {
|
|
38
|
-
acc.push(child.props.x);
|
|
39
|
-
}
|
|
40
|
-
return acc;
|
|
41
|
-
}, []);
|
|
42
|
-
stack.keys(keys);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return stack(data);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
getBarProps({ y }) {
|
|
49
|
-
const { x, r } = this.asProps;
|
|
50
|
-
|
|
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
|
-
);
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
data: series.map((s) => ({
|
|
61
|
-
...s.data,
|
|
62
|
-
[y]: s[1],
|
|
63
|
-
[XY0]: s[0],
|
|
64
|
-
})),
|
|
65
|
-
y0: XY0,
|
|
66
|
-
x,
|
|
67
|
-
r: rBar,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
getHorizontalBarProps({ x }) {
|
|
72
|
-
const { y, r } = this.asProps;
|
|
73
|
-
|
|
74
|
-
const seriesIndex = this.series.findIndex((s) => s.key === x);
|
|
75
|
-
const series = this.series[seriesIndex];
|
|
76
|
-
|
|
77
|
-
const rBar = series.map((s, i) =>
|
|
78
|
-
this.series.slice(seriesIndex + 1).some((bar) => bar[i][0] !== bar[i][1]) ? 0 : r,
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
data: series.map((s) => ({
|
|
83
|
-
...s.data,
|
|
84
|
-
[x]: s[1],
|
|
85
|
-
[XY0]: s[0],
|
|
86
|
-
})),
|
|
87
|
-
x0: XY0,
|
|
88
|
-
y,
|
|
89
|
-
r: rBar,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
render() {
|
|
94
|
-
const Element = this.Element;
|
|
95
|
-
this.series = this.getSeries();
|
|
96
|
-
return <Element render="g" series={this.series} />;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const StackBar = createElement(StackBarRoot, {
|
|
101
|
-
Bar,
|
|
102
|
-
HorizontalBar,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
export default StackBar;
|
package/src/StackedArea.jsx
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { stack as d3Stack } from 'd3-shape';
|
|
3
|
-
import { Component } from '@semcore/core';
|
|
4
|
-
import getOriginChildren from '@semcore/utils/lib/getOriginChildren';
|
|
5
|
-
import createElement from './createElement';
|
|
6
|
-
import Area from './Area';
|
|
7
|
-
|
|
8
|
-
import style from './style/area.shadow.css';
|
|
9
|
-
|
|
10
|
-
const DEFAULT_INSTANCE = Symbol('DEFAULT_INSTANCE');
|
|
11
|
-
const Y0 = Symbol('Y0');
|
|
12
|
-
|
|
13
|
-
class StackedAreaRoot extends Component {
|
|
14
|
-
static displayName = 'StackedArea';
|
|
15
|
-
|
|
16
|
-
static style = style;
|
|
17
|
-
|
|
18
|
-
static defaultProps = () => {
|
|
19
|
-
const stack = d3Stack();
|
|
20
|
-
stack[DEFAULT_INSTANCE] = true;
|
|
21
|
-
return { stack };
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
getSeries() {
|
|
25
|
-
const { Children, data, stack } = this.asProps;
|
|
26
|
-
|
|
27
|
-
if (stack[DEFAULT_INSTANCE]) {
|
|
28
|
-
const keys = React.Children.toArray(getOriginChildren(Children)).reduce((acc, child) => {
|
|
29
|
-
if (React.isValidElement(child) && child.type === StackedArea.Area && !child.props.hide) {
|
|
30
|
-
acc.push(child.props.y);
|
|
31
|
-
}
|
|
32
|
-
return acc;
|
|
33
|
-
}, []);
|
|
34
|
-
stack.keys(keys.reverse());
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return stack(data);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
getAreaProps({ y }) {
|
|
41
|
-
const { x } = this.asProps;
|
|
42
|
-
// or [] if hide area
|
|
43
|
-
const series = this.series.find((s) => s.key === y) || [];
|
|
44
|
-
return {
|
|
45
|
-
data: series.map((s) => ({
|
|
46
|
-
...s.data,
|
|
47
|
-
// if null is passed in the data, then we pass it, because d3 null leads to 0
|
|
48
|
-
[y]: s.data[y] === null ? null : s[1],
|
|
49
|
-
[Y0]: s[0],
|
|
50
|
-
})),
|
|
51
|
-
y0: Y0,
|
|
52
|
-
x,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
render() {
|
|
57
|
-
const Element = this.Element;
|
|
58
|
-
this.series = this.getSeries();
|
|
59
|
-
return <Element render="g" series={this.series} />;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const StackedArea = createElement(StackedAreaRoot, { Area });
|
|
64
|
-
|
|
65
|
-
export default StackedArea;
|
package/src/Tooltip.jsx
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import React, { useCallback } from 'react';
|
|
2
|
-
import { Component, Root, sstyled } from '@semcore/core';
|
|
3
|
-
import Popper from '@semcore/popper';
|
|
4
|
-
import { Box } from '@semcore/flex-box';
|
|
5
|
-
import findComponent from '@semcore/utils/lib/findComponent';
|
|
6
|
-
import { CONSTANT } from './utils';
|
|
7
|
-
import createElement from './createElement';
|
|
8
|
-
import resolveColor from '@semcore/utils/lib/color';
|
|
9
|
-
|
|
10
|
-
import style from './style/tooltip.shadow.css';
|
|
11
|
-
|
|
12
|
-
class TooltipRoot extends Component {
|
|
13
|
-
static displayName = 'Tooltip';
|
|
14
|
-
|
|
15
|
-
static style = style;
|
|
16
|
-
|
|
17
|
-
state = {
|
|
18
|
-
$visible: false,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
handlerCancel = () => false;
|
|
22
|
-
|
|
23
|
-
getTriggerProps() {
|
|
24
|
-
// TODO: как то убрать
|
|
25
|
-
const { x, y } = this.asProps;
|
|
26
|
-
return { x, y };
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getPopperProps() {
|
|
30
|
-
return {
|
|
31
|
-
...this.state,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
componentDidMount() {
|
|
36
|
-
const { eventEmitter, rootRef } = this.asProps;
|
|
37
|
-
this.unsubscribeTooltipVisible = eventEmitter.subscribe(
|
|
38
|
-
'onTooltipVisible',
|
|
39
|
-
(visible, data, node) => {
|
|
40
|
-
this.setState(
|
|
41
|
-
{
|
|
42
|
-
...data,
|
|
43
|
-
$visible: visible,
|
|
44
|
-
},
|
|
45
|
-
() => {
|
|
46
|
-
if (node && (node[CONSTANT.VIRTUAL_ELEMENT] || rootRef.current.contains(node))) {
|
|
47
|
-
this?.setPopperTrigger(node);
|
|
48
|
-
this.popper.current?.update();
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
);
|
|
52
|
-
},
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
componentWillUnmount() {
|
|
57
|
-
if (this.unsubscribeTooltipVisible) {
|
|
58
|
-
this.unsubscribeTooltipVisible();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
render() {
|
|
63
|
-
const { Children, children, tag, ...other } = this.asProps;
|
|
64
|
-
|
|
65
|
-
const advanceMode = !!findComponent(Children, [
|
|
66
|
-
Tooltip.Trigger.displayName,
|
|
67
|
-
Tooltip.Popper.displayName,
|
|
68
|
-
]);
|
|
69
|
-
return (
|
|
70
|
-
<Root
|
|
71
|
-
render={Popper}
|
|
72
|
-
visible={this.state.$visible}
|
|
73
|
-
onFirstUpdate={this.handlerCancel}
|
|
74
|
-
onOutsideClick={this.handlerCancel}
|
|
75
|
-
interaction="none"
|
|
76
|
-
offset={8}
|
|
77
|
-
flip={{ allowedAutoPlacements: ['left', 'right'] }}
|
|
78
|
-
>
|
|
79
|
-
{({ popper, setTrigger }) => {
|
|
80
|
-
this.setPopperTrigger = setTrigger;
|
|
81
|
-
this.popper = popper;
|
|
82
|
-
this.popper.current?.update();
|
|
83
|
-
return advanceMode ? (
|
|
84
|
-
<Children />
|
|
85
|
-
) : (
|
|
86
|
-
<>
|
|
87
|
-
{tag && <Tooltip.Trigger tag={tag} />}
|
|
88
|
-
<Tooltip.Popper {...other}>{children}</Tooltip.Popper>
|
|
89
|
-
</>
|
|
90
|
-
);
|
|
91
|
-
}}
|
|
92
|
-
</Root>
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function PopperPopper(props) {
|
|
98
|
-
const { Element: STooltip, styles, $visible, x, y } = props;
|
|
99
|
-
|
|
100
|
-
const handlerCancel = useCallback(() => false, []);
|
|
101
|
-
|
|
102
|
-
if (!$visible) return null;
|
|
103
|
-
|
|
104
|
-
return sstyled(styles)(
|
|
105
|
-
<STooltip
|
|
106
|
-
render={Popper.Popper}
|
|
107
|
-
childrenPosition="inside"
|
|
108
|
-
onMouseMove={handlerCancel}
|
|
109
|
-
x={x}
|
|
110
|
-
y={y}
|
|
111
|
-
/>,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function Title(props) {
|
|
116
|
-
const STitle = Root;
|
|
117
|
-
const { styles } = props;
|
|
118
|
-
return sstyled(styles)(<STitle render={Box} __excludeProps={['data', 'scale']} />);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function Dot(props) {
|
|
122
|
-
const { styles, color, Children } = props;
|
|
123
|
-
const SDotGroup = Root;
|
|
124
|
-
const SDot = Box;
|
|
125
|
-
return sstyled(styles)(
|
|
126
|
-
<SDotGroup render={Box} __excludeProps={['data', 'scale']}>
|
|
127
|
-
<SDot color={resolveColor(color)} />
|
|
128
|
-
<Children />
|
|
129
|
-
</SDotGroup>,
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function Footer() {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const Tooltip = createElement(TooltipRoot, {
|
|
138
|
-
Trigger: Popper.Trigger,
|
|
139
|
-
Popper: PopperPopper,
|
|
140
|
-
Title,
|
|
141
|
-
Footer,
|
|
142
|
-
Dot,
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
export default Tooltip;
|