Skip to content

Commit

Permalink
fix: sort data for occlusion
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed May 31, 2023
1 parent cd92a6b commit fec7bc8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
8 changes: 5 additions & 3 deletions site/examples/general/venn/demo/venn.ts
Expand Up @@ -33,8 +33,10 @@ chart
text: (d) => d.label || '',
transform: [{ type: 'contrastReverse' }],
})
.style('opacity', 0.4)
.legend(false)
.tooltip({ title: { channel: 'label', valueFormatter: '.1f' } });
.style('opacity', (d) => (d.sets.length > 1 ? 0.001 : 0.5))
.state('inactive', { opacity: 0.2 })
.state('active', { opacity: 0.8 })
.interaction('elementHighlight', true)
.legend(false);

chart.render();
20 changes: 11 additions & 9 deletions src/data/venn.ts
Expand Up @@ -23,15 +23,14 @@ export const Venn: DC<VennOptions> = (options) => {
const [key, path] = as;
return (data) => {
// Transform the data, venn layout use `sets` and `size` field.
const vennData: VennData[] = data.map((d) => ({
...d,
sets: d[sets],
size: d[size],
[key]: d.sets.join('&'),
}));
// Sort data, avoid data occlusion.
const vennData: VennData[] = data
.map((d) => ({
...d,
sets: d[sets],
size: d[size],
[key]: d.sets.join('&'),
}))
.sort((a, b) => a.sets.length - b.sets.length);
vennData.sort((a, b) => a.sets.length - b.sets.length);

// Layout venn data.
const solution = venn(vennData);
Expand All @@ -45,7 +44,10 @@ export const Venn: DC<VennOptions> = (options) => {
? circles
: scaleSolution(solution, width, height, padding);
const setCircles = setsValue.map((set) => circles[set]);
return intersectionAreaPath(setCircles);
let p = intersectionAreaPath(setCircles);
// Close the path for event picker.
if (!/[zZ]$/.test(p)) p += ' Z';
return p;
};

return { ...datum, [path]: pathFunc };
Expand Down

0 comments on commit fec7bc8

Please sign in to comment.