@cloudtower/eagle 0.29.26 → 0.29.28

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.
@@ -1,7 +1,46 @@
1
1
  import { formatPercent } from '../../utils/tower.js';
2
- import React__default from 'react';
2
+ import React__default, { useMemo } from 'react';
3
3
 
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value
13
+ }) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
4
21
  const StackBar = "E_skwah65";
22
+ const useShapeStyle = (shape, color) => {
23
+ return useMemo(() => {
24
+ switch (shape) {
25
+ case "stripes":
26
+ return {
27
+ backgroundImage: `linear-gradient(-45deg,
28
+ ${color} 25%,
29
+ transparent 25%,
30
+ transparent 50%,
31
+ ${color} 50%,
32
+ ${color} 75%,
33
+ transparent 75%,
34
+ transparent)`,
35
+ backgroundSize: "4px 4px"
36
+ };
37
+ default:
38
+ return {
39
+ backgroundColor: color
40
+ };
41
+ }
42
+ }, [color, shape]);
43
+ };
5
44
  function getWidth(input) {
6
45
  const {
7
46
  value,
@@ -9,27 +48,44 @@ function getWidth(input) {
9
48
  } = formatPercent(input);
10
49
  return value + unit;
11
50
  }
51
+ const BarItem = props => {
52
+ const {
53
+ color,
54
+ shape,
55
+ style,
56
+ className
57
+ } = props;
58
+ const shapeStyle = useShapeStyle(shape, color);
59
+ return /* @__PURE__ */React__default.createElement("div", {
60
+ className,
61
+ style: __spreadValues(__spreadValues({}, shapeStyle), style)
62
+ });
63
+ };
12
64
  const BarChart = ({
13
65
  data,
14
66
  total
15
- }) => /* @__PURE__ */React__default.createElement("div", {
16
- className: StackBar
17
- }, (data || []).map((item, index) => {
18
- const {
19
- value,
20
- color
21
- } = item;
22
- const width = total === 0 ? 0 : getWidth(100 * value / total);
67
+ }) => {
23
68
  return /* @__PURE__ */React__default.createElement("div", {
24
- className: "stack-bar-item",
25
- key: index,
26
- style: {
27
- width,
28
- background: color,
29
- display: value === 0 || total === 0 ? "none" : "inline-block"
30
- }
31
- });
32
- }));
69
+ className: StackBar
70
+ }, (data || []).map((item, index) => {
71
+ const {
72
+ value,
73
+ color,
74
+ shape = "fill"
75
+ } = item;
76
+ const width = total === 0 ? 0 : getWidth(100 * value / total);
77
+ return /* @__PURE__ */React__default.createElement(BarItem, {
78
+ className: "stack-bar-item",
79
+ key: index,
80
+ shape,
81
+ color,
82
+ style: {
83
+ width,
84
+ display: value === 0 || total === 0 ? "none" : "inline-block"
85
+ }
86
+ });
87
+ }));
88
+ };
33
89
  var BarChart$1 = BarChart;
34
90
 
35
91
  export { BarChart$1 as default, getWidth };