Skip to content

Commit a29ce33

Browse files
committed
fix images on date axes, and standardize axis object names
1 parent f629f71 commit a29ce33

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

src/components/images/draw.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ module.exports = function draw(gd) {
101101
var thisImage = d3.select(this);
102102

103103
// Axes if specified
104-
var xref = Axes.getFromId(gd, d.xref),
105-
yref = Axes.getFromId(gd, d.yref);
104+
var xa = Axes.getFromId(gd, d.xref),
105+
ya = Axes.getFromId(gd, d.yref);
106106

107107
var size = fullLayout._size,
108-
width = xref ? Math.abs(xref.l2p(d.sizex) - xref.l2p(0)) : d.sizex * size.w,
109-
height = yref ? Math.abs(yref.l2p(d.sizey) - yref.l2p(0)) : d.sizey * size.h;
108+
width = xa ? Math.abs(xa.l2p(d.sizex) - xa.l2p(0)) : d.sizex * size.w,
109+
height = ya ? Math.abs(ya.l2p(d.sizey) - ya.l2p(0)) : d.sizey * size.h;
110110

111111
// Offsets for anchor positioning
112112
var xOffset = width * anchors.x[d.xanchor].offset,
@@ -115,8 +115,8 @@ module.exports = function draw(gd) {
115115
var sizing = anchors.x[d.xanchor].sizing + anchors.y[d.yanchor].sizing;
116116

117117
// Final positions
118-
var xPos = (xref ? xref.l2p(d.x) + xref._offset : d.x * size.w + size.l) + xOffset,
119-
yPos = (yref ? yref.l2p(d.y) + yref._offset : size.h - d.y * size.h + size.t) + yOffset;
118+
var xPos = (xa ? xa.l2p(xa.r2l(d.x)) + xa._offset : d.x * size.w + size.l) + xOffset,
119+
yPos = (ya ? ya.l2p(ya.r2l(d.y)) + ya._offset : size.h - d.y * size.h + size.t) + yOffset;
120120

121121

122122
// Construct the proper aspectRatio attribute
@@ -141,8 +141,8 @@ module.exports = function draw(gd) {
141141

142142

143143
// Set proper clipping on images
144-
var xId = xref ? xref._id : '',
145-
yId = yref ? yref._id : '',
144+
var xId = xa ? xa._id : '',
145+
yId = ya ? ya._id : '',
146146
clipAxes = xId + yId;
147147

148148
if(clipAxes) {

test/image/baselines/layout_image.png

371 Bytes
Loading

test/image/mocks/layout_image.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
44
"x": [1,2,3],
55
"y": [1,2,3]
66
}, {
7-
"x": [1,2,3],
8-
"y": [1,2,3],
7+
"x": ["2001-01-01","2002-01-01","2003-01-01"],
8+
"y": [10,100,1000],
9+
"xaxis": "x2",
910
"yaxis": "y2"
1011
}
1112
],
1213
"layout": {
14+
"xaxis2": {
15+
"anchor": "y2"
16+
},
1317
"yaxis": {
14-
"domain": [0, 0.5]
18+
"domain": [0, 0.45]
1519
},
1620
"yaxis2": {
17-
"domain": [0.5, 1]
21+
"domain": [0.55, 1],
22+
"type": "log"
1823
},
1924
"images": [
2025
{
@@ -41,11 +46,11 @@
4146
},
4247
{
4348
"source": "https://images.plot.ly/language-icons/api-home/r-logo.png",
44-
"xref": "x",
49+
"xref": "x2",
4550
"yref": "y2",
46-
"x": 1,
51+
"x": "2001-01-01",
4752
"y": 3,
48-
"sizex": 2,
53+
"sizex": 63072000000,
4954
"sizey": 2,
5055
"sizing": "stretch",
5156
"opacity": 0.4,

0 commit comments

Comments
 (0)