@page-speed/venn-diagram 0.0.4 → 0.0.6
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/dist/cjs/esm/hooks/useVennLayout.d.ts.map +1 -1
- package/dist/cjs/index.js +48 -36
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/VennDiagram.js +1 -1
- package/dist/esm/components/VennDiagram.js.map +1 -1
- package/dist/esm/hooks/useVennLayout.d.ts.map +1 -1
- package/dist/esm/hooks/useVennLayout.js +48 -36
- package/dist/esm/hooks/useVennLayout.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVennLayout.d.ts","sourceRoot":"","sources":["../../../src/hooks/useVennLayout.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EAER,mBAAmB,EACpB,MAAM,qBAAqB,CAAC;AAE7B,UAAU,oBAAoB;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAMD,eAAO,MAAM,aAAa,GACxB,MAAM,QAAQ,EACd,UAAS,oBAAyB,KACjC,
|
|
1
|
+
{"version":3,"file":"useVennLayout.d.ts","sourceRoot":"","sources":["../../../src/hooks/useVennLayout.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EAER,mBAAmB,EACpB,MAAM,qBAAqB,CAAC;AAE7B,UAAU,oBAAoB;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAMD,eAAO,MAAM,aAAa,GACxB,MAAM,QAAQ,EACd,UAAS,oBAAyB,KACjC,mBA2FF,CAAC;AAKF,eAAO,MAAM,qBAAqB,GAChC,cAAc,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,EAC7C,eAAc,MAAY,EAC1B,gBAAe,MAAY;;;CAiC5B,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -3099,8 +3099,6 @@ const useVennLayout = (data, options = {}) => {
|
|
|
3099
3099
|
height = 400,
|
|
3100
3100
|
padding = 40
|
|
3101
3101
|
} = options;
|
|
3102
|
-
const [error, setError] = require$$0.useState(null);
|
|
3103
|
-
const [isLoading, setIsLoading] = require$$0.useState(false);
|
|
3104
3102
|
const vennData = require$$0.useMemo(() => {
|
|
3105
3103
|
const sets = data.sets.map(set => ({
|
|
3106
3104
|
sets: [set.name],
|
|
@@ -3111,31 +3109,60 @@ const useVennLayout = (data, options = {}) => {
|
|
|
3111
3109
|
size: intersection.size
|
|
3112
3110
|
}));
|
|
3113
3111
|
return [...sets, ...intersections];
|
|
3114
|
-
}, [data]);
|
|
3115
|
-
const
|
|
3112
|
+
}, [data.sets, data.intersections]);
|
|
3113
|
+
const {
|
|
3114
|
+
layout: layout$1,
|
|
3115
|
+
textPositions,
|
|
3116
|
+
error
|
|
3117
|
+
} = require$$0.useMemo(() => {
|
|
3116
3118
|
try {
|
|
3117
|
-
setIsLoading(true);
|
|
3118
|
-
setError(null);
|
|
3119
3119
|
const computed = layout(vennData, {
|
|
3120
|
-
width
|
|
3121
|
-
height
|
|
3120
|
+
width,
|
|
3121
|
+
height,
|
|
3122
|
+
padding
|
|
3123
|
+
});
|
|
3124
|
+
const circleLookup = new Map();
|
|
3125
|
+
computed.forEach(entry => {
|
|
3126
|
+
const sets = entry?.data?.sets;
|
|
3127
|
+
const circles = entry?.circles;
|
|
3128
|
+
if (Array.isArray(sets) && sets.length === 1 && Array.isArray(circles) && circles[0]) {
|
|
3129
|
+
const circle = circles[0];
|
|
3130
|
+
circleLookup.set(sets[0], {
|
|
3131
|
+
x: circle.x ?? 0,
|
|
3132
|
+
y: circle.y ?? 0,
|
|
3133
|
+
radius: circle.radius ?? 0,
|
|
3134
|
+
set: sets[0]
|
|
3135
|
+
});
|
|
3136
|
+
}
|
|
3137
|
+
});
|
|
3138
|
+
const circles = data.sets.map(set => {
|
|
3139
|
+
return circleLookup.get(set.name) ?? {
|
|
3140
|
+
x: 0,
|
|
3141
|
+
y: 0,
|
|
3142
|
+
radius: 0,
|
|
3143
|
+
set: set.name
|
|
3144
|
+
};
|
|
3122
3145
|
});
|
|
3123
|
-
const
|
|
3124
|
-
x:
|
|
3125
|
-
y:
|
|
3126
|
-
|
|
3127
|
-
set: d.sets[0]
|
|
3146
|
+
const positions = computed.filter(entry => entry?.text && entry?.data?.sets).map(entry => ({
|
|
3147
|
+
x: entry.text?.x ?? 0,
|
|
3148
|
+
y: entry.text?.y ?? 0,
|
|
3149
|
+
setNames: Array.isArray(entry.data?.sets) ? entry.data.sets : []
|
|
3128
3150
|
}));
|
|
3129
|
-
return
|
|
3151
|
+
return {
|
|
3152
|
+
layout: circles,
|
|
3153
|
+
textPositions: positions,
|
|
3154
|
+
error: null
|
|
3155
|
+
};
|
|
3130
3156
|
} catch (err) {
|
|
3131
3157
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
3132
|
-
setError(error);
|
|
3133
3158
|
console.error("Venn diagram layout error:", error);
|
|
3134
|
-
return
|
|
3135
|
-
|
|
3136
|
-
|
|
3159
|
+
return {
|
|
3160
|
+
layout: [],
|
|
3161
|
+
textPositions: [],
|
|
3162
|
+
error
|
|
3163
|
+
};
|
|
3137
3164
|
}
|
|
3138
|
-
}, [vennData, width, height, padding]);
|
|
3165
|
+
}, [vennData, width, height, padding, data.sets]);
|
|
3139
3166
|
const paths = require$$0.useMemo(() => {
|
|
3140
3167
|
return layout$1.map(circle => {
|
|
3141
3168
|
const {
|
|
@@ -3146,27 +3173,12 @@ const useVennLayout = (data, options = {}) => {
|
|
|
3146
3173
|
return `M ${x - radius} ${y} A ${radius} ${radius} 0 1 0 ${x + radius} ${y} A ${radius} ${radius} 0 1 0 ${x - radius} ${y}`;
|
|
3147
3174
|
});
|
|
3148
3175
|
}, [layout$1]);
|
|
3149
|
-
const textPositions = require$$0.useMemo(() => {
|
|
3150
|
-
try {
|
|
3151
|
-
const computed = layout(vennData, {
|
|
3152
|
-
width: width - padding * 2,
|
|
3153
|
-
height: height - padding * 2
|
|
3154
|
-
});
|
|
3155
|
-
return computed.map(d => ({
|
|
3156
|
-
x: padding + (d.x || 0) + (width - padding * 2) / 2,
|
|
3157
|
-
y: padding + (d.y || 0) + (height - padding * 2) / 2,
|
|
3158
|
-
setNames: d.sets
|
|
3159
|
-
}));
|
|
3160
|
-
} catch {
|
|
3161
|
-
return [];
|
|
3162
|
-
}
|
|
3163
|
-
}, [vennData, width, height, padding]);
|
|
3164
3176
|
return {
|
|
3165
3177
|
layout: layout$1,
|
|
3166
3178
|
paths,
|
|
3167
3179
|
textPositions,
|
|
3168
3180
|
error,
|
|
3169
|
-
isLoading
|
|
3181
|
+
isLoading: false
|
|
3170
3182
|
};
|
|
3171
3183
|
};
|
|
3172
3184
|
const useResponsiveVennSize = (containerRef, defaultWidth = 600, defaultHeight = 400) => {
|
|
@@ -3385,7 +3397,7 @@ const VennDiagram = ({
|
|
|
3385
3397
|
const containerRef = require$$0.useRef(null);
|
|
3386
3398
|
const [hoveredSets, setHoveredSets] = require$$0.useState(null);
|
|
3387
3399
|
const [selectedSets, setSelectedSets] = require$$0.useState(null);
|
|
3388
|
-
const dimensions = useResponsiveVennSize(containerRef, width,
|
|
3400
|
+
const dimensions = useResponsiveVennSize(containerRef, width, height);
|
|
3389
3401
|
const finalWidth = responsive ? dimensions.width : width;
|
|
3390
3402
|
const finalHeight = responsive ? dimensions.height : height;
|
|
3391
3403
|
const {
|