@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.
Files changed (154) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/lib/cjs/Area.js +71 -49
  3. package/lib/cjs/Area.js.map +1 -1
  4. package/lib/cjs/Axis.js +148 -142
  5. package/lib/cjs/Axis.js.map +1 -1
  6. package/lib/cjs/Bar.js +101 -54
  7. package/lib/cjs/Bar.js.map +1 -1
  8. package/lib/cjs/ClipPath.js +110 -0
  9. package/lib/cjs/ClipPath.js.map +1 -0
  10. package/lib/cjs/Donut.js +169 -68
  11. package/lib/cjs/Donut.js.map +1 -1
  12. package/lib/cjs/Dots.js +55 -21
  13. package/lib/cjs/Dots.js.map +1 -1
  14. package/lib/cjs/GroupBar.js +7 -6
  15. package/lib/cjs/GroupBar.js.map +1 -1
  16. package/lib/cjs/HorizontalBar.js +72 -45
  17. package/lib/cjs/HorizontalBar.js.map +1 -1
  18. package/lib/cjs/Hover.js +46 -47
  19. package/lib/cjs/Hover.js.map +1 -1
  20. package/lib/cjs/Line.js +63 -41
  21. package/lib/cjs/Line.js.map +1 -1
  22. package/lib/cjs/Plot.js +16 -29
  23. package/lib/cjs/Plot.js.map +1 -1
  24. package/lib/cjs/ResponsiveContainer.js +13 -9
  25. package/lib/cjs/ResponsiveContainer.js.map +1 -1
  26. package/lib/cjs/StackBar.js +6 -6
  27. package/lib/cjs/StackBar.js.map +1 -1
  28. package/lib/cjs/StackedArea.js +8 -9
  29. package/lib/cjs/StackedArea.js.map +1 -1
  30. package/lib/cjs/Tooltip.js +49 -75
  31. package/lib/cjs/Tooltip.js.map +1 -1
  32. package/lib/cjs/Venn.js +235 -0
  33. package/lib/cjs/Venn.js.map +1 -0
  34. package/lib/cjs/index.js +8 -0
  35. package/lib/cjs/index.js.map +1 -1
  36. package/lib/cjs/style/area.shadow.css +11 -10
  37. package/lib/cjs/style/bar.shadow.css +4 -0
  38. package/lib/cjs/style/donut.shadow.css +1 -0
  39. package/lib/cjs/style/dot.shadow.css +19 -0
  40. package/lib/cjs/style/line.shadow.css +4 -15
  41. package/lib/cjs/style/tooltip.shadow.css +1 -0
  42. package/lib/cjs/style/venn.shadow.css +23 -0
  43. package/lib/cjs/utils.js +8 -1
  44. package/lib/cjs/utils.js.map +1 -1
  45. package/lib/es6/Area.js +72 -50
  46. package/lib/es6/Area.js.map +1 -1
  47. package/lib/es6/Axis.js +149 -143
  48. package/lib/es6/Axis.js.map +1 -1
  49. package/lib/es6/Bar.js +100 -54
  50. package/lib/es6/Bar.js.map +1 -1
  51. package/lib/es6/ClipPath.js +91 -0
  52. package/lib/es6/ClipPath.js.map +1 -0
  53. package/lib/es6/Donut.js +167 -67
  54. package/lib/es6/Donut.js.map +1 -1
  55. package/lib/es6/Dots.js +51 -20
  56. package/lib/es6/Dots.js.map +1 -1
  57. package/lib/es6/GroupBar.js +7 -6
  58. package/lib/es6/GroupBar.js.map +1 -1
  59. package/lib/es6/HorizontalBar.js +72 -45
  60. package/lib/es6/HorizontalBar.js.map +1 -1
  61. package/lib/es6/Hover.js +47 -48
  62. package/lib/es6/Hover.js.map +1 -1
  63. package/lib/es6/Line.js +65 -43
  64. package/lib/es6/Line.js.map +1 -1
  65. package/lib/es6/Plot.js +17 -29
  66. package/lib/es6/Plot.js.map +1 -1
  67. package/lib/es6/ResponsiveContainer.js +13 -7
  68. package/lib/es6/ResponsiveContainer.js.map +1 -1
  69. package/lib/es6/StackBar.js +6 -6
  70. package/lib/es6/StackBar.js.map +1 -1
  71. package/lib/es6/StackedArea.js +8 -9
  72. package/lib/es6/StackedArea.js.map +1 -1
  73. package/lib/es6/Tooltip.js +52 -76
  74. package/lib/es6/Tooltip.js.map +1 -1
  75. package/lib/es6/Venn.js +217 -0
  76. package/lib/es6/Venn.js.map +1 -0
  77. package/lib/es6/index.js +1 -0
  78. package/lib/es6/index.js.map +1 -1
  79. package/lib/es6/style/area.shadow.css +11 -10
  80. package/lib/es6/style/bar.shadow.css +4 -0
  81. package/lib/es6/style/donut.shadow.css +1 -0
  82. package/lib/es6/style/dot.shadow.css +19 -0
  83. package/lib/es6/style/line.shadow.css +4 -15
  84. package/lib/es6/style/tooltip.shadow.css +1 -0
  85. package/lib/es6/style/venn.shadow.css +23 -0
  86. package/lib/es6/utils.js +6 -1
  87. package/lib/es6/utils.js.map +1 -1
  88. package/lib/types/Area.d.ts +7 -8
  89. package/lib/types/Axis.d.ts +6 -6
  90. package/lib/types/Bar.d.ts +7 -3
  91. package/lib/types/ClipPath.d.ts +26 -0
  92. package/lib/types/Donut.d.ts +12 -2
  93. package/lib/types/GroupBar.d.ts +2 -2
  94. package/lib/types/HorizontalBar.d.ts +7 -3
  95. package/lib/types/Hover.d.ts +2 -2
  96. package/lib/types/Line.d.ts +9 -4
  97. package/{src/types/Plot.ts → lib/types/Plot.d.ts} +2 -2
  98. package/lib/types/ResponsiveContainer.d.ts +1 -1
  99. package/lib/types/StackBar.d.ts +3 -11
  100. package/lib/types/StackedArea.d.ts +7 -6
  101. package/lib/types/Tooltip.d.ts +4 -4
  102. package/lib/types/Venn.d.ts +45 -0
  103. package/lib/types/context.d.ts +1 -1
  104. package/lib/types/index.d.ts +6 -0
  105. package/package.json +10 -5
  106. package/src/Area.js +43 -14
  107. package/src/Axis.js +24 -22
  108. package/src/Bar.js +69 -24
  109. package/src/ClipPath.js +36 -0
  110. package/src/Donut.js +84 -12
  111. package/src/Dots.js +36 -20
  112. package/src/GroupBar.js +1 -0
  113. package/src/HorizontalBar.js +49 -22
  114. package/src/Hover.js +3 -3
  115. package/src/Line.js +41 -13
  116. package/src/Plot.js +3 -7
  117. package/src/ResponsiveContainer.js +3 -3
  118. package/src/StackBar.js +1 -1
  119. package/src/StackedArea.js +3 -2
  120. package/src/Tooltip.js +11 -12
  121. package/src/Venn.js +112 -0
  122. package/src/index.js +1 -0
  123. package/src/style/area.shadow.css +11 -10
  124. package/src/style/bar.shadow.css +4 -0
  125. package/src/style/donut.shadow.css +1 -0
  126. package/src/style/dot.shadow.css +19 -0
  127. package/src/style/line.shadow.css +4 -15
  128. package/src/style/tooltip.shadow.css +1 -0
  129. package/src/style/venn.shadow.css +23 -0
  130. package/src/types/Area.d.ts +7 -8
  131. package/src/types/Axis.d.ts +6 -6
  132. package/src/types/Bar.d.ts +7 -3
  133. package/src/types/ClipPath.d.ts +26 -0
  134. package/src/types/Donut.d.ts +12 -2
  135. package/src/types/GroupBar.d.ts +2 -2
  136. package/src/types/HorizontalBar.d.ts +7 -3
  137. package/src/types/Hover.d.ts +2 -2
  138. package/src/types/Line.d.ts +9 -4
  139. package/src/types/Plot.d.ts +16 -0
  140. package/src/types/ResponsiveContainer.d.ts +1 -1
  141. package/src/types/StackBar.d.ts +3 -11
  142. package/src/types/StackedArea.d.ts +7 -6
  143. package/src/types/Tooltip.d.ts +4 -4
  144. package/src/types/Venn.d.ts +45 -0
  145. package/src/types/context.d.ts +1 -1
  146. package/src/types/index.d.ts +6 -0
  147. package/src/utils.js +7 -1
  148. package/lib/cjs/style/chart.shadow.css +0 -4
  149. package/lib/cjs/types/Plot.js +0 -2
  150. package/lib/cjs/types/Plot.js.map +0 -1
  151. package/lib/es6/style/chart.shadow.css +0 -4
  152. package/lib/es6/types/Plot.js +0 -2
  153. package/lib/es6/types/Plot.js.map +0 -1
  154. package/src/style/chart.shadow.css +0 -4
