8000 Log contour by alexcjohnson · Pull Request #1856 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Log contour #1856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions src/traces/contour/find_all_paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ function equalPts(pt1, pt2, xtol, ytol) {
Math.abs(pt1[1] - pt2[1]) < ytol;
}

// distance in index units - uses the 3rd and 4th items in points
function ptDist(pt1, pt2) {
var dx = pt1[0] - pt2[0],
dy = pt1[1] - pt2[1];
var dx = pt1[2] - pt2[2],
dy = pt1[3] - pt2[3];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 0/1 vs 2/3 the difference between data units and grid index units?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - kinda hacky but since we had this available when calculating the pixel positions I tacked it on.

return Math.sqrt(dx * dx + dy * dy);
}

Expand Down Expand Up @@ -114,9 +115,13 @@ function makePath(pi, loc, edgeflag, xtol, ytol) {
ptavg,
thisdist;

// check for points that are too close together (<1/5 the average dist,
// less if less smoothed) and just take the center (or avg of center 2)
// this cuts down on funny behavior when a point is very close to a contour level
/*
* Check for points that are too close together (<1/5 the average dist
* *in grid index units* (important for log axes and nonuniform grids),
* less if less smoothed) and just take the center (or avg of center 2).
* This cuts down on funny behavior when a point is very close to a
* contour level.
*/
for(cnt = 1; cnt < pts.length; cnt++) {
thisdist = ptDist(pts[cnt], pts[cnt - 1]);
totaldist += thisdist;
Expand Down Expand Up @@ -174,6 +179,10 @@ function makePath(pi, loc, edgeflag, xtol, ytol) {
}
pts.splice(0, cropstart);

// done with the index parts - remove them so path generation works right
// because it depends on only having [xpx, ypx]
for(cnt = 0; cnt < pts.length; cnt++) pts[cnt].length = 2;

// don't return single-point paths (ie all points were the same
// so they got deleted?)
if(pts.length < 2) return;
Expand Down Expand Up @@ -252,6 +261,21 @@ function startStep(mi, edgeflag, loc) {
return [dx, dy];
}

/*
* Find the pixel coordinates of a particular crossing
*
* @param {object} pi: the pathinfo object at this level
* @param {array} loc: the grid index [x, y] of the crossing
* @param {array} step: the direction [dx, dy] we're moving on the grid
*
* @return {array} [xpx, ypx, xi, yi]: the first two are the pixel location,
* the next two are the interpolated grid indices, which we use for
* distance calculations to delete points that are too close together.
* This is important when the grid is nonuniform (and most dramatically when
* we're on log axes and include invalid (0 or negative) values.
* It's crucial to delete these extra two before turning an array of these
* points into a path, because those routines require length-2 points.
*/
function getInterpPx(pi, loc, step) {
var locx = loc[0] + Math.max(step[0], 0),
locy = loc[1] + Math.max(step[1], 0),
Expand All @@ -263,11 +287,13 @@ function getInterpPx(pi, loc, step) {
var dx = (pi.level - zxy) / (pi.z[locy][locx + 1] - zxy);

return [xa.c2p((1 - dx) * pi.x[locx] + dx * pi.x[locx + 1], true),
ya.c2p(pi.y[locy], true)];
ya.c2p(pi.y[locy], true),
locx + dx, locy];
}
else {
var dy = (pi.level - zxy) / (pi.z[locy + 1][locx] - zxy);
return [xa.c2p(pi.x[locx], true),
ya.c2p((1 - dy) * pi.y[locy] + dy * pi.y[locy + 1], true)];
ya.c2p((1 - dy) * pi.y[locy] + dy * pi.y[locy + 1], true),
locx, locy + dy];
}
}
Binary file modified test/image/baselines/2dhistogram_contour_subplots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/colorscale_opacity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/connectgaps_2d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/contour_heatmap_coloring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/contour_lines_coloring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/image/baselines/contour_log.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baseli 6D47 nes/contour_transposed-irregular.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/contour_transposed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/simple_contour.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions test/image/mocks/contour_log.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"data": [
{
"x": [0, 1, 2, 3, 10, 30],
"y": [0, 1, 2, 3, 10, 30],
"z": [
[10, 9, 8, 7, 6, 5],
[9, 8, 7, 6, 5, 4],
[8, 7, 6, 5, 4, 3],
[7, 6, 5, 9, 3, 2],
[6, 5, 4, 8, 2, 1],
[5, 4, 3, 2, 1, 0]
],
"contours": {"start": 4, "end": 6.5, "size": 1},
"type": "contour"
},
{
"x": [0, 1, 2, 3, 10, 30],
"y": [0, 1, 2, 3, 10, 30],
"z": [
[10, 9, 8, 7, 6, 5],
[9, 8, 7, 6, 5, 4],
[8, 7, 6, 5, 4, 3],
[7, 6, 5, 9, 3, 2],
[6, 5, 4, 8, 2, 1],
[5, 4, 3, 2, 1, 0]
],
"contours": {"start": 4, "end": 6.5, "size": 1},
"type": "contour",
"showscale": false,
"xaxis": "x2"
},
{
"x": [0, 1, 2, 3, 10, 30],
"y": [0, 1, 2, 3, 10, 30],
"z": [
[10, 9, 8, 7, 6, 5],
[9, 8, 7, 6, 5, 4],
[8, 7, 6, 5, 4, 3],
[7, 6, 5, 9, 3, 2],
[6, 5, 4, 8, 2, 1],
[5, 4, 3, 2, 1, 0]
],
"contours": {"start": 4, "end": 6.5, "size": 1},
"type": "contour",
"showscale": false,
"yaxis": "y2"
},
{
"x": [0, 1, 2, 3, 10, 30],
"y": [0, 1, 2, 3, 10, 30],
"z": [
[10, 9, 8, 7, 6, 5],
[9, 8, 7, 6, 5, 4],
[8, 7, 6, 5, 4, 3],
[7, 6, 5, 9, 3, 2],
[6, 5, 4, 8, 2, 1],
[5, 4, 3, 2, 1, 0]
],
"contours": {"start": 4, "end": 6.5, "size": 1},
"type": "contour",
"showscale": false,
"xaxis": "x2",
"yaxis": "y2"
}
],
"layout": {
"xaxis": {"domain": [0, 0.45]},
"xaxis2": {"domain": [0.55, 1], "type": "log"},
"yaxis": {"domain": [0, 0.45]},
"yaxis2": {"domain": [0.55, 1], "type": "log"},
"margin": {"l": 50, "b": 50, "r": 110, "t": 10},
"width": 500,
"height": 400
}
}
0