Raster perserveAspectRatio? #2286
-
how to config the I have to do something like this to post-process the plot, wonder if there is a better way to handle it. if (mapPlot && "querySelectorAll" in mapPlot) {
const rasters = mapPlot.querySelectorAll<SVGImageElement>(
'g[aria-label="raster"]>image'
);
rasters.forEach((r) => {
r.setAttribute("preserveAspectRatio", "xMidYMid meet");
});
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Sounds interesting. Can you give a concrete example of what you're trying to achieve? |
Beta Was this translation helpful? Give feedback.
-
Removing (or altering) the Instead, I recommend you use Plot’s aspectRatio option, and set it to 1 if you want the data to be displayed in a square aspect ratio (as with equirectangular coordinates). This option will then compute an appropriate default height for the plot. Plot.plot({
color: {
scheme: "BuGn",
legend: true
},
aspectRatio: 1,
marks: [
Plot.raster(data, {
width: 135,
height: 231,
x1: 93.835,
x2: 108.82,
y1: 34.053,
y2: 8.411999999999999,
interpolate: "none"
})
]
}) If you want a smaller plot, you can set the width attribute to something smaller; it defaults to 640. |
Beta Was this translation helpful? Give feedback.
-
If this is a map of some sort, with x and y representing planar coordinates, you could use a projection of type "identity", or "reflect-y": Plot.plot({
color: {
scheme: "BuGn",
legend: true
},
width: 200,
projection: {
type: "identity",
domain: {
type: "MultiPoint",
coordinates: [
[93.835, 34.053],
[108.82, 8.411999999999999]
]
}
},
marks: [
Plot.raster(data, {
width: 135,
height: 231,
x1: 93.835,
x2: 108.82,
y1: 34.053,
y2: 8.411999999999999,
interpolate: "none"
})
]
}) |
Beta Was this translation helpful? Give feedback.
Removing (or altering) the
preserveAspectRatio
attribute will mean that the raster data will not align with the position scales (Plot’s coordinate system). So, I don’t think you want to do that; or if you do, you want to suppress the x-axis so that it’s not misleading.Instead, I recommend you use Plot’s aspectRatio option, and set it to 1 if you want the data to be displayed in a square aspect ratio (as with equirectangular coordinates). This option will then compute an appropriate default height for the plot.