package/lib/es6/Bar.js CHANGED
@@ -5,33 +5,35 @@ import _inherits from "@babel/runtime/helpers/inherits";
5
5
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
6
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
7
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
- import _extends from "@babel/runtime/helpers/extends";
8
+ import { sstyled as _sstyled } from "@semcore/core";
9
9
 
10
10
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11
11
 
12
12
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
13
 
14
14
  import React from 'react';
15
- import { Component, styled, css, __css__, set, create, map } from '@semcore/core';
15
+ import { Component, sstyled } from '@semcore/core';
16
16
  import createElement from './createElement';
17
+ import ClipPath from './ClipPath';
18
+ import uniqueIDEnhancement from '@semcore/utils/lib/uniqueID';
19
+ import { transition } from 'd3-transition';
17
20
 
18
21
  /*__reshadow-styles__:"./style/bar.shadow.css"*/
19
- var _ref = (
22
+ var style = (
20
23
  /*__reshadow_css_start__*/
21
- __css__(
24
+ _sstyled.insert(
22
25
  /*__inner_css_start__*/
23
- ".___SBar_1fqx0_gg_.__hide_1fqx0_gg_{display:none}.___SBackground_1fqx0_gg_{fill:#e4ecf1}"
26
+ ".___SBar_1u1r9_gg_{fill:var(--color_10kcl1b);transition-property:height,width,y;transition-duration:var(--duration_10kcl1b);transition-timing-function:ease-in-out}.___SBar_1u1r9_gg_.__hide_1u1r9_gg_{display:none}.___SBackground_1u1r9_gg_{fill:#e4ecf1}"
24
27
  /*__inner_css_end__*/
25
- , "1qbp5w9_gg_")
28
+ , "10kcl1b_gg_")
26
29
  /*__reshadow_css_end__*/
27
30
  , {
28
- "__SBar": "___SBar_1fqx0_gg_",
29
- "_hide": "__hide_1fqx0_gg_",
30
- "__SBackground": "___SBackground_1fqx0_gg_"
31
- }),
32
- style = _extends({}, _ref);
33
-
34
- var styled_c8 = create([]);
31
+ "__SBar": "___SBar_1u1r9_gg_",
32
+ "--color": "--color_10kcl1b",
33
+ "--duration": "--duration_10kcl1b",
34
+ "_hide": "__hide_1u1r9_gg_",
35
+ "__SBackground": "___SBackground_1u1r9_gg_"
36
+ });
35
37
 
