Skip to content

Commit 11ddf3a

Browse files
Merge pull request #165 from alexmww/ticket-164
add hasOwnProperty check; fix attr for scatter and polyline graphTypes
2 parents a517f5a + a7bee63 commit 11ddf3a

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/graph-types/interval.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,21 @@ export default function interval (chart: Chart) {
8989
.attr('fill', 'none')
9090

9191
// enter + update
92-
innerSelection.merge(innerSelectionEnter)
92+
const selection = innerSelection.merge(innerSelectionEnter)
9393
.attr('stroke-width', minWidthHeight)
9494
.attr('stroke', utils.color(d, index) as any)
9595
.attr('opacity', closed ? 0.5 : 1)
9696
.attr('d', function (d: Interval[][]) {
9797
return line(d, closed)
9898
})
99-
.attr(d.attr)
99+
100+
if (d.attr) {
101+
for (let k in d.attr) {
102+
if(d.attr.hasOwnProperty(k)) {
103+
selection.attr(k, d.attr[k])
104+
}
105+
}
106+
}
100107

101108
innerSelection.exit().remove()
102109
})

src/graph-types/polyline.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ export default function polyline (chart: Chart) {
7979

8080
if (d.attr) {
8181
for (let k in d.attr) {
82-
path.attr(k, d.attr[k])
82+
if(d.attr.hasOwnProperty(k)) {
83+
path.attr(k, d.attr[k])
84+
}
8385
}
8486
}
8587
})

src/graph-types/scatter.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,21 @@ export default function scatter (chart: Chart) {
3434
const innerSelectionEnter = innerSelection.enter()
3535
.append('circle')
3636

37-
innerSelection.merge(innerSelectionEnter)
37+
const selection = innerSelection.merge(innerSelectionEnter)
3838
.attr('fill', d3Hsl(color.toString()).brighter(1.5).hex())
3939
.attr('stroke', color)
4040
.attr('opacity', 0.7)
4141
.attr('r', 1)
4242
.attr('cx', function (d) { return xScale(d[0]) })
43-
.attr('cy', function (d) { return yScale(d[1]) })
44-
.attr(d.attr)
43+
.attr('cy', function (d) { return yScale(d[1]) });
44+
45+
if (d.attr) {
46+
for (let k in d.attr) {
47+
if(d.attr.hasOwnProperty(k)) {
48+
selection.attr(k, d.attr[k])
49+
}
50+
}
51+
}
4552

4653
innerSelection.exit().remove()
4754
})

0 commit comments

Comments
 (0)