Skip to content

Commit

Permalink
Version 1.6.0
Browse files Browse the repository at this point in the history
* upgraded dependancies
* support for node 4
* support for npm run watch while developing
* RangeSlider can accept multiple graphs
  • Loading branch information
cesine committed Nov 7, 2016
1 parent 93898dc commit b140d85
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 40 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-rc.0",
"version": "1.6.0",
"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-rc.0",
"version": "1.6.0",
"homepage": "http://code.shutterstock.com/rickshaw/",
"dependencies": {
"d3": "^3.5.16"
Expand Down
143 changes: 108 additions & 35 deletions rickshaw.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ Rickshaw.Graph = function(args) {

args = args || {};

if (typeof window !== undefined) {
if (typeof window !== 'undefined') {
var style = window.getComputedStyle(this.element, null);
var elementWidth = parseInt(style.getPropertyValue('width'), 10);
var elementHeight = parseInt(style.getPropertyValue('height'), 10);
Expand Down Expand Up @@ -1097,7 +1097,7 @@ Rickshaw.Fixtures.Time.Local = function() {

this.ceil = function(time, unit) {

var date, floor, year;
var date, floor, year, offset;

if (unit.name == 'day') {

Expand Down Expand Up @@ -1146,8 +1146,8 @@ Rickshaw.Fixtures.Time.Local = function() {

return new Date(year, 0).getTime() / 1000;
}

return Math.ceil(time / unit.seconds) * unit.seconds;
offset = new Date(time * 1000).getTimezoneOffset() * 60;
return Math.ceil((time - offset) / unit.seconds) * unit.seconds + offset;
};
};
Rickshaw.namespace('Rickshaw.Fixtures.Number');
Expand Down Expand Up @@ -1554,13 +1554,15 @@ Rickshaw.Graph.Axis.X = function(args) {
this.ticks = this.staticTicks || Math.floor(this.graph.width / this.pixelsPerTick);

var berth = Math.floor(this.width * berthRate / 2) || 0;
var bar_offset = this.graph.renderer.name == "bar" && Math.ceil(this.graph.width * 0.95 / this.graph.series[0].data.length / 2) || 0;

var transform;

if (this.orientation == 'top') {
var yOffset = this.height || this.graph.height;
transform = 'translate(' + berth + ',' + yOffset + ')';
transform = 'translate(' + (berth + bar_offset) + ',' + yOffset + ')';
} else {
transform = 'translate(' + berth + ', 0)';
transform = 'translate(' + (berth + bar_offset) + ', 0)';
}

if (this.element) {
Expand Down Expand Up @@ -2417,61 +2419,85 @@ Rickshaw.Graph.RangeSlider = Rickshaw.Class.create({

initialize: function(args) {

var $ = jQuery;
var self = this;
var element = this.element = args.element;
var graph = this.graph = args.graph;
var graphs = this.graphs = args.graphs;
if (!graphs) {
graphs = this.graph = args.graph;
}
if (graphs.constructor !== Array) {
graphs = [graphs];
}
this.graph = graphs[0];

this.slideCallbacks = [];

this.build();

graph.onUpdate( function() { this.update() }.bind(this) );
for (var i = 0; i < graphs.length; i++) {
graphs[i].onUpdate(function() {
self.update();
}.bind(self));

graphs[i].onConfigure(function() {
$(element)[0].style.width = graphs[i].width + 'px';
}.bind(self));
}

},

build: function() {

var domain;
var element = this.element;
var graph = this.graph;
var $ = jQuery;

var domain = graph.dataDomain();
var self = this;
var graphs = this.graphs || this.graph;

$( function() {
$(element).slider( {
if (graphs.constructor !== Array) {
graphs = [graphs];
}

// base the slider's min/max on the first graph
this.graph = graphs[0];
domain = graphs[0].dataDomain();

$(function() {
$(element).slider({
range: true,
min: domain[0],
max: domain[1],
values: [
values: [
domain[0],
domain[1]
],
slide: function( event, ui ) {
start: function(event, ui) {
self.slideStarted({ event: event, ui: ui });
},
stop: function(event, ui) {
self.slideFinished({ event: event, ui: ui });
},
slide: function(event, ui) {
if (!self.slideShouldUpdate(event, ui))
return;

if (ui.values[1] <= ui.values[0]) return;

graph.window.xMin = ui.values[0];
graph.window.xMax = ui.values[1];
graph.update();

var domain = graph.dataDomain();

// if we're at an extreme, stick there
if (domain[0] == ui.values[0]) {
graph.window.xMin = undefined;
}

if (domain[1] == ui.values[1]) {
graph.window.xMax = undefined;
for (var i = 0; i < graphs.length; i++) {
self.processSlideChange({
event: event,
ui: ui,
graph: graphs[i]
});
}

self.slideCallbacks.forEach(function(callback) {
callback(graph, graph.window.xMin, graph.window.xMax);
});
}
} );
} );

$(element)[0].style.width = graph.width + 'px';
graphs[0].onConfigure(function() {
$(element)[0].style.width = graphs[0].width + 'px';
}.bind(this));

},

Expand Down Expand Up @@ -2500,6 +2526,45 @@ Rickshaw.Graph.RangeSlider = Rickshaw.Class.create({

onSlide: function(callback) {
this.slideCallbacks.push(callback);
},

processSlideChange: function(args) {
var event = args.event;
var ui = args.ui;
var graph = args.graph;

graph.window.xMin = ui.values[0];
graph.window.xMax = ui.values[1];
graph.update();

var domain = graph.dataDomain();

// if we're at an extreme, stick there
if (domain[0] == ui.values[0]) {
graph.window.xMin = undefined;
}

if (domain[1] == ui.values[1]) {
graph.window.xMax = undefined;
}

this.slideCallbacks.forEach(function(callback) {
callback(graph, graph.window.xMin, graph.window.xMax);
});

},

// allows the slide updates to bail out if sliding is not permitted
slideShouldUpdate: function() {
return true;
},

slideStarted: function() {
return;
},

slideFinished: function() {
return;
}
});

Expand Down Expand Up @@ -3017,6 +3082,9 @@ Rickshaw.Graph.Renderer = Rickshaw.Class.create( {
// Requires that at least one series contains some data
var stackedData = data || this.graph.stackedData || this.graph.stackData();

// filter out any series that may be empty in the current x-domain
stackedData = stackedData.filter(function (a) { return a && a.length !== 0; });

var xMin = +Infinity;
var xMax = -Infinity;

Expand Down Expand Up @@ -3321,8 +3389,13 @@ Rickshaw.Graph.Renderer.Bar = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
}

var frequentInterval = { count: 0, magnitude: 1 };

Rickshaw.keys(intervalCounts).forEach( function(i) {

// Sorting object's keys returned to guarantee consistency when iterating over
// Keys order in `for .. in` loop is not specified and browsers behave differently here
// This results with different invterval value being calculated for different browsers
// See last but one section here: http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.4
var keysSorted = Rickshaw.keys(intervalCounts).sort(function asc(a, b) { return Number(a) - Number(b); });
keysSorted.forEach( function(i) {
if (frequentInterval.count < intervalCounts[i]) {
frequentInterval = {
count: intervalCounts[i],
Expand Down
6 changes: 3 additions & 3 deletions rickshaw.min.js

Large diffs are not rendered by default.

0 comments on commit b140d85

Please sign in to comment.