Skip to content

Commit

Permalink
allow specification of existing axis with add_series
Browse files Browse the repository at this point in the history
  • Loading branch information
timelyportfolio committed Oct 14, 2015
1 parent bb8d1c6 commit e6687c0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
21 changes: 20 additions & 1 deletion inst/experiments/layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,26 @@ mtcars %>%
add_series(x = "cyl", y = "mpg", type = "line", yAxis = list(hidden=FALSE) ) %>%
# hidden = FALSE so we can compare
add_series(x = "cyl", y = "mpg", groups = "name", type = "bubble") %>%
add_series(x = "cyl", y = "mpg", groups = "cyl", type = "bubble")
add_series(x = "cyl", y = "mpg", groups = "cyl", type = "bubble")

# try to use specify axis
mtcars %>%
dimple(mpg ~ cyl, type = "bar", groups = "cyl") %>%
# give the y axis a name if we plan to reuse
yAxis(name = "y1") %>%
add_series(
x = "cyl", y = "mpg", type = "line",
yAxis = list(useAxis = "y1")
) %>%
# hidden = FALSE so we can compare
add_series(
x = "cyl", y = "mpg", groups = "name", type = "bubble",
yAxis = list(useAxis = "y1")
) %>%
add_series(
x = "cyl", y = "mpg", groups = "cyl", type = "bubble",
yAxis = list(useAxis = "y1")
)

# try it with facets
mtcars %>%
Expand Down
34 changes: 28 additions & 6 deletions inst/htmlwidgets/dimple.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,26 @@ HTMLWidgets.widget({
if (!layer.yAxis) layer.yAxis = opts.yAxis;
if (!layer.zAxis) layer.zAxis = opts.zAxis;

var x = buildAxis("x", layer, myChart);
x.hidden = hidden && (typeof(layer.xAxis.hidden) === "undefined" ? true : false);

var y = buildAxis("y", layer, myChart);
y.hidden = hidden && (typeof(layer.yAxis.hidden) === "undefined" ? true : false);
var x = {}, y = {};

if(layer.xAxis.useAxis) {
x = myChart.axes.filter(function(ax){
return ax.name === layer.xAxis.useAxis;
})[0]
} else {
x = buildAxis("x", layer, myChart);
x.hidden = hidden && (typeof(layer.xAxis.hidden) === "undefined" ? true : false);
}

if(layer.yAxis.useAxis) {
y = myChart.axes.filter(function(ax){
return ax.name === layer.yAxis.useAxis;
})[0]
} else {
y = buildAxis("y", layer, myChart);
y.hidden = hidden && (typeof(layer.yAxis.hidden) === "undefined" ? true : false);
}

//z for bubbles
var z = null;
Expand All @@ -140,7 +155,14 @@ HTMLWidgets.widget({
//here think I need to evaluate group and if missing do null
//as the group argument
//if provided need to use groups from layer
var s = new dimple.series(myChart, null, x, y, z, c, p, dimple.plot[layer.type], dimple.aggregateMethod.avg, dimple.plot[layer.type].stacked);
var s = new dimple.series(
myChart,
null,
x, y, z, c, p,
dimple.plot[layer.type],
dimple.aggregateMethod.avg,
dimple.plot[layer.type].stacked
);

//as of v1.1.4 dimple can use different dataset for each series
// facets not currently working with layer data; need to change structure
Expand Down Expand Up @@ -258,7 +280,7 @@ HTMLWidgets.widget({
Object.keys(axisopts).filter(function(oky){
return [
"measure","type","orderRule","grouporderRule",
"outputFormat","inputFormat"
"outputFormat","inputFormat","useAxis"
].indexOf(oky) < 0
}).forEach(function(oky){
axis[oky] = axisopts[oky]
Expand Down

0 comments on commit e6687c0

Please sign in to comment.