Skip to content

Commit 408bebc

Browse files
start to add dimple based on nvd3
1 parent 724999e commit 408bebc

File tree

9 files changed

+12508
-1
lines changed

9 files changed

+12508
-1
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Collate:
2020
'utils-rickshaw.R'
2121
'rChartsClass.R'
2222
'Datatables.R'
23+
'Dimple.R'
2324
'Polycharts.R'
2425
'Morris.R'
2526
'Nvd3.R'
@@ -34,4 +35,4 @@ Collate:
3435
'Highcharts.R'
3536
'Vega.R'
3637
'Leaflet.R'
37-
38+

R/Dimple.R

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
dPlot <- dimplePlot <- function(x, data, ...){
2+
myChart <- Dimple$new()
3+
myChart$getChartParams(x, data, ...)
4+
return(myChart$copy())
5+
}
6+
7+
Dimple <- setRefClass('Dimple', contains = 'rCharts', methods = list(
8+
initialize = function(){
9+
callSuper();
10+
params <<- c(params, list(
11+
chart = list(), xAxis = list(), x2Axis = list(), yAxis = list()
12+
))
13+
},
14+
chart = function(..., replace = F){
15+
params$chart <<- setSpec(params$chart, ..., replace = replace)
16+
},
17+
xAxis = function(..., replace = F){
18+
params$xAxis <<- setSpec(params$xAxis, ..., replace = replace)
19+
#if type is lineWithFocus and x2Axis not specified
20+
#make it the same as xAxis
21+
if( params$type == "lineWithFocusChart" && length(params$x2Axis) == 0 ) {
22+
params$x2Axis <<- setSpec(params$x2Axis, ..., replace = replace)
23+
}
24+
},
25+
x2Axis = function(..., replace = F){
26+
params$x2Axis <<- setSpec(params$x2Axis, ..., replace = replace)
27+
},
28+
yAxis = function(..., replace = F){
29+
params$yAxis <<- setSpec(params$yAxis, ..., replace = replace)
30+
},
31+
getChartParams = function(...){
32+
params <<- modifyList(params, getLayer(...))
33+
},
34+
getPayload = function(chartId){
35+
data = toJSONArray(params$data)
36+
chart = toChain(params$chart, 'chart')
37+
xAxis = toChain(params$xAxis, 'chart.xAxis')
38+
x2Axis = toChain(params$x2Axis, 'chart.x2Axis')
39+
yAxis = toChain(params$yAxis, 'chart.yAxis')
40+
opts = toJSON(params[!(names(params) %in% c('data', 'chart', 'xAxis', 'x2Axis', 'yAxis'))])
41+
list(opts = opts, xAxis = xAxis, x2Axis = x2Axis, yAxis = yAxis, data = data,
42+
chart = chart, chartId = chartId)
43+
}
44+
))

inst/libraries/dimple/LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright 2013 PMSI-AlignAlytics
2+
www.pmsi-consulting.com
3+
4+
Permission is hereby granted, free of charge, to any person obtaining
5+
a copy of this software and associated documentation files (the
6+
"Software"), to deal in the Software without restriction, including
7+
without limitation the rights to use, copy, modify, merge, publish,
8+
distribute, sublicense, and/or sell copies of the Software, and to
9+
permit persons to whom the Software is furnished to do so, subject to
10+
the following conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

inst/libraries/dimple/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
nvd3:
2+
jshead: [js/dimple.v1.js, js/d3.v3.js]
3+
cdn:
4+
jshead:
5+
- "http://d3js.org/d3.v3.min.js"
6+
- "js/dimple.v1.js"

inst/libraries/dimple/examples.R

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## {title: Scatter Chart}
2+
p1 <- nPlot(mpg ~ wt, group = 'cyl', data = mtcars, type = 'scatterChart')
3+
p1$xAxis(axisLabel = 'Weight')
4+
p1
5+
6+
7+
## {title: MultiBar Chart}
8+
hair_eye = as.data.frame(HairEyeColor)
9+
p2 <- nPlot(Freq ~ Hair, group = 'Eye', data = subset(hair_eye, Sex == "Female"), type = 'multiBarChart')
10+
p2$chart(color = c('brown', 'blue', '#594c26', 'green'))
11+
p2
12+
13+
## {title: MultiBar Horizontal Chart}
14+
p3 <- nPlot(~ cyl, group = 'gear', data = mtcars, type = 'multiBarHorizontalChart')
15+
p3$chart(showControls = F)
16+
p3
17+
18+
## {title: Pie Chart}
19+
p4 <- nPlot(~ cyl, data = mtcars, type = 'pieChart')
20+
p4
21+
22+
## {title: Donut Chart}
23+
p5 <- nPlot(~ cyl, data = mtcars, type = 'pieChart')
24+
p5$chart(donut = TRUE)
25+
p5
26+
27+
## {title: Line Chart}
28+
data(economics, package = 'ggplot2')
29+
p6 <- nPlot(uempmed ~ date, data = economics, type = 'lineChart')
30+
p6
31+
32+
## {title: Line with Focus Chart }
33+
ecm <- reshape2::melt(economics[,c('date', 'uempmed', 'psavert')], id = 'date')
34+
p7 <- nPlot(value ~ date, group = 'variable', data = ecm, type = 'lineWithFocusChart')
35+
#test format dates on the xAxis
36+
#also good test of javascript functions as parameters
37+
#dates from R to JSON will come over as number of days since 1970-01-01
38+
#so convert to milliseconds 86400000 in a day and then format with d3
39+
#on lineWithFocusChart type xAxis will also set x2Axis unless it is specified
40+
p7$xAxis( tickFormat="#!function(d) {return d3.time.format('%b %Y')(new Date( d * 86400000 ));}!#" )
41+
#test xAxis also sets x2Axis
42+
p7
43+
#now test setting x2Axis to something different
44+
#test format dates on the x2Axis
45+
#test to show %Y format which is different than xAxis
46+
p7$x2Axis( tickFormat="#!function(d) {return d3.time.format('%Y')(new Date( d * 86400000 ));}!#" )
47+
p7
48+
#test set xAxis again to make sure it does not override set x2Axis
49+
p7$xAxis( NULL, replace = T)
50+
p7
51+
52+
## {title: Stacked Area Chart}
53+
dat <- data.frame(t=rep(0:23,each=4),var=rep(LETTERS[1:4],4),val=round(runif(4*24,0,50)))
54+
p8 <- nPlot(val ~ t, group = 'var', data = dat, type = 'stackedAreaChart', id = 'chart')
55+
p8
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2013, Michael Bostock
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
* The name Michael Bostock may not be used to endorse or promote products
15+
derived from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT,
21+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)