@evergis/charts 3.0.19 → 3.0.21

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 Kirill Protasov
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Kirill Protasov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,15 +1,15 @@
1
- # @evergis/charts
2
-
3
- ## Важно
4
-
5
- - Стилизовать графики необходимо импортируя названия классов из библиотеки.
6
-
7
- `import { calendarChartClassNames } from "@evergis/charts"`
8
-
9
- ## Документация зависимостей
10
-
11
- - [d3](https://github.com/d3/d3/blob/master/API.md)
12
-
13
- - [styled-components](https://styled-components.com/docs)
14
-
15
- - [storybook](https://storybook.js.org/docs/react/writing-docs/docs-page)
1
+ # @evergis/charts
2
+
3
+ ## Важно
4
+
5
+ - Стилизовать графики необходимо импортируя названия классов из библиотеки.
6
+
7
+ `import { calendarChartClassNames } from "@evergis/charts"`
8
+
9
+ ## Документация зависимостей
10
+
11
+ - [d3](https://github.com/d3/d3/blob/master/API.md)
12
+
13
+ - [styled-components](https://styled-components.com/docs)
14
+
15
+ - [storybook](https://storybook.js.org/docs/react/writing-docs/docs-page)
@@ -26,6 +26,8 @@ export interface BarChartMarker {
26
26
  color?: string;
27
27
  className?: string;
28
28
  horizontal?: boolean;
29
+ line?: boolean;
30
+ align?: "center" | "left" | "right";
29
31
  }
30
32
  export declare type BarChartProps = {
31
33
  className?: string;
@@ -2060,6 +2060,13 @@ const useSelection = (node, props) => {
2060
2060
  const drawing = React.useRef(false);
2061
2061
  const startX = React.useRef(0);
2062
2062
  const selection = React.useRef();
2063
+ const clearSelection = React.useCallback(() => {
2064
+ if (node && selection.current) {
2065
+ drawing.current = false;
2066
+ node.removeChild(selection.current);
2067
+ selection.current = undefined;
2068
+ }
2069
+ }, [node]);
2063
2070
  const onStartDrawing = React.useCallback(e => {
2064
2071
  const isTouch = Boolean(e.touches);
2065
2072
  e.stopPropagation();
@@ -2067,6 +2074,7 @@ const useSelection = (node, props) => {
2067
2074
  if (node && e.which !== 3) {
2068
2075
  var _props$margin$bottom, _props$margin, _e$touches$;
2069
2076
 
2077
+ clearSelection();
2070
2078
  selection.current = document.createElement("div");
2071
2079
  selection.current.setAttribute("class", barChartClassNames.barChartSelection);
2072
2080
  selection.current.setAttribute("style", "height: calc(100% - " + ((_props$margin$bottom = (_props$margin = props.margin) == null ? void 0 : _props$margin.bottom) != null ? _props$margin$bottom : 0) + "px)");
@@ -2138,12 +2146,10 @@ const useSelection = (node, props) => {
2138
2146
  if (max - min > 0 && props.onSelect) {
2139
2147
  props.onSelect([min, max]);
2140
2148
  }
2141
-
2142
- drawing.current = false;
2143
- node.removeChild(selection.current);
2144
- selection.current = undefined;
2145
2149
  }
2146
- }, [node]);
2150
+
2151
+ clearSelection();
2152
+ }, [node, clearSelection]);
2147
2153
  React.useEffect(() => {
2148
2154
  if (node) {
2149
2155
  node.childNodes.forEach(child => {
@@ -2670,6 +2676,7 @@ const getBars = _ref => {
2670
2676
  return groups.selectAll('rect').data(item => item).join('rect').attr('x', item => item.x).attr('y', item => item.y).attr('width', barWidth).attr('height', item => item.height).style('fill', item => item.color);
2671
2677
  };
2672
2678
 
2679
+ const MIN_BAR_HEIGHT = 2;
2673
2680
  const draw$4 = (node, props) => {
2674
2681
  const {
2675
2682
  data,
@@ -2816,7 +2823,8 @@ const draw$4 = (node, props) => {
2816
2823
  drawGridX
2817
2824
  });
2818
2825
  xAxis.attr('transform', "translate(0, " + (yScale(yTicks[0]) + (xAxisPadding || 0)) + ")");
2819
- const gSvg = svg.append('g').attr('class', barChartClassNames.barChartBarGlobal);
2826
+ svg.append('defs').append('mask').attr('id', 'height-limit-mask').append('rect').attr('width', '100%').attr('height', height - marginBottom + MIN_BAR_HEIGHT).attr('fill', 'white');
2827
+ const gSvg = svg.append('g').attr('class', barChartClassNames.barChartBarGlobal).attr('mask', 'url(#height-limit-mask)');
2820
2828
  const groups = gSvg.selectAll('g').data(marshalledData).enter().append('g').attr('transform', (_, i) => "translate(" + Math.round(xScale(i)) + "," + -(marginTop || 0) + ")");
2821
2829
  const bars = drawBars ? drawBars({
2822
2830
  groups,
@@ -2833,13 +2841,19 @@ const draw$4 = (node, props) => {
2833
2841
  }
2834
2842
 
2835
2843
  if (marker.horizontal) {
2836
- svg.append('line').style("stroke", marker.color || "inherit").style("stroke-width", 1).style("stroke-dasharray", "5, 3").attr("x1", marginLeft + yAxisWidth).attr("y1", yScale(marker.value) + 1).attr("x2", width).attr("y2", yScale(marker.value) + 1);
2844
+ if (marker.line) {
2845
+ svg.append('line').style("stroke", marker.color || "inherit").style("stroke-width", 1).style("stroke-dasharray", "5, 3").attr("x1", marginLeft + yAxisWidth).attr("y1", yScale(marker.value) + 1).attr("x2", width).attr("y2", yScale(marker.value) + 1);
2846
+ }
2847
+
2837
2848
  svg.append("text").attr("y", yScale(marker.value) + 1).attr("x", marginLeft + yAxisWidth).attr('text-anchor', 'middle').attr("class", ["marker", marker.className].filter(Boolean).join(" ")).style("fill", (marker == null ? void 0 : marker.color) || "inherit").text(marker.label);
2838
2849
  return;
2839
2850
  }
2840
2851
 
2841
- svg.append('line').style("stroke", marker.color || "inherit").style("stroke-width", 1).style("stroke-dasharray", "5, 3").attr("x1", width / data.length * marker.value + 1).attr("y1", 0).attr("x2", width / data.length * marker.value + 1).attr("y2", height - marginTop - marginBottom + marginBottom / 2);
2842
- svg.append("text").attr("y", height).attr("x", width / data.length * marker.value + 1).attr('text-anchor', 'middle').attr("class", ["marker", marker.className].filter(Boolean).join(" ")).style("fill", (marker == null ? void 0 : marker.color) || "inherit").text(marker.label);
2852
+ if (marker.line) {
2853
+ svg.append('line').style("stroke", marker.color || "inherit").style("stroke-width", 1).style("stroke-dasharray", "5, 3").attr("x1", width / data.length * marker.value + 1).attr("y1", 0).attr("x2", width / data.length * marker.value + 1).attr("y2", height - marginTop - marginBottom + marginBottom / 2);
2854
+ }
2855
+
2856
+ svg.append("text").attr("y", height).attr("x", width / data.length * marker.value + 1).attr('text-anchor', marker.align === 'right' ? 'end' : marker.align === 'left' ? 'start' : 'middle').attr("class", ["marker", marker.className].filter(Boolean).join(" ")).style("fill", (marker == null ? void 0 : marker.color) || "inherit").text(marker.label);
2843
2857
  });
2844
2858
  let lines = null;
2845
2859