-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathrenderMarks.js
More file actions
52 lines (50 loc) · 1.13 KB
/
renderMarks.js
File metadata and controls
52 lines (50 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
export const renderMarks = (
svg,
{
data,
xScale,
yScale,
xValue,
yValue,
pointRadius,
pointRadiusValue,
pointRadiusScale,
sizeScale,
sizeValue,
colorScale,
pointOpacity,
blurRadius = 0,
},
) => {
// Add filter definitions if blur is needed
if (blurRadius > 0) {
svg
.append('defs')
.append('filter')
.attr('id', 'blur-filter')
.append('feGaussianBlur')
.attr('stdDeviation', blurRadius);
}
// Render the data points
const points = svg
.selectAll('circle.data-point')
.data(data)
.join('circle')
.attr('class', 'data-point')
.attr('cx', (d) => xScale(xValue(d)))
.attr('cy', (d) => yScale(yValue(d)))
.attr('r', (d) => {
if (sizeValue) return sizeScale(sizeValue(d));
if (pointRadiusValue)
return pointRadiusScale(pointRadiusValue(d));
return pointRadius;
})
.attr('fill', (d) => colorScale[d.species])
.attr('opacity', pointOpacity);
// Apply blur filter if needed
if (blurRadius > 0) {
points.attr('filter', 'url(#blur-filter)');
} else {
points.attr('filter', null);
}
};