@reltio/components 1.4.1998 → 1.4.1999
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/cjs/UpSetChart/UpSetChart.d.ts +5 -8
- package/cjs/UpSetChart/UpSetChart.js +61 -5
- package/cjs/UpSetChart/UpSetChart.test.d.ts +1 -0
- package/cjs/UpSetChart/UpSetChart.test.js +198 -0
- package/cjs/UpSetChart/components/IntersectionsChart/IntersectionsChart.d.ts +15 -0
- package/cjs/UpSetChart/components/IntersectionsChart/IntersectionsChart.js +66 -0
- package/cjs/UpSetChart/components/IntersectionsChart/index.d.ts +1 -0
- package/cjs/UpSetChart/components/IntersectionsChart/index.js +5 -0
- package/cjs/UpSetChart/components/IntersectionsChart/styles.d.ts +1 -0
- package/cjs/UpSetChart/components/IntersectionsChart/styles.js +32 -0
- package/cjs/UpSetChart/components/IntersectionsChartAxis/IntersectionsChartAxis.d.ts +10 -0
- package/cjs/UpSetChart/components/IntersectionsChartAxis/IntersectionsChartAxis.js +64 -0
- package/cjs/UpSetChart/components/IntersectionsChartAxis/index.d.ts +1 -0
- package/cjs/UpSetChart/components/IntersectionsChartAxis/index.js +5 -0
- package/cjs/UpSetChart/components/IntersectionsChartAxis/styles.d.ts +1 -0
- package/cjs/UpSetChart/components/IntersectionsChartAxis/styles.js +32 -0
- package/cjs/UpSetChart/components/IntersectionsMatrix/IntersectionsMatrix.d.ts +13 -0
- package/cjs/UpSetChart/components/IntersectionsMatrix/IntersectionsMatrix.js +56 -0
- package/cjs/UpSetChart/components/IntersectionsMatrix/index.d.ts +1 -0
- package/cjs/UpSetChart/components/IntersectionsMatrix/index.js +5 -0
- package/cjs/UpSetChart/components/IntersectionsMatrix/styles.d.ts +1 -0
- package/cjs/UpSetChart/components/IntersectionsMatrix/styles.js +27 -0
- package/cjs/UpSetChart/components/SetsChart/SetsChart.d.ts +15 -0
- package/cjs/UpSetChart/components/SetsChart/SetsChart.js +58 -0
- package/cjs/UpSetChart/components/SetsChart/index.d.ts +1 -0
- package/cjs/UpSetChart/components/SetsChart/index.js +5 -0
- package/cjs/UpSetChart/components/SetsChart/styles.d.ts +1 -0
- package/cjs/UpSetChart/components/SetsChart/styles.js +43 -0
- package/cjs/UpSetChart/components/SetsChartAxis/SetsChartAxis.d.ts +6 -0
- package/cjs/UpSetChart/components/SetsChartAxis/SetsChartAxis.js +20 -0
- package/cjs/UpSetChart/components/SetsChartAxis/index.d.ts +1 -0
- package/cjs/UpSetChart/components/SetsChartAxis/index.js +5 -0
- package/cjs/UpSetChart/components/SetsChartAxis/styles.d.ts +1 -0
- package/cjs/UpSetChart/components/SetsChartAxis/styles.js +17 -0
- package/cjs/UpSetChart/constants.d.ts +16 -3
- package/cjs/UpSetChart/constants.js +20 -4
- package/cjs/UpSetChart/gameOfThrones.test-data.d.ts +4 -0
- package/cjs/UpSetChart/gameOfThrones.test-data.js +26 -0
- package/cjs/UpSetChart/helpers.d.ts +20 -0
- package/cjs/UpSetChart/helpers.js +127 -0
- package/cjs/UpSetChart/styles.d.ts +4 -1
- package/cjs/UpSetChart/styles.js +11 -12
- package/cjs/UpSetChart/types.d.ts +16 -0
- package/cjs/UpSetChart/types.js +2 -0
- package/cjs/UpSetChart/useUpSetChartSizes.d.ts +20 -0
- package/cjs/UpSetChart/useUpSetChartSizes.js +34 -0
- package/esm/UpSetChart/UpSetChart.d.ts +5 -8
- package/esm/UpSetChart/UpSetChart.js +38 -5
- package/esm/UpSetChart/UpSetChart.test.d.ts +1 -0
- package/esm/UpSetChart/UpSetChart.test.js +193 -0
- package/esm/UpSetChart/components/IntersectionsChart/IntersectionsChart.d.ts +15 -0
- package/esm/UpSetChart/components/IntersectionsChart/IntersectionsChart.js +39 -0
- package/esm/UpSetChart/components/IntersectionsChart/index.d.ts +1 -0
- package/esm/UpSetChart/components/IntersectionsChart/index.js +1 -0
- package/esm/UpSetChart/components/IntersectionsChart/styles.d.ts +1 -0
- package/esm/UpSetChart/components/IntersectionsChart/styles.js +29 -0
- package/esm/UpSetChart/components/IntersectionsChartAxis/IntersectionsChartAxis.d.ts +10 -0
- package/esm/UpSetChart/components/IntersectionsChartAxis/IntersectionsChartAxis.js +34 -0
- package/esm/UpSetChart/components/IntersectionsChartAxis/index.d.ts +1 -0
- package/esm/UpSetChart/components/IntersectionsChartAxis/index.js +1 -0
- package/esm/UpSetChart/components/IntersectionsChartAxis/styles.d.ts +1 -0
- package/esm/UpSetChart/components/IntersectionsChartAxis/styles.js +29 -0
- package/esm/UpSetChart/components/IntersectionsMatrix/IntersectionsMatrix.d.ts +13 -0
- package/esm/UpSetChart/components/IntersectionsMatrix/IntersectionsMatrix.js +26 -0
- package/esm/UpSetChart/components/IntersectionsMatrix/index.d.ts +1 -0
- package/esm/UpSetChart/components/IntersectionsMatrix/index.js +1 -0
- package/esm/UpSetChart/components/IntersectionsMatrix/styles.d.ts +1 -0
- package/esm/UpSetChart/components/IntersectionsMatrix/styles.js +24 -0
- package/esm/UpSetChart/components/SetsChart/SetsChart.d.ts +15 -0
- package/esm/UpSetChart/components/SetsChart/SetsChart.js +31 -0
- package/esm/UpSetChart/components/SetsChart/index.d.ts +1 -0
- package/esm/UpSetChart/components/SetsChart/index.js +1 -0
- package/esm/UpSetChart/components/SetsChart/styles.d.ts +1 -0
- package/esm/UpSetChart/components/SetsChart/styles.js +40 -0
- package/esm/UpSetChart/components/SetsChartAxis/SetsChartAxis.d.ts +6 -0
- package/esm/UpSetChart/components/SetsChartAxis/SetsChartAxis.js +13 -0
- package/esm/UpSetChart/components/SetsChartAxis/index.d.ts +1 -0
- package/esm/UpSetChart/components/SetsChartAxis/index.js +1 -0
- package/esm/UpSetChart/components/SetsChartAxis/styles.d.ts +1 -0
- package/esm/UpSetChart/components/SetsChartAxis/styles.js +14 -0
- package/esm/UpSetChart/constants.d.ts +16 -3
- package/esm/UpSetChart/constants.js +19 -3
- package/esm/UpSetChart/gameOfThrones.test-data.d.ts +4 -0
- package/esm/UpSetChart/gameOfThrones.test-data.js +23 -0
- package/esm/UpSetChart/helpers.d.ts +20 -0
- package/esm/UpSetChart/helpers.js +120 -0
- package/esm/UpSetChart/styles.d.ts +4 -1
- package/esm/UpSetChart/styles.js +11 -12
- package/esm/UpSetChart/types.d.ts +16 -0
- package/esm/UpSetChart/types.js +1 -0
- package/esm/UpSetChart/useUpSetChartSizes.d.ts +20 -0
- package/esm/UpSetChart/useUpSetChartSizes.js +30 -0
- package/package.json +1 -1
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
export var PRIMARY_COLOR = '
|
|
3
|
-
export var
|
|
1
|
+
// Colors
|
|
2
|
+
export var PRIMARY_COLOR = '#000066';
|
|
3
|
+
export var DIMMED_COLOR = '#CCCCE0';
|
|
4
4
|
export var TEXT_COLOR = 'rgba(0, 0, 0, 0.87)';
|
|
5
|
+
// Gaps
|
|
6
|
+
export var TOP_GAP = 24;
|
|
7
|
+
export var TEXT_GAP = 16;
|
|
8
|
+
export var GAP_BETWEEN_TABLE_AND_CHART = 8;
|
|
9
|
+
export var GAP_BEFORE_LEFT_BAR = 12;
|
|
10
|
+
// Sizes
|
|
11
|
+
export var AXIS_TICK_LABEL_SIZE = '12px';
|
|
12
|
+
export var SET_LABEL_SIZE = '13px';
|
|
13
|
+
export var SET_BAR_HEIGHT = 12;
|
|
14
|
+
export var MATRIX_ROW_HEIGHT = 29;
|
|
15
|
+
export var MIN_MATRIX_COLUMN_WIDTH = 28;
|
|
16
|
+
export var MIN_INTERSECTION_CHART_HEIGHT = 120;
|
|
17
|
+
export var MIN_SETS_CHART_WIDTH = 100;
|
|
18
|
+
export var MAX_SETS_CHART_WIDTH = 200;
|
|
19
|
+
export var MAX_CHARACTERS = 20;
|
|
20
|
+
export var MIN_CHARACTERS = 8;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export var gameOfThronesData = [
|
|
2
|
+
{ name: 'Alton Lannister', sets: ['was killed', 'Lannister', 'male'] },
|
|
3
|
+
{ name: 'Arya Stark', sets: ['Stark', 'female'] },
|
|
4
|
+
{ name: 'Bran Stark', sets: ['royal', 'Stark', 'male'] },
|
|
5
|
+
{ name: 'Benjen Stark', sets: ['was killed', 'Stark', 'male'] },
|
|
6
|
+
{ name: 'Brandon Stark', sets: ['was killed', 'Stark'] },
|
|
7
|
+
{ name: 'Catelyn Stark', sets: ['was killed', 'Stark', 'female'] },
|
|
8
|
+
{ name: 'Cersei Lannister', sets: ['royal', 'was killed', 'Lannister', 'female'] },
|
|
9
|
+
{ name: 'Eddard Stark', sets: ['was killed', 'Stark', 'male'] },
|
|
10
|
+
{ name: 'Jaime Lannister', sets: ['was killed', 'Lannister', 'male'] },
|
|
11
|
+
{ name: 'Jon Snow', sets: ['royal', 'was killed', 'Stark', 'male'] },
|
|
12
|
+
{ name: 'Kevan Lannister', sets: ['was killed', 'Lannister', 'male'] },
|
|
13
|
+
{ name: 'Lancel Lannister', sets: ['was killed', 'Lannister', 'male'] },
|
|
14
|
+
{ name: 'Lyanna Stark', sets: ['was killed', 'Stark', 'female'] },
|
|
15
|
+
{ name: 'Martyn Lannister', sets: ['was killed', 'Lannister', 'male'] },
|
|
16
|
+
{ name: 'Rickard Stark', sets: ['was killed', 'Stark', 'male'] },
|
|
17
|
+
{ name: 'Rickon Stark', sets: ['was killed', 'Stark', 'male'] },
|
|
18
|
+
{ name: 'Robb Stark', sets: ['royal', 'was killed', 'Stark', 'male'] },
|
|
19
|
+
{ name: 'Sansa Stark', sets: ['royal', 'Stark', 'female'] },
|
|
20
|
+
{ name: 'Tyrion Lannister', sets: ['Lannister', 'male'] },
|
|
21
|
+
{ name: 'Tywin Lannister', sets: ['was killed', 'Lannister', 'male'] },
|
|
22
|
+
{ name: 'Willem Lannister', sets: ['was killed', 'Lannister', 'male'] }
|
|
23
|
+
];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ScaleBand } from 'd3-scale';
|
|
2
|
+
import { DataSet, Intersection, UpSetChartData } from './types';
|
|
3
|
+
export declare const findIntersections: (data: UpSetChartData) => {
|
|
4
|
+
intersections: Intersection[];
|
|
5
|
+
sets: DataSet[];
|
|
6
|
+
};
|
|
7
|
+
export declare const getMatrixData: (xScale: ScaleBand<string>, yScale: ScaleBand<string>, intersections: Intersection[], sets: DataSet[]) => {
|
|
8
|
+
circles: {
|
|
9
|
+
cx: number;
|
|
10
|
+
cy: number;
|
|
11
|
+
isPresent: boolean;
|
|
12
|
+
intersectionIndex: number;
|
|
13
|
+
}[];
|
|
14
|
+
lines: any[];
|
|
15
|
+
};
|
|
16
|
+
export declare const truncateLabels: (sets: DataSet[], maxLabelsWidth: number) => {
|
|
17
|
+
labels: string[];
|
|
18
|
+
maxWidth: number;
|
|
19
|
+
};
|
|
20
|
+
export declare const calculateTicksWidth: (ticks: number[]) => number;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
+
if (ar || !(i in from)) {
|
|
4
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
+
ar[i] = from[i];
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
+
};
|
|
10
|
+
import { AXIS_TICK_LABEL_SIZE, MAX_CHARACTERS, MIN_CHARACTERS, SET_LABEL_SIZE } from './constants';
|
|
11
|
+
export var findIntersections = function (data) {
|
|
12
|
+
var setsCombinations = {};
|
|
13
|
+
var individualSets = {};
|
|
14
|
+
data.forEach(function (_a) {
|
|
15
|
+
var name = _a.name, sets = _a.sets;
|
|
16
|
+
sets.forEach(function (set) {
|
|
17
|
+
if (!individualSets[set]) {
|
|
18
|
+
individualSets[set] = [];
|
|
19
|
+
}
|
|
20
|
+
individualSets[set].push(name);
|
|
21
|
+
});
|
|
22
|
+
var generateCombinations = function (subset, index) {
|
|
23
|
+
if (index === sets.length) {
|
|
24
|
+
if (subset.length > 0) {
|
|
25
|
+
var key = subset.sort().join(',');
|
|
26
|
+
if (!setsCombinations[key]) {
|
|
27
|
+
setsCombinations[key] = [];
|
|
28
|
+
}
|
|
29
|
+
setsCombinations[key].push(name);
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
generateCombinations(subset, index + 1);
|
|
34
|
+
generateCombinations(__spreadArray(__spreadArray([], subset, true), [sets[index]], false), index + 1);
|
|
35
|
+
};
|
|
36
|
+
generateCombinations([], 0);
|
|
37
|
+
});
|
|
38
|
+
var intersections = Object.entries(setsCombinations)
|
|
39
|
+
.map(function (_a, index) {
|
|
40
|
+
var key = _a[0], elements = _a[1];
|
|
41
|
+
return ({
|
|
42
|
+
index: index,
|
|
43
|
+
sets: key.split(','),
|
|
44
|
+
size: elements.length,
|
|
45
|
+
elements: elements
|
|
46
|
+
});
|
|
47
|
+
})
|
|
48
|
+
.sort(function (a, b) { return b.size - a.size; });
|
|
49
|
+
var sets = Object.entries(individualSets).map(function (_a, index) {
|
|
50
|
+
var name = _a[0], elements = _a[1];
|
|
51
|
+
return ({
|
|
52
|
+
index: index,
|
|
53
|
+
name: name,
|
|
54
|
+
size: elements.length,
|
|
55
|
+
elements: elements
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
return { intersections: intersections, sets: sets };
|
|
59
|
+
};
|
|
60
|
+
export var getMatrixData = function (xScale, yScale, intersections, sets) {
|
|
61
|
+
var circles = intersections.flatMap(function (intersection, i) {
|
|
62
|
+
return sets.map(function (set) { return ({
|
|
63
|
+
cx: xScale(String(i)) + xScale.bandwidth() / 2,
|
|
64
|
+
cy: yScale(set.name) + yScale.bandwidth() / 2,
|
|
65
|
+
isPresent: intersection.sets.includes(set.name),
|
|
66
|
+
intersectionIndex: intersection.index
|
|
67
|
+
}); });
|
|
68
|
+
});
|
|
69
|
+
var lines = intersections.reduce(function (acc, intersection, i) {
|
|
70
|
+
var activeSetIndices = intersection.sets
|
|
71
|
+
.map(function (name) { return sets.findIndex(function (set) { return set.name === name; }); })
|
|
72
|
+
.filter(function (i) { return i >= 0; })
|
|
73
|
+
.sort(function (a, b) { return a - b; });
|
|
74
|
+
if (activeSetIndices.length > 1) {
|
|
75
|
+
var firstIdx = activeSetIndices[0];
|
|
76
|
+
var lastIdx = activeSetIndices[activeSetIndices.length - 1];
|
|
77
|
+
var x = xScale(String(i)) + xScale.bandwidth() / 2;
|
|
78
|
+
var y1 = yScale(sets[firstIdx].name) + yScale.bandwidth() / 2;
|
|
79
|
+
var y2 = yScale(sets[lastIdx].name) + yScale.bandwidth() / 2;
|
|
80
|
+
return __spreadArray(__spreadArray([], acc, true), [{ x: x, y1: y1, y2: y2, intersectionIndex: intersection.index }], false);
|
|
81
|
+
}
|
|
82
|
+
return acc;
|
|
83
|
+
}, []);
|
|
84
|
+
return { circles: circles, lines: lines };
|
|
85
|
+
};
|
|
86
|
+
export var truncateLabels = function (sets, maxLabelsWidth) {
|
|
87
|
+
var newTruncatedLabels = [];
|
|
88
|
+
var maxWidth = 0;
|
|
89
|
+
var tempSvgElement = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
90
|
+
document.body.appendChild(tempSvgElement);
|
|
91
|
+
var tempTextElement = document.createElementNS('http://www.w3.org/2000/svg', 'text');
|
|
92
|
+
tempTextElement.setAttribute('font-size', SET_LABEL_SIZE);
|
|
93
|
+
tempSvgElement.appendChild(tempTextElement);
|
|
94
|
+
sets.forEach(function (_a) {
|
|
95
|
+
var name = _a.name;
|
|
96
|
+
var truncatedText = name.length > MAX_CHARACTERS ? name.slice(0, MAX_CHARACTERS) + '...' : name;
|
|
97
|
+
tempTextElement.textContent = truncatedText;
|
|
98
|
+
while (tempTextElement.getBBox().width > maxLabelsWidth && truncatedText.length > MIN_CHARACTERS) {
|
|
99
|
+
truncatedText = truncatedText.slice(0, -4) + '...';
|
|
100
|
+
tempTextElement.textContent = truncatedText;
|
|
101
|
+
}
|
|
102
|
+
newTruncatedLabels.push(truncatedText);
|
|
103
|
+
maxWidth = Math.max(maxWidth, tempTextElement.getBBox().width);
|
|
104
|
+
});
|
|
105
|
+
document.body.removeChild(tempSvgElement);
|
|
106
|
+
return { labels: newTruncatedLabels, maxWidth: maxWidth };
|
|
107
|
+
};
|
|
108
|
+
export var calculateTicksWidth = function (ticks) {
|
|
109
|
+
var tempSvgElement = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
110
|
+
var tempTextElement = document.createElementNS('http://www.w3.org/2000/svg', 'text');
|
|
111
|
+
tempTextElement.setAttribute('font-size', AXIS_TICK_LABEL_SIZE);
|
|
112
|
+
tempSvgElement.appendChild(tempTextElement);
|
|
113
|
+
document.body.appendChild(tempSvgElement);
|
|
114
|
+
var maxWidth = ticks.reduce(function (maxWidth, tick) {
|
|
115
|
+
tempTextElement.textContent = String(tick);
|
|
116
|
+
return Math.max(maxWidth, tempTextElement.getBBox().width);
|
|
117
|
+
}, 0);
|
|
118
|
+
document.body.removeChild(tempSvgElement);
|
|
119
|
+
return maxWidth;
|
|
120
|
+
};
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export declare const useStyles: (props
|
|
1
|
+
export declare const useStyles: (props: {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
}) => import("@mui/styles").ClassNameMap<"svg" | "wrapper">;
|
package/esm/UpSetChart/styles.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { makeStyles } from '@mui/styles';
|
|
2
|
-
export var useStyles = makeStyles(function (
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export var useStyles = makeStyles(function () { return ({
|
|
3
|
+
wrapper: function (_a) {
|
|
4
|
+
var width = _a.width, height = _a.height;
|
|
5
|
+
return ({
|
|
6
|
+
width: width,
|
|
7
|
+
height: height,
|
|
8
|
+
display: 'flex',
|
|
9
|
+
overflow: 'auto'
|
|
10
|
+
});
|
|
5
11
|
},
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
},
|
|
9
|
-
axisTick: {
|
|
10
|
-
fontSize: '12px !important'
|
|
11
|
-
},
|
|
12
|
-
chartLabel: {
|
|
13
|
-
fill: "".concat(theme.palette.text.secondary, " !important"),
|
|
14
|
-
fontSize: '10px !important'
|
|
12
|
+
svg: {
|
|
13
|
+
flexShrink: '0'
|
|
15
14
|
}
|
|
16
15
|
}); });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type UpSetChartData = {
|
|
2
|
+
name: string;
|
|
3
|
+
sets: string[];
|
|
4
|
+
}[];
|
|
5
|
+
export type Intersection = {
|
|
6
|
+
index: number;
|
|
7
|
+
sets: string[];
|
|
8
|
+
size: number;
|
|
9
|
+
elements: string[];
|
|
10
|
+
};
|
|
11
|
+
export type DataSet = {
|
|
12
|
+
index: number;
|
|
13
|
+
name: string;
|
|
14
|
+
size: number;
|
|
15
|
+
elements: string[];
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DataSet, Intersection } from './types';
|
|
2
|
+
type Props = {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
intersections: Intersection[];
|
|
6
|
+
sets: DataSet[];
|
|
7
|
+
};
|
|
8
|
+
export declare const useUpSetChartSizes: ({ width, height, intersections, sets }: Props) => {
|
|
9
|
+
labels: string[];
|
|
10
|
+
svgWidth: number;
|
|
11
|
+
svgHeight: number;
|
|
12
|
+
intersectionsChartWidth: number;
|
|
13
|
+
intersectionsChartHeight: number;
|
|
14
|
+
matrixY: number;
|
|
15
|
+
matrixHeight: number;
|
|
16
|
+
maxLabelsWidth: number;
|
|
17
|
+
leftPadding: number;
|
|
18
|
+
setsChartWidth: number;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { GAP_BEFORE_LEFT_BAR, GAP_BETWEEN_TABLE_AND_CHART, MATRIX_ROW_HEIGHT, MAX_SETS_CHART_WIDTH, MIN_INTERSECTION_CHART_HEIGHT, MIN_MATRIX_COLUMN_WIDTH, MIN_SETS_CHART_WIDTH, TEXT_GAP, TOP_GAP } from './constants';
|
|
2
|
+
import { truncateLabels } from './helpers';
|
|
3
|
+
export var useUpSetChartSizes = function (_a) {
|
|
4
|
+
var width = _a.width, height = _a.height, intersections = _a.intersections, sets = _a.sets;
|
|
5
|
+
var minMatrixWidth = intersections.length * MIN_MATRIX_COLUMN_WIDTH * 1.2;
|
|
6
|
+
var matrixHeight = sets.length * MATRIX_ROW_HEIGHT;
|
|
7
|
+
var availableLabelsWidth = width - minMatrixWidth - TEXT_GAP * 2 - GAP_BEFORE_LEFT_BAR - MIN_SETS_CHART_WIDTH;
|
|
8
|
+
var _b = truncateLabels(sets, availableLabelsWidth), labels = _b.labels, labelsWidth = _b.maxWidth;
|
|
9
|
+
var availableSetsChartWidth = width - minMatrixWidth - TEXT_GAP * 2 - GAP_BEFORE_LEFT_BAR - labelsWidth;
|
|
10
|
+
var setsChartWidth = Math.min(Math.max(availableSetsChartWidth, MIN_SETS_CHART_WIDTH), MAX_SETS_CHART_WIDTH);
|
|
11
|
+
var maxLabelsWidth = width - minMatrixWidth - TEXT_GAP * 2 - GAP_BEFORE_LEFT_BAR - setsChartWidth;
|
|
12
|
+
var leftPadding = setsChartWidth + labelsWidth + TEXT_GAP * 2 + GAP_BEFORE_LEFT_BAR;
|
|
13
|
+
var intersectionsChartWidth = Math.max(minMatrixWidth, width - leftPadding);
|
|
14
|
+
var intersectionsChartHeight = Math.max(MIN_INTERSECTION_CHART_HEIGHT, height - TOP_GAP - matrixHeight - GAP_BETWEEN_TABLE_AND_CHART);
|
|
15
|
+
var svgWidth = leftPadding + intersectionsChartWidth;
|
|
16
|
+
var svgHeight = intersectionsChartHeight + matrixHeight + TOP_GAP + GAP_BETWEEN_TABLE_AND_CHART;
|
|
17
|
+
var matrixY = svgHeight - matrixHeight - 1;
|
|
18
|
+
return {
|
|
19
|
+
labels: labels,
|
|
20
|
+
svgWidth: svgWidth,
|
|
21
|
+
svgHeight: svgHeight,
|
|
22
|
+
intersectionsChartWidth: intersectionsChartWidth,
|
|
23
|
+
intersectionsChartHeight: intersectionsChartHeight,
|
|
24
|
+
matrixY: matrixY,
|
|
25
|
+
matrixHeight: matrixHeight,
|
|
26
|
+
maxLabelsWidth: maxLabelsWidth,
|
|
27
|
+
leftPadding: leftPadding,
|
|
28
|
+
setsChartWidth: setsChartWidth
|
|
29
|
+
};
|
|
30
|
+
};
|