Skip to content

Commit 35a0001

Browse files
committed
Fix shape labels for multi-axis references and add labels to mock
1 parent 7645c40 commit 35a0001

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

src/components/shapes/display_labels.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,27 @@ module.exports = function drawLabel(gd, index, options, shapeGroup) {
8282
} else {
8383
// Otherwise, we use the x and y bounds defined in the shape options
8484
// and convert them to pixel coordinates
85-
// Setup conversion functions
86-
var xa = Axes.getFromId(gd, options.xref);
87-
var xShiftStart = options.x0shift;
88-
var xShiftEnd = options.x1shift;
89-
var xRefType = Axes.getRefType(options.xref);
90-
var ya = Axes.getFromId(gd, options.yref);
91-
var yShiftStart = options.y0shift;
92-
var yShiftEnd = options.y1shift;
93-
var yRefType = Axes.getRefType(options.yref);
94-
var x2p = function (v, shift) {
95-
var dataToPixel = helpers.getDataToPixel(gd, xa, shift, false, xRefType);
96-
return dataToPixel(v);
85+
// Setup conversion functions, handling array refs for multi-axis shapes
86+
var isArrayXref = Array.isArray(options.xref);
87+
var isArrayYref = Array.isArray(options.yref);
88+
var xa0 = Axes.getFromId(gd, isArrayXref ? options.xref[0] : options.xref);
89+
var xa1 = Axes.getFromId(gd, isArrayXref ? options.xref[1] : options.xref);
90+
var ya0 = Axes.getFromId(gd, isArrayYref ? options.yref[0] : options.yref);
91+
var ya1 = Axes.getFromId(gd, isArrayYref ? options.yref[1] : options.yref);
92+
var xRefType0 = Axes.getRefType(isArrayXref ? options.xref[0] : options.xref);
93+
var xRefType1 = Axes.getRefType(isArrayXref ? options.xref[1] : options.xref);
94+
var yRefType0 = Axes.getRefType(isArrayYref ? options.yref[0] : options.yref);
95+
var yRefType1 = Axes.getRefType(isArrayYref ? options.yref[1] : options.yref);
96+
var x2p = function(v, shift, xa, xRefType) {
97+
return helpers.getDataToPixel(gd, xa, shift, false, xRefType)(v);
9798
};
98-
var y2p = function (v, shift) {
99-
var dataToPixel = helpers.getDataToPixel(gd, ya, shift, true, yRefType);
100-
return dataToPixel(v);
99+
var y2p = function(v, shift, ya, yRefType) {
100+
return helpers.getDataToPixel(gd, ya, shift, true, yRefType)(v);
101101
};
102-
shapex0 = x2p(options.x0, xShiftStart);
103-
shapex1 = x2p(options.x1, xShiftEnd);
104-
shapey0 = y2p(options.y0, yShiftStart);
105-
shapey1 = y2p(options.y1, yShiftEnd);
102+
shapex0 = x2p(options.x0, options.x0shift, xa0, xRefType0);
103+
shapex1 = x2p(options.x1, options.x1shift, xa1, xRefType1);
104+
shapey0 = y2p(options.y0, options.y0shift, ya0, yRefType0);
105+
shapey1 = y2p(options.y1, options.y1shift, ya1, yRefType1);
106106
}
107107

108108
// Handle `auto` angle

test/image/mocks/multi_axis_shapes.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"y0": 5,
2525
"y1": 2,
2626
"fillcolor": "rgba(255, 0, 0, 0.3)",
27-
"line": { "color": "red", "width": 2 }
27+
"line": { "color": "red", "width": 2 },
28+
"label": { "text": "rect" }
2829
},
2930
{
3031
"type": "circle",
@@ -35,7 +36,8 @@
3536
"y0": 0,
3637
"y1": 5,
3738
"fillcolor": "rgba(0, 0, 255, 0.3)",
38-
"line": { "color": "blue", "width": 2 }
39+
"line": { "color": "blue", "width": 2 },
40+
"label": { "text": "circle" }
3941
},
4042
{
4143
"type": "line",
@@ -45,15 +47,17 @@
4547
"x1": 4,
4648
"y0": 0.5,
4749
"y1": 4,
48-
"line": { "color": "green", "width": 3 }
50+
"line": { "color": "green", "width": 3 },
51+
"label": { "text": "line" }
4952
},
5053
{
5154
"type": "path",
5255
"xref": ["x2", "x2", "x4", "x4"],
5356
"yref": ["y2", "y2", "y4", "y4"],
5457
"path": "M0.5,0.5 L5,0.5 L4,4 L0.5,4 Z",
5558
"fillcolor": "rgba(255, 165, 0, 0.3)",
56-
"line": { "color": "orange", "width": 2 }
59+
"line": { "color": "orange", "width": 2 },
60+
"label": { "text": "path" }
5761
}
5862
]
5963
}

0 commit comments

Comments
 (0)