Skip to content

Commit

Permalink
1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cesine committed Jul 29, 2017
1 parent ef1da3e commit 0aff8dd
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rickshaw",
"version": "1.6.0",
"version": "1.6.1",
"description": "Rickshaw is a JavaScript toolkit for creating interactive time series graphs.",
"main": "./rickshaw",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rickshaw",
"version": "1.6.0",
"version": "1.6.1",
"homepage": "http://code.shutterstock.com/rickshaw/",
"dependencies": {
"d3": "^3.5.16"
Expand Down
122 changes: 121 additions & 1 deletion rickshaw.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
root.Rickshaw = factory(d3);
}
}(this, function (d3) {
/* jshint -W079 */
/* jshint -W079 */

var Rickshaw = {
version: '1.6.1',

namespace: function(namespace, obj) {

Expand Down Expand Up @@ -2033,6 +2034,125 @@ Rickshaw.Graph.Behavior.Series.Toggle = function(args) {
this.updateBehaviour = function () { this._addBehavior() };

};
Rickshaw.namespace('Rickshaw.Graph.DragZoom');

Rickshaw.Graph.DragZoom = Rickshaw.Class.create({

initialize: function(args) {
if (!args || !args.graph) {
throw new Error("Rickshaw.Graph.DragZoom needs a reference to a graph");
}
var defaults = {
opacity: 0.5,
fill: 'steelblue',
minimumTimeSelection: 60,
callback: function() {}
};

this.graph = args.graph;
this.svg = d3.select(this.graph.element).select("svg");
this.svgWidth = parseInt(this.svg.attr("width"), 10);
this.opacity = args.opacity || defaults.opacity;
this.fill = args.fill || defaults.fill;
this.minimumTimeSelection = args.minimumTimeSelection || defaults.minimumTimeSelection;
this.callback = args.callback || defaults.callback;

this.registerMouseEvents();
},

registerMouseEvents: function() {
var self = this;
var ESCAPE_KEYCODE = 27;
var rectangle;

var drag = {
startDt: null,
stopDt: null,
startPX: null,
stopPX: null
};

this.svg.on("mousedown", onMousedown);

function onMouseup(datum, index) {
drag.stopDt = pointAsDate(d3.event);
var windowAfterDrag = [
drag.startDt,
drag.stopDt
].sort(compareNumbers);

self.graph.window.xMin = windowAfterDrag[0];
self.graph.window.xMax = windowAfterDrag[1];

var endTime = self.graph.window.xMax;
var range = self.graph.window.xMax - self.graph.window.xMin;

reset(this);

if (range < self.minimumTimeSelection || isNaN(range)) {
return;
}
self.graph.update();
self.callback({range: range, endTime: endTime});
}

function onMousemove() {
var offset = drag.stopPX = (d3.event.offsetX || d3.event.layerX);
if (offset > (self.svgWidth - 1) || offset < 1) {
return;
}

var limits = [drag.startPX, offset].sort(compareNumbers);
var selectionWidth = limits[1]-limits[0];
if (isNaN(selectionWidth)) {
return reset(this);
}
rectangle.attr("fill", self.fill)
.attr("x", limits[0])
.attr("width", selectionWidth);
}

function onMousedown() {
var el = d3.select(this);
rectangle = el.append("rect")
.style("opacity", self.opacity)
.attr("y", 0)
.attr("height", "100%");

if(d3.event.preventDefault) {
d3.event.preventDefault();
} else {
d3.event.returnValue = false;
}
drag.target = d3.event.target;
drag.startDt = pointAsDate(d3.event);
drag.startPX = d3.event.offsetX || d3.event.layerX;
el.on("mousemove", onMousemove);
d3.select(document).on("mouseup", onMouseup);
d3.select(document).on("keyup", function() {
if (d3.event.keyCode === ESCAPE_KEYCODE) {
reset(this);
}
});
}

function reset(el) {
var s = d3.select(el);
s.on("mousemove", null);
d3.select(document).on("mouseup", null);
drag = {};
rectangle.remove();
}

function compareNumbers(a, b) {
return a - b;
}

function pointAsDate(e) {
return Math.floor(self.graph.x.invert(e.offsetX || e.layerX));
}
}
});
Rickshaw.namespace('Rickshaw.Graph.HoverDetail');

Rickshaw.Graph.HoverDetail = Rickshaw.Class.create({
Expand Down
6 changes: 3 additions & 3 deletions rickshaw.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/js/Rickshaw.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* jshint -W079 */

var Rickshaw = {
version: '1.6.0',
version: '1.6.1',

namespace: function(namespace, obj) {

Expand Down

0 comments on commit 0aff8dd

Please sign in to comment.