Skip to content
Open
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: dygraphs
Type: Package
Title: Interface to 'Dygraphs' Interactive Time Series Charting Library
Version: 1.1.1.6
Version: 1.2.3
Authors@R: c(
person("Dan", "Vanderkam", role = c("aut", "cph"),
comment = "dygraphs library in htmlwidgets/lib, http://dygraphs.com/"),
Expand Down
2 changes: 1 addition & 1 deletion R/range-selector.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dyRangeSelector <- function(dygraph,
selector$retainDateWindow <- retainDateWindow

if(keepMouseZoom)
selector$interactionModel= JS("Dygraph.Interaction.defaultModel")
selector$interactionModel= JS("Dygraph.defaultInteractionModel")

# merge selector
dygraph$x$attrs <- mergeLists(dygraph$x$attrs, selector)
Expand Down
89 changes: 47 additions & 42 deletions inst/htmlwidgets/dygraphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ HTMLWidgets.widget({

// disable zoom interaction except for clicks
if (attrs.disableZoom) {
attrs.interactionModel = Dygraph.Interaction.nonInteractiveModel_;
attrs.interactionModel = Dygraph.nonInteractiveModel_;
}

// convert non-arrays to arrays
Expand Down Expand Up @@ -100,10 +100,15 @@ HTMLWidgets.widget({
// transpose array
attrs.file = HTMLWidgets.transposeArray2D(attrs.file);

/*
// add drawCallback for group
if (x.group != null)
this.addGroupDrawCallback(x);

if (typeof(x.group) !== "undefined" && x.group !== null) {
this.addGroupDrawCallback(x);
this.addGroupHighlightCallback(x);
this.addGroupUnhighlightCallback(x);
}
*/

// add shading and event callback if necessary
this.addShadingCallback(x);
this.addEventCallback(x);
Expand All @@ -113,7 +118,7 @@ HTMLWidgets.widget({
if (attrs.mobileDisableYTouch !== false && this.isMobilePhone()) {
// create default interaction model if necessary
if (!attrs.interactionModel)
attrs.interactionModel = Dygraph.Interaction.defaultModel;
attrs.interactionModel = Dygraph.defaultInteractionModel;
// disable y touch direction
attrs.interactionModel.touchstart = function(event, dygraph, context) {
Dygraph.defaultInteractionModel.touchstart(event, dygraph, context);
Expand Down Expand Up @@ -230,8 +235,18 @@ HTMLWidgets.widget({
// create the dygraph and add it to it's group (if any)
dygraph = thiz.dygraph = new Dygraph(el, attrs.file, attrs);
dygraph.userDateWindow = attrs.dateWindow;
if (x.group != null)
if (x.group !== null && typeof(x.group) !== "undefined") {
if(typeof(groups[x.group]) === "undefined") {
groups[x.group] = [];
}
groups[x.group].push(dygraph);
if(typeof(groups[x.group].sync) !== "undefined") {
groups[x.group].sync.detach();
}
if(groups[x.group].length > 1) {
groups[x.group].sync = Dygraph.synchronize.apply(null, groups[x.group]);
}
}

// add shiny inputs for date window and click
if (HTMLWidgets.shinyMode) {
Expand All @@ -252,6 +267,22 @@ HTMLWidgets.widget({
dygraph.setAnnotations(x.annotations);
});
}

// set up a container for tasks to perform after completion
// one example would be add callbacks for event handling
// styling
if (!(typeof x.tasks === "undefined") ){
if ( (typeof x.tasks.length === "undefined") ||
(typeof x.tasks === "function" ) ) {
// handle a function not enclosed in array
// should be able to remove once using jsonlite
x.tasks = [x.tasks];
}
x.tasks.map(function(t){
// for each tasks call the task with el supplied as `this`
t.call({el:el,x:x,dygraph:dygraph});
});
}

},

Expand Down Expand Up @@ -471,48 +502,22 @@ HTMLWidgets.widget({
dygraph.userDateWindow = null;
}

// record user valueRange (or lack thereof)
if (dygraph.yAxisRange()[0] != yRanges[0][0] ||
dygraph.yAxisRange()[1] != yRanges[0][1]) {
dygraph.valueRange = yRanges[0];
} else {
dygraph.valueRange = null;
}

// record in group if necessary
if (x.group != null && groups[x.group] != null) {
var group = groups[x.group];
for(var i = 0; i<group.length; i++)
for(var i = 0; i<group.length; i++) {
group[i].userDateWindow = dygraph.userDateWindow;
}
};
},

addGroupDrawCallback: function(x) {

// get attrs
var attrs = x.attrs;

// check for an existing drawCallback
var prevDrawCallback = attrs["drawCallback"];

groups[x.group] = groups[x.group] || [];
var group = groups[x.group];
var blockRedraw = false;
attrs.drawCallback = function(me, initial) {

// call existing
if (prevDrawCallback)
prevDrawCallback(me, initial);

// sync peers in group
if (blockRedraw || initial) return;
blockRedraw = true;
var range = dygraph.xAxisRange();
for (var j = 0; j < group.length; j++) {
if (group[j] == me) continue;
// update group range only if it's different (prevents
// infinite recursion in updateOptions)
var peerRange = group[j].xAxisRange();
if (peerRange[0] != range[0] || peerRange[1] != range[1]) {
group[j].updateOptions({
dateWindow: range
});
group[i].valueRange = dygraph.valueRange;
}
}
blockRedraw = false;
};
},

Expand Down
6 changes: 5 additions & 1 deletion inst/htmlwidgets/dygraphs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ dependencies:
src: "htmlwidgets/lib/jquery"
script: jquery.min.js
- name: dygraphs
version: 1.1.1
version: 2.1.0
src: "htmlwidgets/lib/dygraphs"
script:
- dygraph-combined.js
- shapes.js
stylesheet: dygraph.css
- name: synchronizer
version: 2.1.0
src: "plugins"
script: synchronizer.js
- name: moment
version: 2.8.4
src: "htmlwidgets/lib/timezone"
Expand Down
Loading