vue-plotly icon indicating copy to clipboard operation
vue-plotly copied to clipboard

autoResize not working

Open kjschiroo opened this issue 5 years ago • 8 comments

autoResize doesn't appear to be working, and it looks like it might be a two part issue.

In this commit the code went from using the function generated by debounce as the event listener, to accidentally throwing that function away. The result here is that this.react never ends up getting called because the generated debouncing function never got called.

I would suspect that this snippet would fix that aspect of the problem

this.__resizeListener = debounce(() => {
  this.internalLayout.datarevision++
  this.react()
}, 200)

however javascript isn't my strongest language.

The second part of it is that even once this change is made and react gets called, it still doesn't appear to successfully resize the image. I haven't ruled out that just being part of my specific setup though. Thoughts?

kjschiroo avatar May 30 '19 21:05 kjschiroo

Falling back to 0.2.0 does work in my setup.

kjschiroo avatar May 30 '19 21:05 kjschiroo

I had some issues regarding the responsiveness, this works for me on latest:

options: {
            responsive: true,
          }

spacemudd avatar Jul 28 '19 13:07 spacemudd

autoResize doesn't appear to be working, and it looks like it might be a two part issue.

In this commit the code went from using the function generated by debounce as the event listener, to accidentally throwing that function away. The result here is that this.react never ends up getting called because the generated debouncing function never got called.

I would suspect that this snippet would fix that aspect of the problem

this.__resizeListener = debounce(() => {
  this.internalLayout.datarevision++
  this.react()
}, 200)

however javascript isn't my strongest language.

The second part of it is that even once this change is made and react gets called, it still doesn't appear to successfully resize the image. I haven't ruled out that just being part of my specific setup though. Thoughts?

This in conjunction with layout: {autosize:true} fixed everything for me

glorat avatar Jan 09 '20 09:01 glorat

autoResize doesn't appear to be working, and it looks like it might be a two part issue. In this commit the code went from using the function generated by debounce as the event listener, to accidentally throwing that function away. The result here is that this.react never ends up getting called because the generated debouncing function never got called. I would suspect that this snippet would fix that aspect of the problem

this.__resizeListener = debounce(() => {
  this.internalLayout.datarevision++
  this.react()
}, 200)

however javascript isn't my strongest language. The second part of it is that even once this change is made and react gets called, it still doesn't appear to successfully resize the image. I haven't ruled out that just being part of my specific setup though. Thoughts?

This in conjunction with layout: {autosize:true} fixed everything for me

I am using this with Vuetify and the following code is resizing is working; options: { responsive: true }.

ghost avatar Jan 09 '20 13:01 ghost

@JLBlueDom that doesn't have effect for me. I suspect the difference is that you're putting the graph in a responsive layout (e.g. Vuetify/Bootstrap) whereas I'm using old school fixed container sizes.

Either way, if you agree this snippet is required, I'll create a fork and PR

glorat avatar Jan 10 '20 01:01 glorat

@JLBlueDom that doesn't have effect for me. I suspect the difference is that you're putting the graph in a responsive layout (e.g. Vuetify/Bootstrap) whereas I'm using old school fixed container sizes.

Either way, if you agree this snippet is required, I'll create a fork and PR

Your suspicion may be correct. All I really know is it works perfectly in Vuetify. :)

ghost avatar Jan 10 '20 13:01 ghost

I use css-element-queries for this and it works smoothly with good performance

import ReziseSensor from "css-element-queries/src/ResizeSensor";
//....
mounted() {
 new ReziseSensor(this.$el, () => {
   this.$refs.plotly.relayout({
      width: this.$el.clientWidth,
      height: this.$el.parentElement.clientHeight
    })
  })
}

Tehsurfer avatar Feb 04 '20 01:02 Tehsurfer

@kjschiroo the solution is relatively simple. Wherever you make you component, on the component itself set:

<Plotly :autoResize="true"/>

See: https://github.com/statnett/vue-plotly/issues/27 for more details as to why.

SumNeuron avatar Feb 13 '20 10:02 SumNeuron