hrbrmstr / metricsgraphics

:chart_with_upwards_trend: htmlwidget interface to the MetricsGraphics.js D3 chart library
http://hrbrmstr.github.io/metricsgraphics/
Other
132 stars 35 forks source link

dynamic sizing/resizing behavior #1

Closed jjallaire closed 9 years ago

jjallaire commented 9 years ago

This set of changes implements automatic sizing/resizing for metrics graphics widgets. This means that they will always size themselves to the dimensions of their container (e.g. the Viewer pane in RStudio, a standalone browser window, the correct knitr figure size, or the size allocated by metricsgraphicsOutput in Shiny). This is preferable to a hard-coded approach because it removes the burden from the user of writing code to get the size just right for whatever context they are using the widget in (note that users can always pass an explicit width and height to override this behavior). The article on widget sizing is worth a read for additional context: http://www.htmlwidgets.org/develop_sizing.html

Note that one related change is the elimination of the title and description attributes. The problem they cause for metricsgraphics is that they aren't factored into the size of the graph, so when you pass width and height of the container (e.g. knitr figure size) the space allocated to the title is in addition to the graph (so the bottom of the graph is clipped off). This could probably be overcome by doing some dynamic DOM text measurement but that's pretty hairy so not attempted here. My view is that the convenience of automatic sizing outweighs the nicety of having a title (and there are other ways to get titles commonly used such as text headers in Rmd or Shiny, slide headers in presentations, etc.)

timelyportfolio commented 9 years ago

@ramnathv just wanted to make sure you saw this; know you had initially sketched out a metrics widget, and also know metrics has changed quite a bit since then

hrbrmstr commented 9 years ago

I think I'd have to agree on this (esp as for use in an R context). The mozilla folks definitely seem to have planned for these charts to be in a Bootstrap context (which makes the layout easier and does the description on hover as y'all prbly know already). As an aside, i noticed that knitting an Rmd with (at least these charts) shows up fine in the RStudio viewer, Safari & Firefox, but Chrome tosses errors. Do you see that with any of the other htmlwidgets?

timelyportfolio commented 9 years ago

The Bootstrap and jquery dependencies are being discussed (without resolution as far as I can tell) here in this issue https://github.com/mozilla/metrics-graphics/issues/132.

Also, as @ramnathv and I are working on the next iteration of rCharts, we are dealing with these same issues with titles, axis labels, captions, etc. especially since most of the charting libraries do not support these well. I think it would be ideal to decide on a consistent structure/interface for these.

jjallaire commented 9 years ago

The chrome issue was due to using a non-minified version of ds.js. I've updated to prevent this.

jjallaire commented 9 years ago

There is a merge conflict introduced by a recent commit, I'll resolve this and let you know when things are good to go

hrbrmstr commented 9 years ago

You, sir, are a machine. I was thinking it might be the unminified js libs. Thx again. I'll hopefully be wrapping a few other libs we use a bit at work.

jjallaire commented 9 years ago

Okay, I've fixed the merge conflicts so should be good to go