Hello! Very very new to js, I was wondering if plotly.animate or any other ways to animate work in svelte with script.onload ?
With Svelte I’ve tried onMount() and inside that script.onload, it loads my graph but (even though the frames are right) the animation side of things doesn’t work.
Here’s my code starting from the treemap data I tried plotly.animate but it didn’t do anything so I took it out
<script>
tm_data = { // treemap data
type: "treemap",
labels: tx_list,
parents: block_root,
marker: {colorscale: 'Greens'}
};
frames.push(tm_data)
if (frame0 == null) { // the very first frame to show
frame0 = tm_data;
}
}
// --------ANIMATION---------------
var sliderSteps = [];
for (let i = 0; i < block_range; i++){
sliderSteps.push({
method: 'animate',
label: frames[i],
args: [[frames[i]], {
frame: { duration: duration, redraw: false },
transition: { duration: duration },
mode: "immediate",
}]
});
}
var layout = {
'title': "Animation of bitcoin blocks",
updatemenus: [{
bordercolor: '#2E8B57',
buttons: [{
method: 'animate',
args: [null, {frame: {duration: duration, redraw: false}, fromcurrent: true, transition: {duration: duration}, mode: 'immediate'}],
label: 'Play'
}],
direction: 'left',
pad: {'r': 10, 't': 10},
showactive: false,
type: 'buttons',
x: 0.1,
xanchor: 'right',
y: 0,
yanchor: 'top'
}],
type: 'buttons',
buttons: [{
method: 'animate',
args: [null, {
frame: {duration: duration, redraw: false},
mode: 'immediate',
fromcurrent: true,
transition: {duration: duration},
}],
label: 'Play'
}, {
method: 'animate',
args: [[null], {
mode: 'immediate',
transition: {duration: 0},
frame: {duration: 0, redraw: false}
}],
label: 'Pause'
}],
sliders: [{
active: 0,
steps: sliderSteps,
x:0,
y:0,
len:0.9,
xanchor: 'left',
yanchor: 'top',
pad: {'t': 50, 'b': 10},
currentvalue: {
visible: true,
prefix: 'Block:',
xanchor: 'right',
font: {size: 20, color: '#666'}
},
transition: {duration: duration},
}]
};
onMount(() => { // i think this is called at the end when it's compiling everything
let script = document.createElement('script');
script.src = "https://cdn.plot.ly/plotly-latest.min.js"
document.head.append(script);
script.onload = function() {
Plotly.newPlot('myDiv', {data:frames, layout:layout, frames: frames})
};
});
</script>
Also going to try out svelte-kit sometime today…
Thanks!