3

I have a plotly graph in a custom Angular component:

<plotly-plot [data]="graph.data" [layout]="graph.layout" (hover)="onHover($event)">
</plotly-plot>

I also have a slider, which I want to use to restyle the plot:

<mat-slider
 thumbLabel
 [displayWith]="formatLabel"
 tickInterval="1000"
 min="0"
 max="7000"
 (input)="getSliderVal($event)">
</mat-slider>

Currently I am registering the slider change events and redrawing whole graph, which is inefficient. I see there is (restyle) prop in the docs but I don't know how to use it. Any help appreciated!

1 Answer 1

6

I think I have foound a way. In plotly.js docs it is specified to use .restyle() in the folowing way:

var update = {
    opacity: 0.4,
    'marker.color': 'red'
};
Plotly.restyle(graphDiv, update, 0);

So if you are using Angular you need to specify the plot div ID via [divId] like this:

<plotly-plot [data]="graph.data" [layout]="graph.layout" (hover)="onHover($event)" [divId]="embeddingsPlotID">

where embeddingsPlotID is specified in your component. Then you can call the .restyle() like this:

PlotlyModule.plotlyjs.restyle("embeddingsPlot",{"marker.size":event.value},0)

from your parent component. Sadly in my case this doesen't seem to be much of a speedup compared to redtawing a whole plot (I have cca. 3k points)

Sign up to request clarification or add additional context in comments.

2 Comments

for [divId]="embeddingsPlotID" , it should be added into parent div where the the traces are plotted ?
One important detail is omitted: component variable this.embeddingsPlotID="embeddingsPlot";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.