36
38
  var BarRoot = /*#__PURE__*/function (_Component) {
37
39
  _inherits(BarRoot, _Component);
@@ -55,42 +57,83 @@ var BarRoot = /*#__PURE__*/function (_Component) {
55
57
  };
56
58
  }
57
59
  }, {
58
- key: "render",
59
- value: function render() {
60
- var SBar = this.Element;
60
+ key: "animationBar",
61
+ value: function animationBar() {
61
62
  var _this$asProps2 = this.asProps,
62
- styles = _this$asProps2.styles,
63
- color = _this$asProps2.color,
64
- x = _this$asProps2.x,
65
- y = _this$asProps2.y,
66
- y0 = _this$asProps2.y0,
67
- data = _this$asProps2.data,
68
- scale = _this$asProps2.scale,
69
- hide = _this$asProps2.hide,
70
- offset = _this$asProps2.offset;
63
+ duration = _this$asProps2.duration,
64
+ uid = _this$asProps2.uid;
65
+ var selectRect = transition().selection().selectAll("#".concat(uid, " rect"));
66
+ var selectRectNode = selectRect.node();
67
+
68
+ if (duration > 0 && selectRectNode && selectRectNode.getAttribute('y') !== '0') {
69
+ selectRect.transition().duration(duration).attr('y', 0);
70
+ }
71
+ }
72
+ }, {
73
+ key: "componentDidUpdate",
74
+ value: function componentDidUpdate() {
75
+ this.animationBar();
76
+ }
77
+ }, {
78
+ key: "componentDidMount",
79
+ value: function componentDidMount() {
80
+ this.animationBar();
81
+ }
82
+ }, {
83
+ key: "renderBar",
84
+ value: function renderBar(d, i) {
85
+ var _ref, _d$y, _d$y2;
86
+
87
+ var SBar = this.Element;
88
+ var _this$asProps3 = this.asProps,
89
+ styles = _this$asProps3.styles,
90
+ color = _this$asProps3.color,
91
+ x = _this$asProps3.x,
92
+ y = _this$asProps3.y,
93
+ y0 = _this$asProps3.y0,
94
+ scale = _this$asProps3.scale,
95
+ hide = _this$asProps3.hide,
96
+ offset = _this$asProps3.offset,
97
+ duration = _this$asProps3.duration,
98
+ uid = _this$asProps3.uid;
71
99
 
72
100
  var _scale = _slicedToArray(scale, 2),
73
101
  xScale = _scale[0],
74
102
  yScale = _scale[1];
75
103
 
76
- return data.map(function (d, i) {
77
- var _d$y, _d$y2;
78
-
79
- return styled((set([styled_c8, styles]), /*#__PURE__*/React.createElement(SBar, map("SBar", {
80
- key: i,
81
- __excludeProps: ['data', 'scale', 'value'],
82
- value: d,
83
- index: i,
84
- render: "rect",
85
- childrenPosition: "above",
86
- hide: hide,
87
- fill: color,
88
- width: xScale.bandwidth(),
89
- height: Math.abs(yScale(d[y]) - Math.min(yScale(yScale.domain()[0]), yScale((_d$y = d[y0]) !== null && _d$y !== void 0 ? _d$y : 0))),
90
- x: xScale(d[x]) + offset[0],
91
- y: yScale(Math.max((_d$y2 = d[y0]) !== null && _d$y2 !== void 0 ? _d$y2 : 0, d[y])) + offset[1]
92
- }))));
93
- });
104
+ return _ref = sstyled(styles), /*#__PURE__*/React.createElement(SBar, _ref.cn("SBar", {
105
+ "key": "bar-".concat(i),
106
+ "render": "rect",
107
+ "clipPath": "url(#".concat(uid, ")"),
108
+ "__excludeProps": ['data', 'scale', 'value'],
109
+ "childrenPosition": "above",
110
+ "value": d,
111
+ "index": i,
112
+ "hide": hide,
113
+ "color": color,
114
+ "width": xScale.bandwidth(),
115
+ "height": Math.abs(yScale(d[y]) - Math.min(yScale(yScale.domain()[0]), yScale((_d$y = d[y0]) !== null && _d$y !== void 0 ? _d$y : 0))),
116
+ "x": xScale(d[x]) + offset[0],
117
+ "y": yScale(Math.max((_d$y2 = d[y0]) !== null && _d$y2 !== void 0 ? _d$y2 : 0, d[y])) + offset[1],
118
+ "use:duration": "".concat(duration, "ms")
119
+ }));
120
+ }
121
+ }, {
122
+ key: "render",
123
+ value: function render() {
124
+ var _this$asProps4 = this.asProps,
125
+ data = _this$asProps4.data,
126
+ uid = _this$asProps4.uid,
127
+ size = _this$asProps4.size,
128
+ duration = _this$asProps4.duration;
129
+ return /*#__PURE__*/React.createElement(React.Fragment, null, data.map(this.renderBar.bind(this)), duration && /*#__PURE__*/React.createElement(ClipPath, {
130
+ key: "".concat(uid, "-animation"),
131
+ id: uid,
132
+ x: "0",
133
+ y: size[1],
134
+ width: size[0],
135
+ height: "".concat(size[1], "px")
136
+ }));
94
137
  }
95
138
  }]);
