@page-speed/venn-diagram 0.0.5 → 0.0.7

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 +1 @@
1
- {"version":3,"file":"VennDiagram.d.ts","sourceRoot":"","sources":["../../../src/components/VennDiagram.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAA0B,MAAM,qBAAqB,CAAC;AA6B/E,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CA8KlD,CAAC"}
1
+ {"version":3,"file":"VennDiagram.d.ts","sourceRoot":"","sources":["../../../src/components/VennDiagram.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAA0B,MAAM,qBAAqB,CAAC;AA6B/E,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAkLlD,CAAC"}
@@ -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,mBAwFF,CAAC;AAKF,eAAO,MAAM,qBAAqB,GAChC,cAAc,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,EAC7C,eAAc,MAAY,EAC1B,gBAAe,MAAY;;;CAiC5B,CAAC"}
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 layout$1 = require$$0.useMemo(() => {
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: width - padding * 2,
3121
- height: height - padding * 2
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 circles = computed.filter(d => d.circles && d.circles.length === 1).map(d => ({
3124
- x: padding + (d.x || 0) + (width - padding * 2) / 2,
3125
- y: padding + (d.y || 0) + (height - padding * 2) / 2,
3126
- radius: d.radius || 0,
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 circles;
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
- } finally {
3136
- setIsLoading(false);
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) => {
@@ -3238,7 +3250,7 @@ const isAccessibleContrast = (foreground, background) => {
3238
3250
  return contrastRatio >= 4.5;
3239
3251
  };
3240
3252
 
3241
- var styles = {"vennContainer":"VennDiagram-module_vennContainer__zE5Q4","svg":"VennDiagram-module_svg__8SEMM","circleGroup":"VennDiagram-module_circleGroup__9MTB2","circle":"VennDiagram-module_circle__sXeUM","selected":"VennDiagram-module_selected__U2SLC","labelGroup":"VennDiagram-module_labelGroup__bbeK2","value":"VennDiagram-module_value__0wKIt","label":"VennDiagram-module_label__fsN9f","legend":"VennDiagram-module_legend__ZOQL5","legendItem":"VennDiagram-module_legendItem__G3upl","legendLabel":"VennDiagram-module_legendLabel__yK6aP","legendValue":"VennDiagram-module_legendValue__cuwMv","error":"VennDiagram-module_error__czgBP","loading":"VennDiagram-module_loading__8lTBq"};
3253
+ var styles = {"vennRoot":"VennDiagram-module_vennRoot__iCmDV","vennContainer":"VennDiagram-module_vennContainer__zE5Q4","svg":"VennDiagram-module_svg__8SEMM","circleGroup":"VennDiagram-module_circleGroup__9MTB2","circle":"VennDiagram-module_circle__sXeUM","selected":"VennDiagram-module_selected__U2SLC","labelGroup":"VennDiagram-module_labelGroup__bbeK2","value":"VennDiagram-module_value__0wKIt","label":"VennDiagram-module_label__fsN9f","legend":"VennDiagram-module_legend__ZOQL5","legendItem":"VennDiagram-module_legendItem__G3upl","legendLabel":"VennDiagram-module_legendLabel__yK6aP","legendValue":"VennDiagram-module_legendValue__cuwMv","error":"VennDiagram-module_error__czgBP","loading":"VennDiagram-module_loading__8lTBq"};
3242
3254
 
3243
3255
  const VennDiagramContext = /*#__PURE__*/require$$0.createContext(null);
3244
3256
  VennDiagramContext.displayName = "VennDiagramContext";
@@ -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, responsive ? width : undefined);
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 {
@@ -3450,20 +3462,23 @@ const VennDiagram = ({
3450
3462
  return jsxRuntimeExports.jsx(VennDiagramContext.Provider, {
3451
3463
  value: contextValue,
3452
3464
  children: jsxRuntimeExports.jsxs("div", {
3453
- ref: containerRef,
3454
- className: `${styles.vennContainer} ${className || ""}`,
3455
- style: {
3456
- width: responsive ? "100%" : finalWidth,
3457
- height: responsive ? "100%" : finalHeight,
3458
- ...style
3459
- },
3465
+ className: `${styles.vennRoot} ${className || ""}`,
3466
+ style: style,
3460
3467
  "data-testid": testId,
3461
- children: [renderer === "svg" && jsxRuntimeExports.jsx(VennDiagramSVG, {
3462
- layout: layout,
3463
- textPositions: textPositions,
3464
- width: finalWidth,
3465
- height: finalHeight,
3466
- onClick: onClick
3468
+ children: [jsxRuntimeExports.jsx("div", {
3469
+ ref: containerRef,
3470
+ className: styles.vennContainer,
3471
+ style: {
3472
+ width: responsive ? "100%" : finalWidth,
3473
+ height: responsive ? "100%" : finalHeight
3474
+ },
3475
+ children: renderer === "svg" && jsxRuntimeExports.jsx(VennDiagramSVG, {
3476
+ layout: layout,
3477
+ textPositions: textPositions,
3478
+ width: finalWidth,
3479
+ height: finalHeight,
3480
+ onClick: onClick
3481
+ })
3467
3482
  }), showLegend && jsxRuntimeExports.jsx("div", {
3468
3483
  className: styles.legend,
3469
3484
  children: data.sets.map((set, idx) => jsxRuntimeExports.jsxs("div", {