Skip to content

Array edits #1403

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 18 commits into from
Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions src/components/images/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ function imageDefaults(imageIn, imageOut, fullLayout) {
if(!visible) return imageOut;

coerce('layer');
coerce('x');
coerce('y');
coerce('xanchor');
coerce('yanchor');
coerce('sizex');
Expand All @@ -51,7 +49,10 @@ function imageDefaults(imageIn, imageOut, fullLayout) {

for(var i = 0; i < 2; i++) {
// 'paper' is the fallback axref
Axes.coerceRef(imageIn, imageOut, gdMock, axLetters[i], 'paper');
var axLetter = axLetters[i],
axRef = Axes.coerceRef(imageIn, imageOut, gdMock, axLetter, 'paper');

Axes.coercePosition(imageOut, gdMock, coerce, axRef, axLetter, 0);
}

return imageOut;
Expand Down
2 changes: 1 addition & 1 deletion src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ Plotly.plot = function(gd, data, layout, config) {
// calc and autorange for errorbars
ErrorBars.calc(gd);

// TODO: autosize extra for text markers
// TODO: autosize extra for text markers and images
Copy link
Contributor

Choose a reason for hiding this comment

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

There's actually an issue for that one #1111

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah thanks - comment-linked in 46962af

return Lib.syncOrAsync([
Registry.getComponentMethod('shapes', 'calcAutorange'),
Registry.getComponentMethod('annotations', 'calcAutorange'),
Expand Down
15 changes: 15 additions & 0 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -1911,6 +1911,8 @@ plots.doCalcdata = function(gd, traces) {

var trace, _module, i, j;

var hasCategoryAxis = false;

// XXX: Is this correct? Needs a closer look so that *some* traces can be recomputed without
// *all* needing doCalcdata:
var calcdata = new Array(fullData.length);
Expand All @@ -1936,6 +1938,7 @@ plots.doCalcdata = function(gd, traces) {
// to be filled in later by ax.d2c
for(i = 0; i < axList.length; i++) {
axList[i]._categories = axList[i]._initialCategories.slice();
if(axList[i].type === 'category') hasCategoryAxis = true;
}

// If traces were specified and this trace was not included,
Expand Down Expand Up @@ -2012,6 +2015,18 @@ plots.doCalcdata = function(gd, traces) {

calcdata[i] = cd;
}

// To handle the case of components using category names as coordinates, we
// need to re-supply defaults for these objects now, after calc has
// finished populating the category mappings
// Any component that uses `Axes.coercePosition` falls into this category
if(hasCategoryAxis) {
var dataReferencedComponents = ['annotations', 'shapes', 'images'];
for(i = 0; i < dataReferencedComponents.length; i++) {
Registry.getComponentMethod(dataReferencedComponents[i], 'supplyLayoutDefaults')(
gd.layout, fullLayout, fullData);
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suppose I could list these components somehow in the registry... worth it or overkill?

BTW you'll see I added category-name coordinates to image and shape test images, annotations didn't need this because 16.json already has it, and that's the failing test that prompted this fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's leave it like that for now. We could always add that list to the registry down the road if it comes up somewhere else. 👍

};

plots.rehover = function(gd) {
Expand Down
Binary file modified test/image/baselines/layout_image.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/shapes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/image/mocks/layout_image.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"data": [
{
"x": [1,2,3],
"y": [1,2,3]
"y": ["a", "b", "c"]
}, {
"x": ["2001-01-01","2002-01-01","2003-01-01"],
"y": [10,100,1000],
Expand Down Expand Up @@ -38,7 +38,7 @@
"xref": "x",
"yref": "y",
"x": 1.5,
"y": 2,
"y": "b",
"sizex": 1,
"sizey": 1,
"xanchor": "right",
Expand Down
1 change: 1 addition & 0 deletions test/image/mocks/shapes.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{"path":"M0.5,3C0.5,9 0.9,9 0.9,3C0.9,1 0.5,1 0.5,3ZM0.6,4C0.6,5 0.66,5 0.66,4ZM0.74,4C0.74,5 0.8,5 0.8,4ZM0.6,3C0.63,2 0.77,2 0.8,3Z","fillcolor":"#fd2","line":{"width":1,"color":"black"}},
{"layer":"below","xref":"x2","yref":"y2","type":"circle","x0":"2000-01-01 02","x1":"2000-01-01 08:30:33.456","y0":0.1,"y1":0.9,"fillcolor":"rgba(0,0,0,0.5)","line":{"color":"rgba(0,255,0,0.5)", "width":5}},
{"xref":"x2","yref":"y2","path":"M2000-01-01_11:20:45.6,0.2Q2000-01-01_10:00,0.85 2000-01-01_21,0.8Q2000-01-01_22:20,0.15 2000-01-01_11:20:45.6,0.2Z","fillcolor":"rgb(151,73,58)"},
{"xref":"x2","yref":"y2","type":"line","x0":"2000-01-01 11:00","x1":"2000-01-01 09:00","y0":"b","y1":"a","line":{"color":"#006","width":3}},
{"yref":"paper","type":"line","x0":0.1,"x1":0.4,"y0":0,"y1":0.4,"line":{"color":"#009","dash":"dot","width":1}},
{"yref":"paper","path":"M0.5,0H1.1L0.8,0.4Z","line":{"width":0},"fillcolor":"#ccd3ff"},
{"xref":"paper","x0":0.1,"x1":0.2,"y0":-1,"y1":3,"fillcolor":"#ccc"},
Expand Down