question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

redraw() doesn't respect changes in containing div's size.

See original GitHub issue

I set a listener for window resize events. When fired I call redraw() in my google-chart, as I want my chart to be responsive. to make my chart match the width of it’s containing div when redrawn I have the following css:

google-chart {
    width: 100%;
}

This works when starting from a small width and getting bigger. The window resizes and the graph is redraw with the appropriate width. However when going from big to small, it will not redraw smaller to what the new 100% if containing div is, so I end up with an overflow of the containing div.

This is very strange behavior and I can only assume it’s a bug as the redraw is getting called and it will redraw it larger than current but not smaller.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jukbotcommented, Jan 12, 2018

For my workaround in Polymer, I’m using iron-resize behavior to detect the size of the chart container.

 class ViewStatistic extends Polymer.mixinBehaviors([Polymer.IronResizableBehavior],
      Polymer.Element) {
      static get is() {
        return 'view-statistic';
      }

   connectedCallback() {
        super.connectedCallback();
        requestAnimationFrame(this._installListeners.bind(this))
      }

      _installListeners() {
         this.addEventListener('iron-resize', this._setChartSize.bind(this))
      }
    
      _setChartSize() {
        this.width = this.$.chartContainer.offsetWidth;
        this.height = this.$.chartContainer.offsetHeight;
        if (this.width > 0) {
          this.columnOptions = {
            width: this.width - 40,
            height: 500,
          }
          this.$.columnChart.redraw()
        }
      }
}
  customElements.define(ViewDashboardStatistic.is, ViewDashboardStatistic);
0reactions
rslawikcommented, Apr 15, 2021

Great that you have solved it. I will close this issue then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not respecting parent size · Issue #2422 · chartjs/Chart.js
I solved it by setting maintainAspectRatio to false in the options section, in addition to changing the size of the parent div ....
Read more >
Set width of a "Position: fixed" div relative to parent div
Any idea how to solve this if #container width is 50% inside a div with width = 100px (then container width would be...
Read more >
CSS- Div- Be Careful When You Size Your Divs
Fortunately, it's easy to fix - although this is an Explorer-only solution! Place both DIVs into a container DIV that's set to 100%...
Read more >
Animating CSS Width And Height Without The Squish Effect
In the transform example the radius is not redrawn (like in the width example), it is simply scaled. Redrawing would require a repaint,...
Read more >
Plot sizing problems - plotly.js
With autosize not set, the width of the containing div is correctly consumed, but how the height is derived isn't clear. Setting autosize:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found