Skip to content

Commit b5a674f

Browse files
committed
a little more stuff contourcarpet can inherit from contour
1 parent f5873f1 commit b5a674f

File tree

3 files changed

+16
-56
lines changed

3 files changed

+16
-56
lines changed

src/traces/contour/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var Contour = {};
1414
Contour.attributes = require('./attributes');
1515
Contour.supplyDefaults = require('./defaults');
1616
Contour.calc = require('./calc');
17-
Contour.plot = require('./plot');
17+
Contour.plot = require('./plot').plot;
1818
Contour.style = require('./style');
1919
Contour.colorbar = require('./colorbar');
2020
Contour.hoverPoints = require('./hover');

src/traces/contour/plot.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var constants = require('./constants');
2525
var costConstants = constants.LABELOPTIMIZER;
2626

2727

28-
module.exports = function plot(gd, plotinfo, cdcontours) {
28+
exports.plot = function plot(gd, plotinfo, cdcontours) {
2929
for(var i = 0; i < cdcontours.length; i++) {
3030
plotOne(gd, plotinfo, cdcontours[i]);
3131
}
@@ -82,7 +82,7 @@ function plotOne(gd, plotinfo, cd) {
8282
];
8383

8484
// draw everything
85-
var plotGroup = makeContourGroup(plotinfo, cd, id);
85+
var plotGroup = exports.makeContourGroup(plotinfo, cd, id);
8686
makeBackground(plotGroup, perimeter, contours);
8787
makeFills(plotGroup, pathinfo, perimeter, contours);
8888
makeLinesAndLabels(plotGroup, pathinfo, gd, cd[0], contours, perimeter);
@@ -123,7 +123,7 @@ function emptyPathinfo(contours, plotinfo, cd0) {
123123
}
124124
return pathinfo;
125125
}
126-
function makeContourGroup(plotinfo, cd, id) {
126+
exports.makeContourGroup = function(plotinfo, cd, id) {
127127
var plotgroup = plotinfo.plot.select('.maplayer')
128128
.selectAll('g.contour.' + id)
129129
.data(cd);
@@ -135,7 +135,7 @@ function makeContourGroup(plotinfo, cd, id) {
135135
plotgroup.exit().remove();
136136

137137
return plotgroup;
138-
}
138+
};
139139

140140
function makeBackground(plotgroup, perimeter, contours) {
141141
var bggroup = plotgroup.selectAll('g.contourbg').data([0]);
@@ -278,7 +278,7 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
278278
// if we're showing labels, because the fill paths include the perimeter
279279
// so can't be used to position the labels correctly.
280280
// In this case we'll remove the lines after making the labels.
281-
var linegroup = createLines(lineContainer, showLines || showLabels, pathinfo);
281+
var linegroup = exports.createLines(lineContainer, showLines || showLabels, pathinfo);
282282

283283
var lineClip = createLineClip(lineContainer, clipLinesForLabels,
284284
gd._fullLayout._defs, cd0.trace.uid);
@@ -358,7 +358,7 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
358358
if(showLabels && !showLines) linegroup.remove();
359359
}
360360

361-
function createLines(lineContainer, makeLines, pathinfo) {
361+
exports.createLines = function(lineContainer, makeLines, pathinfo) {
362362
var smoothing = pathinfo[0].smoothing;
363363

364364
var linegroup = lineContainer.selectAll('g.contourlevel')
@@ -369,8 +369,10 @@ function createLines(lineContainer, makeLines, pathinfo) {
369369
.classed('contourlevel', true);
370370

371371
if(makeLines) {
372+
// pedgepaths / ppaths are used by contourcarpet, for the paths transformed from a/b to x/y
373+
// edgepaths / paths are used by contour since it's in x/y from the start
372374
var opencontourlines = linegroup.selectAll('path.openline')
373-
.data(function(d) { return d.edgepaths; });
375+
.data(function(d) { return d.pedgepaths || d.edgepaths; });
374376

375377
opencontourlines.exit().remove();
376378
opencontourlines.enter().append('path')
@@ -384,7 +386,7 @@ function createLines(lineContainer, makeLines, pathinfo) {
384386
.style('vector-effect', 'non-scaling-stroke');
385387

386388
var closedcontourlines = linegroup.selectAll('path.closedline')
387-
.data(function(d) { return d.paths; });
389+
.data(function(d) { return d.ppaths || d.paths; });
388390

389391
closedcontourlines.exit().remove();
390392
closedcontourlines.enter().append('path')
@@ -399,7 +401,7 @@ function createLines(lineContainer, makeLines, pathinfo) {
399401
}
400402

401403
return linegroup;
402-
}
404+
};
403405

404406
function createLineClip(lineContainer, clipLinesForLabels, defs, uid) {
405407
var clipId = clipLinesForLabels ? ('clipline' + uid) : null;

src/traces/contourcarpet/plot.js

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var Drawing = require('../../components/drawing');
1515

1616
var makeCrossings = require('../contour/make_crossings');
1717
var findAllPaths = require('../contour/find_all_paths');
18+
var contourPlot = require('../contour/plot');
1819
var convertToConstraints = require('./convert_to_constraints');
1920
var joinAllPaths = require('./join_all_paths');
2021
var emptyPathinfo = require('./empty_pathinfo');
@@ -95,7 +96,7 @@ function plotOne(gd, plotinfo, cd) {
9596
mapPathinfo(pathinfo, ab2p);
9697

9798
// draw everything
98-
var plotGroup = makeContourGroup(plotinfo, cd, id);
99+
var plotGroup = contourPlot.makeContourGroup(plotinfo, cd, id);
99100

100101
// Compute the boundary path
101102
var seg, xp, yp, i;
@@ -131,52 +132,9 @@ function clipBoundary(plotGroup, carpet) {
131132
plotGroup.attr('clip-path', 'url(#' + carpet.clipPathId + ')');
132133
}
133134

134-
function makeContourGroup(plotinfo, cd, id) {
135-
var plotgroup = plotinfo.plot.select('.maplayer')
136-
.selectAll('g.contour.' + id)
137-
.classed('trace', true)
138-
.data(cd);
139-
140-
plotgroup.enter().append('g')
141-
.classed('contour', true)
142-
.classed(id, true);
143-
144-
plotgroup.exit().remove();
145-
146-
return plotgroup;
147-
}
148-
149135
function makeLines(plotgroup, pathinfo, contours) {
150-
var smoothing = pathinfo[0].smoothing;
151-
152-
var linegroup = plotgroup.selectAll('g.contourlevel')
153-
.data(contours.showlines === false ? [] : pathinfo);
154-
linegroup.enter().append('g')
155-
.classed('contourlevel', true);
156-
linegroup.exit().remove();
157-
158-
var opencontourlines = linegroup.selectAll('path.openline')
159-
.data(function(d) { return d.pedgepaths; });
160-
opencontourlines.enter().append('path')
161-
.classed('openline', true);
162-
opencontourlines.exit().remove();
163-
opencontourlines
164-
.attr('d', function(d) {
165-
return Drawing.smoothopen(d, smoothing);
166-
})
167-
.style('vector-effect', 'non-scaling-stroke');
168-
169-
var closedcontourlines = linegroup.selectAll('path.closedline')
170-
.data(function(d) { return d.ppaths; });
171-
closedcontourlines.enter().append('path')
172-
.classed('closedline', true);
173-
closedcontourlines.exit().remove();
174-
closedcontourlines
175-
.attr('d', function(d) {
176-
return Drawing.smoothclosed(d, smoothing);
177-
})
178-
.style('vector-effect', 'non-scaling-stroke')
179-
.style('stroke-miterlimit', 1);
136+
contourPlot.createLines(plotgroup,
137+
contours.showlines !== false, pathinfo);
180138
}
181139

182140
function makeBackground(plotgroup, clipsegments, xaxis, yaxis, isConstraint, coloring) {

0 commit comments

Comments
 (0)