Skip to content

Commit 7ed9eb9

Browse files
committed
fix for components using category names as coordinates
1 parent d7cdc0a commit 7ed9eb9

File tree

7 files changed

+23
-6
lines changed

7 files changed

+23
-6
lines changed

src/components/images/defaults.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ function imageDefaults(imageIn, imageOut, fullLayout) {
3737
if(!visible) return imageOut;
3838

3939
coerce('layer');
40-
coerce('x');
41-
coerce('y');
4240
coerce('xanchor');
4341
coerce('yanchor');
4442
coerce('sizex');
@@ -51,7 +49,10 @@ function imageDefaults(imageIn, imageOut, fullLayout) {
5149

5250
for(var i = 0; i < 2; i++) {
5351
// 'paper' is the fallback axref
54-
Axes.coerceRef(imageIn, imageOut, gdMock, axLetters[i], 'paper');
52+
var axLetter = axLetters[i],
53+
axRef = Axes.coerceRef(imageIn, imageOut, gdMock, axLetter, 'paper');
54+
55+
Axes.coercePosition(imageOut, gdMock, coerce, axRef, axLetter, 0);
5556
}
5657

5758
return imageOut;

src/plot_api/plot_api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ Plotly.plot = function(gd, data, layout, config) {
251251
// calc and autorange for errorbars
252252
ErrorBars.calc(gd);
253253

254-
// TODO: autosize extra for text markers
254+
// TODO: autosize extra for text markers and images
255255
return Lib.syncOrAsync([
256256
Registry.getComponentMethod('shapes', 'calcAutorange'),
257257
Registry.getComponentMethod('annotations', 'calcAutorange'),

src/plots/plots.js

+15
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,8 @@ plots.doCalcdata = function(gd, traces) {
19111911

19121912
var trace, _module, i, j;
19131913

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

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

20132016
calcdata[i] = cd;
20142017
}
2018+
2019+
// To handle the case of components using category names as coordinates, we
2020+
// need to re-supply defaults for these objects now, after calc has
2021+
// finished populating the category mappings
2022+
// Any component that uses `Axes.coercePosition` falls into this category
2023+
if(hasCategoryAxis) {
2024+
var dataReferencedComponents = ['annotations', 'shapes', 'images'];
2025+
for(i = 0; i < dataReferencedComponents.length; i++) {
2026+
Registry.getComponentMethod(dataReferencedComponents[i], 'supplyLayoutDefaults')(
2027+
gd.layout, fullLayout, fullData);
2028+
}
2029+
}
20152030
};
20162031

20172032
plots.rehover = function(gd) {

test/image/baselines/layout_image.png

-635 Bytes
Loading

test/image/baselines/shapes.png

1.68 KB
Loading

test/image/mocks/layout_image.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"data": [
33
{
44
"x": [1,2,3],
5-
"y": [1,2,3]
5+
"y": ["a", "b", "c"]
66
}, {
77
"x": ["2001-01-01","2002-01-01","2003-01-01"],
88
"y": [10,100,1000],
@@ -38,7 +38,7 @@
3838
"xref": "x",
3939
"yref": "y",
4040
"x": 1.5,
41-
"y": 2,
41+
"y": "b",
4242
"sizex": 1,
4343
"sizey": 1,
4444
"xanchor": "right",

test/image/mocks/shapes.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
{"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"}},
3030
{"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}},
3131
{"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)"},
32+
{"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}},
3233
{"yref":"paper","type":"line","x0":0.1,"x1":0.4,"y0":0,"y1":0.4,"line":{"color":"#009","dash":"dot","width":1}},
3334
{"yref":"paper","path":"M0.5,0H1.1L0.8,0.4Z","line":{"width":0},"fillcolor":"#ccd3ff"},
3435
{"xref":"paper","x0":0.1,"x1":0.2,"y0":-1,"y1":3,"fillcolor":"#ccc"},

0 commit comments

Comments
 (0)