danielkrizian / rChartsDygraphs

An `rCharts` extension. Run `dygraphs` from R - interactive visualizations of time series using JavaScript and HTML canvas. See: http://dygraphs.com/ and
http://rcharts.io/
9 stars 10 forks source link

Decimal Point Precision #14

Open TonyDIRL opened 10 years ago

TonyDIRL commented 10 years ago

Perhaps I'm missing something obvious but I can't get beyond two decimal points of precision on y-axis variables.

getSymbols("SPY", from = "2014-01-01")
mychart=dygraph(SPY$SPY.Open+0.0025)
mychart$setOpts(drawPoints=TRUE,digitsAfterDecimal= 5,yaxisLabelWidth= 5)
mychart

The relevant dygraph parameters are digitsAfterDecimal, yaxisLabelWidth and a custom yaxisLabelFormatter function as can be seen in this jsfiddle: http://jsfiddle.net/TonyDIRL/fGZ2D/

Reviewing the generated source from the above R code shows

..."SPY.Open": [ 183.98, 183.23,

I've walked through the parseData function within the library but I can't see where the explicit rounding occurs.

Please advise.

danielkrizian commented 10 years ago

good catch! The unintended, explicit rounding happens in RJSONIO::toJSON, which is still part of rCharts I guess, @ramnathv ? (fyi @timelyportfolio )

str(mychart) # explore object components
mychart$params$data # no explicit rounding here
#                                      t SPY.Open
# 2014-01-02 #!new Date(1388620800000)!# 183.9825
# 2014-01-03 #!new Date(1388707200000)!# 183.2325

RJSONIO::toJSON(mychart$params$data) # it happens here dammit!
# ... \n\"SPY.Open\": [ 183.98, 183.23, 183.49 ...
timelyportfolio commented 10 years ago

This might help https://github.com/ramnathv/rCharts/issues/248 . I will confirm when I get on a computer.

TonyDIRL commented 10 years ago

After reading around the issue and some tickering I believe the digits parameter of toJSON

toJSON(num, digits = 10)

will solve the issue. @danielkrizian would you consider making 'digits' a parameter within the dygraph() call facilitating more flexibility for the user?

danielkrizian commented 10 years ago

Hi @TonyDIRL , Dygraph class does not even call toJSON directly. Ability to add digits as a parameter of toJSON and the function call itself is down in the rCharts class in Ramnath's package, which Dygraph class inherits from. I 've created a pull request for @ramnathv to review: https://github.com/ramnathv/rCharts/pull/449. If my guess is correct, I will add inside the dygraph constructor the following code: Dygraph$addParams(digits=digits). Guys let me know if you have a better idea.

TonyDIRL commented 10 years ago

Thank you