@semcore/d3-chart 1.5.6 → 1.6.3
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 +22 -0
- package/lib/cjs/Area.js +6 -6
- package/lib/cjs/Axis.js +12 -12
- package/lib/cjs/Bar.js +5 -5
- package/lib/cjs/Bubble.js +276 -0
- package/lib/cjs/Bubble.js.map +1 -0
- package/lib/cjs/Donut.js +5 -5
- package/lib/cjs/Dots.js +5 -5
- package/lib/cjs/GroupBar.js +6 -6
- package/lib/cjs/HorizontalBar.js +5 -5
- package/lib/cjs/Hover.js +3 -3
- package/lib/cjs/Line.js +5 -5
- package/lib/cjs/ScatterPlot.js +224 -0
- package/lib/cjs/ScatterPlot.js.map +1 -0
- package/lib/cjs/StackBar.js +6 -6
- package/lib/cjs/StackedArea.js +7 -7
- package/lib/cjs/Tooltip.js +14 -10
- package/lib/cjs/Tooltip.js.map +1 -1
- package/lib/cjs/Venn.js +4 -4
- package/lib/cjs/index.js +16 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/style/bubble.shadow.css +45 -0
- package/lib/cjs/style/scatterplot.shadow.css +27 -0
- package/lib/cjs/style/tooltip.shadow.css +2 -2
- package/lib/es6/Area.js +6 -6
- package/lib/es6/Axis.js +12 -12
- package/lib/es6/Bar.js +5 -5
- package/lib/es6/Bubble.js +259 -0
- package/lib/es6/Bubble.js.map +1 -0
- package/lib/es6/Donut.js +5 -5
- package/lib/es6/Dots.js +5 -5
- package/lib/es6/GroupBar.js +6 -6
- package/lib/es6/HorizontalBar.js +5 -5
- package/lib/es6/Hover.js +3 -3
- package/lib/es6/Line.js +5 -5
- package/lib/es6/ScatterPlot.js +209 -0
- package/lib/es6/ScatterPlot.js.map +1 -0
- package/lib/es6/StackBar.js +6 -6
- package/lib/es6/StackedArea.js +7 -7
- package/lib/es6/Tooltip.js +14 -10
- package/lib/es6/Tooltip.js.map +1 -1
- package/lib/es6/Venn.js +4 -4
- package/lib/es6/index.js +2 -0
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/style/bubble.shadow.css +45 -0
- package/lib/es6/style/scatterplot.shadow.css +27 -0
- package/lib/es6/style/tooltip.shadow.css +2 -2
- package/lib/types/Bubble.d.ts +27 -0
- package/lib/types/ScatterPlot.d.ts +27 -0
- package/lib/types/index.d.ts +6 -0
- package/package.json +1 -1
- package/src/Bubble.js +189 -0
- package/src/ScatterPlot.js +130 -0
- package/src/Tooltip.js +8 -2
- package/src/index.js +2 -0
- package/src/style/bubble.shadow.css +45 -0
- package/src/style/scatterplot.shadow.css +27 -0
- package/src/style/tooltip.shadow.css +2 -2
- package/src/types/Bubble.d.ts +27 -0
- package/src/types/ScatterPlot.d.ts +27 -0
- package/src/types/index.d.ts +6 -0
|
@@ -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/Tooltip.js
CHANGED
|
@@ -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
|
|
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
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
@import '@semcore/utils/style/var.css';
|
|
2
|
+
@import '@semcore/d3-chart/src/style/var.css';
|
|
3
|
+
|
|
4
|
+
SBubble {
|
|
5
|
+
fill: #2bb3ff;
|
|
6
|
+
stroke: #fff;
|
|
7
|
+
stroke-width: 2px;
|
|
8
|
+
transition-property: cx, cy;
|
|
9
|
+
transition-duration: var(--duration);
|
|
10
|
+
transition-timing-function: ease-in-out;
|
|
11
|
+
opacity: 0.5;
|
|
12
|
+
&:hover {
|
|
13
|
+
opacity: 0.8;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
SBubble[color] {
|
|
18
|
+
fill: var(--color);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
SCenter {
|
|
22
|
+
text-anchor: middle;
|
|
23
|
+
font-size: 11px;
|
|
24
|
+
stroke: #2bb3ff;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
SCenter[color] {
|
|
28
|
+
stroke: var(--color);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
SLabel {
|
|
32
|
+
fill: #2bb3ff;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
SLabel[position='right'] {
|
|
36
|
+
text-anchor: end;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
SLabel[position='left'] {
|
|
40
|
+
text-anchor: start;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
SLabel[color] {
|
|
44
|
+
fill: var(--color);
|
|
45
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
@import '@semcore/utils/style/var.css';
|
|
2
|
+
@import '@semcore/d3-chart/src/style/var.css';
|
|
3
|
+
|
|
4
|
+
SScatterPlot {
|
|
5
|
+
fill: #2bb3ff;
|
|
6
|
+
transition-property: cx, cy;
|
|
7
|
+
transition-duration: var(--duration);
|
|
8
|
+
transition-timing-function: ease-in-out;
|
|
9
|
+
opacity: 0.5;
|
|
10
|
+
&:hover {
|
|
11
|
+
opacity: 0.8;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
SScatterPlot[color] {
|
|
16
|
+
fill: var(--color);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
SValue {
|
|
20
|
+
text-anchor: middle;
|
|
21
|
+
font-size: 10px;
|
|
22
|
+
stroke: #008ff8;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
SValue[color] {
|
|
26
|
+
stroke: var(--color);
|
|
27
|
+
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
@import '@semcore/d3-chart/src/style/var.css';
|
|
3
3
|
|
|
4
4
|
STooltip {
|
|
5
|
+
font-size: var(--fs-100);
|
|
6
|
+
line-height: var(--lh-100);
|
|
5
7
|
position: relative;
|
|
6
8
|
background-color: #fff;
|
|
7
9
|
border-radius: 3px;
|
|
@@ -12,8 +14,6 @@ STooltip {
|
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
STitle {
|
|
15
|
-
font-size: var(--fs-100);
|
|
16
|
-
line-height: var(--lh-100);
|
|
17
17
|
color: var(--gray60);
|
|
18
18
|
margin-bottom: 8px;
|
|
19
19
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CProps, ReturnEl } from '@semcore/core';
|
|
2
|
+
import IContext from './context';
|
|
3
|
+
|
|
4
|
+
export interface IBubbleProps extends IContext {
|
|
5
|
+
/** Field from data for XAxis */
|
|
6
|
+
x: string;
|
|
7
|
+
/** Field from data for YAxis */
|
|
8
|
+
y: string;
|
|
9
|
+
/** Field from data for circle radius */
|
|
10
|
+
value: string;
|
|
11
|
+
/** Field from data for circle label */
|
|
12
|
+
label?: string;
|
|
13
|
+
/** Circle color */
|
|
14
|
+
color?: string;
|
|
15
|
+
/** Cross in the center of the bubble
|
|
16
|
+
* @default true
|
|
17
|
+
*/
|
|
18
|
+
markedCross?: boolean;
|
|
19
|
+
/** Animation duration in ms
|
|
20
|
+
* @default 500
|
|
21
|
+
*/
|
|
22
|
+
duration?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare const Bubble: <T>(props: CProps<IBubbleProps & T>) => ReturnEl;
|
|
26
|
+
|
|
27
|
+
export default Bubble;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CProps, ReturnEl } from '@semcore/core';
|
|
2
|
+
import IContext from './context';
|
|
3
|
+
|
|
4
|
+
export interface IScatterPlotProps extends IContext {
|
|
5
|
+
/** Field from data for XAxis */
|
|
6
|
+
x: string;
|
|
7
|
+
/** Field from data for YAxis */
|
|
8
|
+
y: string;
|
|
9
|
+
/** Field from data for circle value */
|
|
10
|
+
value?: string;
|
|
11
|
+
/** Circle color */
|
|
12
|
+
color?: string;
|
|
13
|
+
/** Circle value color */
|
|
14
|
+
valueColor?: string;
|
|
15
|
+
/** Animation duration in ms
|
|
16
|
+
* @default 500
|
|
17
|
+
*/
|
|
18
|
+
duration?: number;
|
|
19
|
+
/** Radius of circles
|
|
20
|
+
* @default 5.5 or 12 with value
|
|
21
|
+
*/
|
|
22
|
+
r?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare const ScatterPlot: <T>(props: CProps<IScatterPlotProps & T>) => ReturnEl;
|
|
26
|
+
|
|
27
|
+
export default ScatterPlot;
|
package/src/types/index.d.ts
CHANGED
|
@@ -39,3 +39,9 @@ export * from './Donut';
|
|
|
39
39
|
|
|
40
40
|
export { default as Tooltip } from './Tooltip';
|
|
41
41
|
export * from './Tooltip';
|
|
42
|
+
|
|
43
|
+
export { default as ScatterPlot } from './ScatterPlot';
|
|
44
|
+
export * from './ScatterPlot';
|
|
45
|
+
|
|
46
|
+
export { default as Bubble } from './Bubble';
|
|
47
|
+
export * from './Bubble';
|