Skip to content

Commit 0eec095

Browse files
committed
DRY
1 parent f1b5038 commit 0eec095

File tree

1 file changed

+10
-29
lines changed

1 file changed

+10
-29
lines changed

src/marks/delaunay.js

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class DelaunayLink extends Mark {
9999
}
100100

101101
export class DelaunayMesh extends Mark {
102-
constructor(data, options = {}) {
102+
constructor(data, options = {}, defaults = meshDefaults) {
103103
const {x, y} = options;
104104
super(
105105
data,
@@ -108,50 +108,31 @@ export class DelaunayMesh extends Mark {
108108
{name: "y", value: y, scale: "y"}
109109
],
110110
options,
111-
meshDefaults
111+
defaults
112112
);
113113
}
114+
_render(index, {x: X, y: Y}) {
115+
return Delaunay.from(index, i => X[i], i => Y[i]).render();
116+
}
114117
render(index, {x, y}, channels, dimensions) {
115-
const {x: X, y: Y} = channels;
116118
const {dx, dy} = this;
117119
// TODO Group by z or stroke.
118-
const delaunay = Delaunay.from(index, i => X[i], i => Y[i]);
119120
return create("svg:g")
120121
.call(applyIndirectStyles, this, dimensions)
121122
.call(g => g.append("path")
122123
.call(applyDirectStyles, this)
123124
.call(applyTransform, x, y, offset + dx, offset + dy)
124-
.attr("d", delaunay.render()))
125+
.attr("d", this._render(index, channels)))
125126
.node();
126127
}
127128
}
128129

129-
export class Hull extends Mark {
130+
export class Hull extends DelaunayMesh {
130131
constructor(data, options = {}) {
131-
const {x, y} = options;
132-
super(
133-
data,
134-
[
135-
{name: "x", value: x, scale: "x"},
136-
{name: "y", value: y, scale: "y"}
137-
],
138-
options,
139-
hullDefaults
140-
);
132+
super(data, options, hullDefaults);
141133
}
142-
render(index, {x, y}, channels, dimensions) {
143-
const {x: X, y: Y} = channels;
144-
const {dx, dy} = this;
145-
// TODO Group by z or stroke.
146-
// TODO Use faster monotone chain algorithm?
147-
const delaunay = Delaunay.from(index, i => X[i], i => Y[i]);
148-
return create("svg:g")
149-
.call(applyIndirectStyles, this, dimensions)
150-
.call(g => g.append("path")
151-
.call(applyDirectStyles, this)
152-
.call(applyTransform, x, y, offset + dx, offset + dy)
153-
.attr("d", delaunay.renderHull()))
154-
.node();
134+
_render(index, {x: X, y: Y}) {
135+
return Delaunay.from(index, i => X[i], i => Y[i]).renderHull();
155136
}
156137
}
157138

0 commit comments

Comments
 (0)