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