rickshaw icon indicating copy to clipboard operation
rickshaw copied to clipboard

Make Charts Scalable/Responsive

Open unclesnottie opened this issue 10 years ago • 10 comments

Currently building a chart in Rickshaw using Rickshaw.Graph.Axis.* creates SVG images but then fixes the height and width in pixels and positions elements using pixels. This means it draws a scalable image and positions it in a non-scalable way. Any time a chart needs to be resized, see Responsive web design, the window resize event must have a handler to redraw the chart using Javascript. This is very inefficient. Pages with multiple charts can bring a browser to it's knees even if you debounce the window resize event handler.

Rickshaw should render the SVG element with a 100% width and height using an appropriate viewBox to establish the proportions. This allows the actual chart size to be controlled in CSS and would not require javascript to resize. If absolutely positioning element is a must, then use percentages rather than pixels so it will scale.

unclesnottie avatar Oct 08 '14 14:10 unclesnottie

+1 We are seeing the same issue and are wondering if this is a pull request that would have a chance of being accepted.

gregz67 avatar Nov 13 '14 15:11 gregz67

I have not seen any pull request for this (though I really haven't looked hard). There are a few problems which I've noticed. As stated before, Rickshaw currently fixes the width and height of the SVG element. The second problem I've noticed is that some of the interactive elements built on top of the SVG are absolutely positioned elements that are aligned with pixels. For this to be fixed and fully responsive, these overlay elements would also have to be positioned differently (probably with % rather than px).

unclesnottie avatar Jan 19 '15 19:01 unclesnottie

+1 to this,

carl0zen avatar Jun 29 '15 19:06 carl0zen

+1 to this

aucontraire avatar Nov 10 '15 18:11 aucontraire

+1

tsareg avatar Nov 13 '15 16:11 tsareg

+1

shlima avatar Dec 11 '15 22:12 shlima

+1

ghost avatar Dec 15 '15 12:12 ghost

bump +1

Mart-Bogdan avatar Dec 27 '15 22:12 Mart-Bogdan

You can put in your own viewBox if needed:

var svg = graph.element.querySelector('svg'),
      w = svg.getAttribute('width'),
      h = svg.getAttribute('height');

  svg.removeAttribute('width');
  svg.removeAttribute('height');

  if(w && h) svg.setAttribute('viewBox', [0, 0, w, h].join(' '));

thure avatar Jul 07 '16 11:07 thure

@thure I don't think the viewBox helps. The issue is not with SVG elements but rather with DOM elements positioned with pixels.

unclesnottie avatar Jul 25 '16 14:07 unclesnottie