96
139
 
@@ -101,14 +144,17 @@ _defineProperty(BarRoot, "displayName", 'Bar');
101
144
 
102
145
  _defineProperty(BarRoot, "style", style);
103
146
 
147
+ _defineProperty(BarRoot, "enhance", [uniqueIDEnhancement()]);
148
+
104
149
  _defineProperty(BarRoot, "defaultProps", {
105
150
  color: '#50aef4',
106
- offset: [0, 0]
151
+ offset: [0, 0],
152
+ duration: 500
107
153
  });
108
154
 
109
- var styled_12c = create([]);
110
-
111
155
  function Background(props) {
156
+ var _ref2;
157
+
112
158
  var SBackground = props.Element,
113
159
  styles = props.styles,
114
160
  scale = props.scale,
@@ -119,14 +165,14 @@ function Background(props) {
119
165
  yScale = _scale2[1];
120
166
 
121
167
  var yRange = yScale.range();
122
- return styled((set([styled_12c, styles]), /*#__PURE__*/React.createElement(SBackground, map("SBackground", {
123
- render: "rect",
124
- childrenPosition: "above",
125
- width: xScale.bandwidth(),
126
- height: yRange[0] - yRange[1],
127
- x: xScale(value),
128
- y: yRange[1]
129
- }))));
168
+ return _ref2 = sstyled(styles), /*#__PURE__*/React.createElement(SBackground, _ref2.cn("SBackground", {
169
+ "render": "rect",
170
+ "childrenPosition": "above",
171
+ "width": xScale.bandwidth(),
172
+ "height": yRange[0] - yRange[1],
173
+ "x": xScale(value),
174
+ "y": yRange[1]
175
+ }));
130
176
  }
131
177
 
132
178
  export default createElement(BarRoot, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Bar.js"],"names":["React","Component","styled","createElement","BarRoot","props","index","asProps","x","data","value","SBar","Element","styles","color","y","y0","scale","hide","offset","xScale","yScale","map","d","i","bandwidth","Math","abs","min","domain","max","style","Background","SBackground","yRange","range"],"mappings":";;;;;;;;;;;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,SAAT,EAAoBC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D,CALX;AAAA,OAMKwB,MAAM,CAAC,CAAD;AANX,KADK,EAAP;AAUD;;AAED,eAAe/B,aAAa,CAACC,OAAD,EAAU;AAAE4B,EAAAA,UAAU,EAAVA;AAAF,CAAV,CAA5B","sourcesContent":["import React from 'react';\nimport { Component, styled } from '@semcore/core';\nimport createElement from './createElement';\n\nimport style from './style/bar.shadow.css';\n\nclass BarRoot extends Component {\n static displayName = 'Bar';\n\n static style = style;\n\n static defaultProps = {\n color: '#50aef4',\n offset: [0, 0],\n };\n\n getBackgroundProps(props, index) {\n const { x, data } = this.asProps;\n return {\n value: data[index][x],\n };\n }\n\n render() {\n const SBar = this.Element;\n const { styles, color, x, y, y0, data, scale, hide, offset } = this.asProps;\n\n const [xScale, yScale] = scale;\n\n return data.map((d, i) => {\n return styled(styles)(\n <SBar\n key={i}\n __excludeProps={['data', 'scale', 'value']}\n value={d}\n index={i}\n render=\"rect\"\n childrenPosition=\"above\"\n hide={hide}\n fill={color}\n // TODO: https://github.com/airbnb/visx/blob/2fa674e7d7fdc9cffea13e8bf644d46dd6f0db5b/packages/visx-shape/src/util/getBandwidth.ts#L3\n width={xScale.bandwidth()}\n height={Math.abs(yScale(d[y]) - Math.min(yScale(yScale.domain()[0]), yScale(d[y0] ?? 0)))}\n x={xScale(d[x]) + offset[0]}\n y={yScale(Math.max(d[y0] ?? 0, d[y])) + offset[1]}\n />,\n );\n });\n }\n}\n\nfunction Background(props) {\n const { Element: SBackground, styles, scale, value } = props;\n\n const [xScale, yScale] = scale;\n const yRange = yScale.range();\n\n return styled(styles)(\n <SBackground\n render=\"rect\"\n childrenPosition=\"above\"\n width={xScale.bandwidth()}\n height={yRange[0] - yRange[1]}\n x={xScale(value)}\n y={yRange[1]}\n />,\n );\n}\n\nexport default createElement(BarRoot, { Background });\n"],"file":"Bar.js"}
1
+ {"version":3,"sources":["../../src/Bar.js"],"names":["React","Component","sstyled","createElement","ClipPath","uniqueIDEnhancement","transition","BarRoot","props","index","asProps","x","data","value","duration","uid","selectRect","selection","selectAll","selectRectNode","node","getAttribute","attr","animationBar","d","i","SBar","Element","styles","color","y","y0","scale","hide","offset","xScale","yScale","bandwidth","Math","abs","min","domain","max","size","map","renderBar","bind","style","Background","SBackground","yRange","range"],"mappings":";;;;;;;;;;;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,SAAT,EAAoBC,OAApB,QAAmC,eAAnC;AACA,OAAOC,aAAP,MAA0B,iBAA1B;AACA,OAAOC,QAAP,MAAqB,YAArB;AACA,OAAOC,mBAAP,MAAgC,6BAAhC;AACA,SAASC,UAAT,QAA2B,eAA3B;;;;;;;;;;;;;;;;;;;IAIMC,O;;;;;;;;;;;;;WAWJ,4BAAmBC,KAAnB,EAA0BC,KAA1B,EAAiC;AAAA,0BACX,KAAKC,OADM;AAAA,UACvBC,CADuB,iBACvBA,CADuB;AAAA,UACpBC,IADoB,iBACpBA,IADoB;AAE/B,aAAO;AACLC,QAAAA,KAAK,EAAED,IAAI,CAACH,KAAD,CAAJ,CAAYE,CAAZ;AADF,OAAP;AAGD;;;WAED,wBAAe;AAAA,2BACa,KAAKD,OADlB;AAAA,UACLI,QADK,kBACLA,QADK;AAAA,UACKC,GADL,kBACKA,GADL;AAEb,UAAMC,UAAU,GAAGV,UAAU,GAC1BW,SADgB,GAEhBC,SAFgB,YAEFH,GAFE,WAAnB;AAGA,UAAMI,cAAc,GAAGH,UAAU,CAACI,IAAX,EAAvB;;AAEA,UAAIN,QAAQ,GAAG,CAAX,IAAgBK,cAAhB,IAAkCA,cAAc,CAACE,YAAf,CAA4B,GAA5B,MAAqC,GAA3E,EAAgF;AAC9EL,QAAAA,UAAU,CACPV,UADH,GAEGQ,QAFH,CAEYA,QAFZ,EAGGQ,IAHH,CAGQ,GAHR,EAGa,CAHb;AAID;AACF;;;WAED,8BAAqB;AACnB,WAAKC,YAAL;AACD;;;WAED,6BAAoB;AAClB,WAAKA,YAAL;AACD;;;WAED,mBAAUC,CAAV,EAAaC,CAAb,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A,MAGlBG,MAHkB;AAAA,MAGVC,MAHU;;AAIzB,MAAMc,MAAM,GAAGd,MAAM,CAACe,KAAP,EAAf;AAEA,iBAAOjD,OAAO,CAAC0B,MAAD,CAAd,eACE,oBAAC,WAAD;AAAA,cACS,MADT;AAAA,wBAEmB,OAFnB;AAAA,aAGSO,MAAM,CAACE,SAAP,EAHT;AAAA,cAIUa,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CAJ5B;AAAA,SAKKf,MAAM,CAACtB,KAAD,CALX;AAAA,SAMKqC,MAAM,CAAC,CAAD;AANX,KADF;AAUD;;AAED,eAAe/C,aAAa,CAACI,OAAD,EAAU;AAAEyC,EAAAA,UAAU,EAAVA;AAAF,CAAV,CAA5B","sourcesContent":["import React from 'react';\nimport { Component, sstyled } from '@semcore/core';\nimport createElement from './createElement';\nimport ClipPath from './ClipPath';\nimport uniqueIDEnhancement from '@semcore/utils/lib/uniqueID';\nimport { transition } from 'd3-transition';\n\nimport style from './style/bar.shadow.css';\n\nclass BarRoot extends Component {\n static displayName = 'Bar';\n static style = style;\n static enhance = [uniqueIDEnhancement()];\n\n static defaultProps = {\n color: '#50aef4',\n offset: [0, 0],\n duration: 500,\n };\n\n getBackgroundProps(props, index) {\n const { x, data } = this.asProps;\n return {\n value: data[index][x],\n };\n }\n\n animationBar() {\n const { duration, uid } = this.asProps;\n const selectRect = transition()\n .selection()\n .selectAll(`#${uid} rect`);\n const selectRectNode = selectRect.node();\n\n if (duration > 0 && selectRectNode && selectRectNode.getAttribute('y') !== '0') {\n selectRect\n .transition()\n .duration(duration)\n .attr('y', 0);\n }\n }\n\n componentDidUpdate() {\n this.animationBar();\n }\n\n componentDidMount() {\n this.animationBar();\n }\n\n renderBar(d, i) {\n const SBar = this.Element;\n const { styles, color, x, y, y0, scale, hide, offset, duration, uid } = this.asProps;\n\n const [xScale, yScale] = scale;\n\n return sstyled(styles)(\n <SBar\n key={`bar-${i}`}\n render=\"rect\"\n clipPath={`url(#${uid})`}\n __excludeProps={['data', 'scale', 'value']}\n childrenPosition=\"above\"\n value={d}\n index={i}\n hide={hide}\n color={color}\n // TODO: https://github.com/airbnb/visx/blob/2fa674e7d7fdc9cffea13e8bf644d46dd6f0db5b/packages/visx-shape/src/util/getBandwidth.ts#L3\n width={xScale.bandwidth()}\n height={Math.abs(yScale(d[y]) - Math.min(yScale(yScale.domain()[0]), yScale(d[y0] ?? 0)))}\n x={xScale(d[x]) + offset[0]}\n y={yScale(Math.max(d[y0] ?? 0, d[y])) + offset[1]}\n use:duration={`${duration}ms`}\n />,\n );\n }\n render() {\n const { data, uid, size, duration } = this.asProps;\n return (\n <>\n {data.map(this.renderBar.bind(this))}\n {duration && (\n <ClipPath\n key={`${uid}-animation`}\n id={uid}\n x=\"0\"\n y={size[1]}\n width={size[0]}\n height={`${size[1]}px`}\n />\n )}\n </>\n );\n }\n}\n\nfunction Background(props) {\n const { Element: SBackground, styles, scale, value } = props;\n\n const [xScale, yScale] = scale;\n const yRange = yScale.range();\n\n return sstyled(styles)(\n <SBackground\n render=\"rect\"\n childrenPosition=\"above\"\n width={xScale.bandwidth()}\n height={yRange[0] - yRange[1]}\n x={xScale(value)}\n y={yRange[1]}\n />,\n );\n}\n\nexport default createElement(BarRoot, { Background });\n"],"file":"Bar.js"}
@@ -0,0 +1,91 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
+ import _createClass from "@babel/runtime/helpers/createClass";
5
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
6
+ import _inherits from "@babel/runtime/helpers/inherits";
7
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
8
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
9
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
10
+
11
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
12
+
13
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
14
+
15
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
16
+
17
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
18
+
19
+ import React from 'react';
20
+ import createComponent, { Component } from '@semcore/core';
21
+ import propsForElement from '@semcore/utils/lib/propsForElement';
22
+
23
+ var ClipPath = /*#__PURE__*/function (_Component) {
24
+ _inherits(ClipPath, _Component);
25
+
26
+ var _super = _createSuper(ClipPath);
27
+
28
+ function ClipPath() {
29
+ var _this;
30
+
31
+ _classCallCheck(this, ClipPath);
32
+
33
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
34
+ args[_key] = arguments[_key];
35
+ }
36
+
37
+ _this = _super.call.apply(_super, [this].concat(args));
38
+
39
+ _defineProperty(_assertThisInitialized(_this), "refClipPath", /*#__PURE__*/React.createRef());
40
+
41
+ return _this;
42
+ }
43
+
44
+ _createClass(ClipPath, [{
45
+ key: "componentDidMount",
46
+ value: function componentDidMount() {
47
+ var _this$asProps = this.asProps,
48
+ id = _this$asProps.id,
49
+ tag = _this$asProps.tag,
50
+ setAttributeTag = _this$asProps.setAttributeTag;
51
+ if (!document || !document.querySelector("#".concat(id))) return;
52
+ var svg = document.querySelector("#".concat(id)).closest('svg');
53
+ Array.from(svg.querySelectorAll("[clip-path=\"url(#".concat(id, ")\"]"))).forEach(function (node) {
54
+ node && node.getTotalLength && node.getTotalLength();
55
+ });
56
+ setAttributeTag && Array.from(document.querySelectorAll("#".concat(id, " ").concat(tag))).forEach(setAttributeTag);
57
+ }
58
+ }, {
59
+ key: "render",
60
+ value: function render() {
61
+ var _this$asProps2 = this.asProps,
62
+ id = _this$asProps2.id,
63
+ transition = _this$asProps2.transition,
64
+ Tag = _this$asProps2.tag,
65
+ style = _this$asProps2.style,
66
+ className = _this$asProps2.className,
67
+ other = _objectWithoutProperties(_this$asProps2, ["id", "transition", "tag", "style", "className"]);
68
+
69
+ return /*#__PURE__*/React.createElement("clipPath", {
70
+ ref: this.refClipPath,
71
+ id: id
72
+ }, /*#__PURE__*/React.createElement(Tag, _extends({
73
+ style: _objectSpread(_objectSpread({}, style), {}, {
74
+ transition: transition
75
+ })
76
+ }, propsForElement(other, Tag))));
77
+ }
78
+ }]);
79
+
80
+ return ClipPath;
81
+ }(Component);
82
+
83
+ _defineProperty(ClipPath, "defaultProps", {
84
+ tag: 'rect',
85
+ id: '',
86
+ transition: '',
87
+ setAttributeTag: null
88
+ });
89
+
90
+ export default createComponent(ClipPath);
91
+ //# sourceMappingURL=ClipPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ClipPath.js"],"names":["React","createComponent","Component","propsForElement","ClipPath","createRef","asProps","id","tag","setAttributeTag","document","querySelector","svg","closest","Array","from","querySelectorAll","forEach","node","getTotalLength","transition","Tag","style","className","other","refClipPath"],"mappings":";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AOe,KAAP;AAAcF,UAAAA,UAAU,EAAVA;AAAd;AAAV,SAA0CjB,eAAe,CAACqB,KAAD,EAAQH,GAAR,CAAzD,EADF,CADF;AAKD;;;;EA5BoBnB,S;;gBAAjBE,Q,kBACkB;AACpBI,EAAAA,GAAG,EAAE,MADe;AAEpBD,EAAAA,EAAE,EAAE,EAFgB;AAGpBa,EAAAA,UAAU,EAAE,EAHQ;AAIpBX,EAAAA,eAAe,EAAE;AAJG,C;;AA8BxB,eAAeR,eAAe,CAACG,QAAD,CAA9B","sourcesContent":["import React from 'react';\nimport createComponent, { Component } from '@semcore/core';\nimport propsForElement from '@semcore/utils/lib/propsForElement';\n\nclass ClipPath extends Component {\n static defaultProps = {\n tag: 'rect',\n id: '',\n transition: '',\n setAttributeTag: null,\n };\n\n refClipPath = React.createRef();\n\n componentDidMount() {\n const { id, tag, setAttributeTag } = this.asProps;\n if (!document || !document.querySelector(`#${id}`)) return;\n const svg = document.querySelector(`#${id}`).closest('svg');\n Array.from(svg.querySelectorAll(`[clip-path=\"url(#${id})\"]`)).forEach((node) => {\n node && node.getTotalLength && node.getTotalLength();\n });\n setAttributeTag &&\n Array.from(document.querySelectorAll(`#${id} ${tag}`)).forEach(setAttributeTag);\n }\n\n render() {\n const { id, transition, tag: Tag, style, className, ...other } = this.asProps;\n return (\n <clipPath ref={this.refClipPath} id={id}>\n <Tag style={{ ...style, transition }} {...propsForElement(other, Tag)} />\n </clipPath>\n );\n }\n}\n\nexport default createComponent(ClipPath);\n"],"file":"ClipPath.js"}