@kiva/kv-components 3.106.0 → 3.107.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.
@@ -0,0 +1,109 @@
1
+ // utils/treemap.js
2
+ var getMaximum = (array) => Math.max(...array);
3
+ var getMinimum = (array) => Math.min(...array);
4
+ var sumReducer = (acc, cur) => acc + cur;
5
+ var roundValue = (number) => Math.max(Math.round(number * 100) / 100, 0);
6
+ var validateArguments = ({ data, width, height }) => {
7
+ if (!width || typeof width !== "number" || width < 0) {
8
+ throw new Error("You need to specify the width of your treemap");
9
+ }
10
+ if (!height || typeof height !== "number" || height < 0) {
11
+ throw new Error("You need to specify the height of your treemap");
12
+ }
13
+ if (!data || !Array.isArray(data) || data.length === 0 || !data.every((dataPoint) => Object.prototype.hasOwnProperty.call(dataPoint, "value") && typeof dataPoint.value === "number" && dataPoint.value >= 0 && !Number.isNaN(dataPoint.value))) {
14
+ throw new Error("You data must be in this format [{ value: 1 }, { value: 2 }], 'value' being a positive number");
15
+ }
16
+ };
17
+ function getTreemap({ data, width, height }) {
18
+ let Rectangle = {};
19
+ let initialData = [];
20
+ function worstRatio(row, width2) {
21
+ const sum = row.reduce(sumReducer, 0);
22
+ const rowMax = getMaximum(row);
23
+ const rowMin = getMinimum(row);
24
+ return Math.max(width2 ** 2 * rowMax / sum ** 2, sum ** 2 / (width2 ** 2 * rowMin));
25
+ }
26
+ const getMinWidth = () => {
27
+ if (Rectangle.totalHeight ** 2 > Rectangle.totalWidth ** 2) {
28
+ return { value: Rectangle.totalWidth, vertical: false };
29
+ }
30
+ return { value: Rectangle.totalHeight, vertical: true };
31
+ };
32
+ const layoutRow = (row, width2, vertical) => {
33
+ const rowHeight = row.reduce(sumReducer, 0) / width2;
34
+ row.forEach((rowItem) => {
35
+ const rowWidth = rowItem / rowHeight;
36
+ const { xBeginning } = Rectangle;
37
+ const { yBeginning } = Rectangle;
38
+ let data2;
39
+ if (vertical) {
40
+ data2 = {
41
+ x: xBeginning,
42
+ y: yBeginning,
43
+ width: rowHeight,
44
+ height: rowWidth,
45
+ data: initialData[Rectangle.data.length]
46
+ };
47
+ Rectangle.yBeginning += rowWidth;
48
+ } else {
49
+ data2 = {
50
+ x: xBeginning,
51
+ y: yBeginning,
52
+ width: rowWidth,
53
+ height: rowHeight,
54
+ data: initialData[Rectangle.data.length]
55
+ };
56
+ Rectangle.xBeginning += rowWidth;
57
+ }
58
+ Rectangle.data.push(data2);
59
+ });
60
+ if (vertical) {
61
+ Rectangle.xBeginning += rowHeight;
62
+ Rectangle.yBeginning -= width2;
63
+ Rectangle.totalWidth -= rowHeight;
64
+ } else {
65
+ Rectangle.xBeginning -= width2;
66
+ Rectangle.yBeginning += rowHeight;
67
+ Rectangle.totalHeight -= rowHeight;
68
+ }
69
+ };
70
+ const layoutLastRow = (rows, children, width2) => {
71
+ const { vertical } = getMinWidth();
72
+ layoutRow(rows, width2, vertical);
73
+ layoutRow(children, width2, vertical);
74
+ };
75
+ const squarify = (children, row, width2) => {
76
+ if (children.length === 1) {
77
+ return layoutLastRow(row, children, width2);
78
+ }
79
+ const rowWithChild = [...row, children[0]];
80
+ if (row.length === 0 || worstRatio(row, width2) >= worstRatio(rowWithChild, width2)) {
81
+ children.shift();
82
+ return squarify(children, rowWithChild, width2);
83
+ }
84
+ layoutRow(row, width2, getMinWidth().vertical);
85
+ return squarify(children, [], getMinWidth().value);
86
+ };
87
+ validateArguments({ data, width, height });
88
+ Rectangle = {
89
+ data: [],
90
+ xBeginning: 0,
91
+ yBeginning: 0,
92
+ totalWidth: width,
93
+ totalHeight: height
94
+ };
95
+ initialData = data;
96
+ const totalValue = data.map((dataPoint) => dataPoint.value).reduce(sumReducer, 0);
97
+ const dataScaled = data.map((dataPoint) => dataPoint.value * height * width / totalValue);
98
+ squarify(dataScaled, [], getMinWidth().value);
99
+ return Rectangle.data.map((dataPoint) => ({
100
+ ...dataPoint,
101
+ x: roundValue(dataPoint.x),
102
+ y: roundValue(dataPoint.y),
103
+ width: roundValue(dataPoint.width),
104
+ height: roundValue(dataPoint.height)
105
+ }));
106
+ }
107
+ export {
108
+ getTreemap
109
+ };
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@kiva/kv-components",
3
- "version": "3.106.0",
3
+ "version": "3.107.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "main": "index.js",
8
+ "main": "dist/index.cjs",
9
+ "module": "dist/index.js",
9
10
  "devDependencies": {
10
11
  "@babel/core": "^7.14.8",
11
12
  "@babel/eslint-parser": "^7.13.14",
@@ -46,6 +47,7 @@
46
47
  "storybook": "7.6.20",
47
48
  "style-loader": "^3.3.4",
48
49
  "tailwindcss": "^3.4.3",
50
+ "tsup": "^6.7.0",
49
51
  "vue": "2.6.14",
50
52
  "vue-loader": "^15.9.6",
51
53
  "vue-router": "^3.5.2",
@@ -56,7 +58,7 @@
56
58
  "build-storybook": "vue-demi-switch 2 && storybook build -c vue/.storybook",
57
59
  "lint": "eslint --ext .js,.vue ./",
58
60
  "test": "npm run lint",
59
- "build": "echo No build needed for @kiva/kv-components."
61
+ "build": "tsup utils/*.js --format cjs,esm --clean"
60
62
  },
61
63
  "dependencies": {
62
64
  "@kiva/kv-tokens": "^2.13.0",
@@ -74,6 +76,12 @@
74
76
  "popper.js": "^1.16.1",
75
77
  "vue-demi": "^0.14.7"
76
78
  },
79
+ "exports": {
80
+ ".": {
81
+ "require": "./dist/index.cjs",
82
+ "import": "./dist/index.js"
83
+ }
84
+ },
77
85
  "peerDependencies": {
78
86
  "@vue/composition-api": "^1.0.0-rc.1",
79
87
  "vue": "^2.6.0 || >=3.0.0"
@@ -83,5 +91,5 @@
83
91
  "optional": true
84
92
  }
85
93
  },
86
- "gitHead": "c195fd4d6bf8055879846dc5821873e9bc336f1c"
94
+ "gitHead": "6efc99e83efc05ac8d3ee259bc24a22012dc22ef"
87
95
  }
@@ -7,7 +7,7 @@
7
7
  >
8
8
  <!-- Carousel Content -->
9
9
  <div
10
- class="tw-flex tw-flex-col tw-gap-y-1"
10
+ class="tw-flex tw-flex-col"
11
11
  :style="`height: ${heightStyle}`"
12
12
  @click.capture="onCarouselContainerClick"
13
13
  >