statnett / vue-plotly

A vue wrapper for plotly.js chart library
MIT License
119 stars 28 forks source link

autoResize not working #20

Open kjschiroo opened 5 years ago

kjschiroo commented 5 years ago

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 commented 5 years ago

Falling back to 0.2.0 does work in my setup.

spacemudd commented 5 years ago

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

options: {
            responsive: true,
          }
glorat commented 4 years ago

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

ghost commented 4 years ago

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 }.

glorat commented 4 years ago

@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

ghost commented 4 years ago

@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. :)

Tehsurfer commented 4 years ago

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
    })
  })
}
SumNeuron commented 4 years ago

@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.