I am also adding a legend using annotations that is not associated to any point. All annotations are using the setting draggable: 'xy'.
Everything looks and works perfectly in the UI. But I am trying to do a export of the map via chart.getSVG(). All the annotations are in their proper spots. However, whenever I drag any annotation and export, the exported image shows the map point annotations in their original positions.
For my legend, I used shapes to create boxes around the text and it shows the shapes moved, but the text inside remains in the initial position. What is the proper way to export the map with the annotations in their newly placed positions?
Here is the code I use to add the legend at the least:
Code: Select all
function generateLegend(region) {
window[`${region}Map`].addAnnotation({
id: `${region}legend`,
draggable: 'xy',
labelOptions: {
allowOverlap: true,
backgroundColor: null,
borderWidth: 0,
padding: 10,
},
labels: [
{
point: {
x: window.regionValStore[region]['legendParams']['x'],
y: window.regionValStore[region]['legendParams']['y'],
},
text: `
<svg width="300" height="200">
<text x="8%" y="30" fill="black" style="text-align:center; text-decoration:underline;">
Legend
</text>
<text x="10%" y="40" fill="black" text-anchor="middle">
<tspan x="10%" dy="1.5em" style="font-weight:bold; margin:2px;">
TOTAL COUNT
</tspan>
<tspan x="10%" dy="1.5em" style="font-weight:bold; margin:2px;">
ITEM CODE
</tspan>
<tspan x="10%" dy="1.5em" style="font-weight:bold; margin:2px;">
ITEM UNIT
</tspan>
</text>
<text x="10" y="100" fill="black" style="border:solid black 1px; background-color:#8895bd;">
<tspan x="10" dy="1.5em" style="font-weight:bold; color:#ce0000; margin:2px;">
Red font = changes
</tspan>
<tspan x="10" dy="1.5em" style="font-weight:bold; color:#ce0000; margin:2px;">
previous year
</tspan>
</text>
<text x="10" y="140" fill="black" style="border:solid black 1px; background-color:#8895bd;">
<tspan x="10" dy="1.5em" style="font-weight:bold; background-color:yellow; margin:2px;">
Yellow Highlight = Pre-decisional
</tspan>
<tspan x="10" dy="1.5em" style="font-weight:bold; background-color:yellow; margin:2px;">
Inventory Changes
</tspan>
</text>
</svg>
`,
style: {
color: '#000000',
fontSize: '12px',
},
},
],
shapes: [
{
type: 'rect',
points: [{
x: window.regionValStore[region]['legendParams']['x'] - 102,
y: window.regionValStore[region]['legendParams']['y'] - 155,
}],
stroke: 'black',
strokeWidth: 1,
fill: 'none',
width: 200,
height: 60,
}, {
type: 'rect',
points: [{
x: window.regionValStore[region]['legendParams']['x'] - 102,
y: window.regionValStore[region]['legendParams']['y'] - 95,
}],
stroke: 'black',
strokeWidth: 1,
fill: 'none',
width: 200,
height: 43,
}, {
type: 'rect',
points: [{
x: window.regionValStore[region]['legendParams']['x'] - 102,
y: window.regionValStore[region]['legendParams']['y'] - 52,
}],
stroke: 'black',
strokeWidth: 1,
fill: 'yellow',
width: 200,
height: 45,
},
],
events: {
drag: function(event) {
console.log('dragged');
annotation.update({
x: event.chartX,
y: event.chartY
});
}
}
});
}