Skip to content

Commit

Permalink
update built libs
Browse files Browse the repository at this point in the history
  • Loading branch information
dchester committed Oct 23, 2013
1 parent 55be4a5 commit 470b6f8
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 50 deletions.
42 changes: 36 additions & 6 deletions rickshaw.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
background: white;
white-space: nowrap;
}
.rickshaw_graph .detail .x_label.left {
left: 0;
}
.rickshaw_graph .detail .x_label.right {
right: 0;
}
.rickshaw_graph .detail .item {
position: absolute;
z-index: 2;
Expand All @@ -40,25 +46,49 @@
color: white;
border: 1px solid rgba(0, 0, 0, 0.4);
margin-left: 1em;
margin-right: 1em;
margin-top: -1em;
white-space: nowrap;
}
.rickshaw_graph .detail .item.left {
left: 0;
}
.rickshaw_graph .detail .item.right {
right: 0;
}
.rickshaw_graph .detail .item.active {
opacity: 1;
background: rgba(0, 0, 0, 0.8);
}
.rickshaw_graph .detail .item:before {
content: "\25c2";
.rickshaw_graph .detail .item:after {
position: absolute;
left: -0.5em;
color: rgba(0, 0, 0, 0.7);
display: block;
width: 0;
height: 0;

content: "";

border: 5px solid transparent;
}
.rickshaw_graph .detail .item.left:after {
top: 1em;
left: -5px;
margin-top: -5px;
border-right-color: rgba(0, 0, 0, 0.8);
border-left-width: 0;
}
.rickshaw_graph .detail .item.right:after {
top: 1em;
right: -5px;
margin-top: -5px;
border-left-color: rgba(0, 0, 0, 0.8);
border-right-width: 0;
}
.rickshaw_graph .detail .dot {
width: 4px;
height: 4px;
margin-left: -4px;
margin-top: -3px;
margin-left: -2px;
margin-top: -2px;
border-radius: 5px;
position: absolute;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.6);
Expand Down
196 changes: 155 additions & 41 deletions rickshaw.js
Original file line number Diff line number Diff line change
Expand Up @@ -1701,8 +1701,32 @@ Rickshaw.Graph.Axis.Y.Scaled = Rickshaw.Class.create( Rickshaw.Graph.Axis.Y, {
},

_drawAxis: function($super, scale) {
// make a copy of the custom scale, adjust the range to match the graph's scale
var adjustedScale = this.scale.copy().range(scale.range());
// Adjust scale's domain to compensate for adjustments to the
// renderer's domain (e.g. padding).
var domain = this.scale.domain();
var renderDomain = this.graph.renderer.domain().y;

var extents = [
Math.min.apply(Math, domain),
Math.max.apply(Math, domain)];

// A mapping from the ideal render domain [0, 1] to the extent
// of the original scale's domain. This is used to calculate
// the extents of the adjusted domain.
var extentMap = d3.scale.linear().domain([0, 1]).range(extents);

var adjExtents = [
extentMap(renderDomain[0]),
extentMap(renderDomain[1])];

// A mapping from the original domain to the adjusted domain.
var adjustment = d3.scale.linear().domain(extents).range(adjExtents);

// Make a copy of the custom scale, apply the adjusted domain, and
// copy the range to match the graph's scale.
var adjustedScale = this.scale.copy()
.domain(domain.map(adjustment))
.range(scale.range());

return $super(adjustedScale);
},
Expand Down Expand Up @@ -1737,14 +1761,14 @@ Rickshaw.Graph.Behavior.Series.Highlight = function(args) {
if (activeLine) return;
else activeLine = l;

self.legend.lines.forEach( function(line, index) {
self.legend.lines.forEach( function(line) {

if (l === line) {

// if we're not in a stacked renderer bring active line to the top
if (index > 0 && self.graph.renderer.unstack && (line.series.renderer ? line.series.renderer.unstack : true)) {
if (self.graph.renderer.unstack && (line.series.renderer ? line.series.renderer.unstack : true)) {

var seriesIndex = self.graph.series.length - index - 1;
var seriesIndex = self.graph.series.indexOf(line.series);
line.originalIndex = seriesIndex;

var series = self.graph.series.splice(seriesIndex, 1)[0];
Expand Down Expand Up @@ -2156,17 +2180,65 @@ Rickshaw.Graph.HoverDetail = Rickshaw.Class.create({
this.element.appendChild(dot);

if (point.active) {
item.className = 'item active';
dot.className = 'dot active';
item.classList.add('active');
dot.classList.add('active');
}

// Assume left alignment until the element has been displayed and
// bounding box calculations are possible.
var alignables = [xLabel, item];
alignables.forEach(function(el) {
el.classList.add('left');
});

this.show();

// If left-alignment results in any error, try right-alignment.
var leftAlignError = this._calcLayoutError(alignables);
if (leftAlignError > 0) {
alignables.forEach(function(el) {
el.classList.remove('left');
el.classList.add('right');
});

// If right-alignment is worse than left alignment, switch back.
var rightAlignError = this._calcLayoutError(alignables);
if (rightAlignError > leftAlignError) {
alignables.forEach(function(el) {
el.classList.remove('right');
el.classList.add('left');
});
}
}

if (typeof this.onRender == 'function') {
this.onRender(args);
}
},

_calcLayoutError: function(alignables) {
// Layout error is calculated as the number of linear pixels by which
// an alignable extends past the left or right edge of the parent.
var parentRect = this.element.parentNode.getBoundingClientRect();

var error = 0;
var alignRight = alignables.forEach(function(el) {
var rect = el.getBoundingClientRect();
if (!rect.width) {
return;
}

if (rect.right > parentRect.right) {
error += rect.right - parentRect.right;
}

if (rect.left < parentRect.left) {
error += parentRect.left - rect.left;
}
});
return error;
},

_addListeners: function() {

this.graph.element.addEventListener(
Expand All @@ -2191,7 +2263,6 @@ Rickshaw.Graph.HoverDetail = Rickshaw.Class.create({
);
}
});

Rickshaw.namespace('Rickshaw.Graph.JSONP');

Rickshaw.Graph.JSONP = Rickshaw.Class.create( Rickshaw.Graph.Ajax, {
Expand All @@ -2208,28 +2279,51 @@ Rickshaw.Graph.JSONP = Rickshaw.Class.create( Rickshaw.Graph.Ajax, {
} );
Rickshaw.namespace('Rickshaw.Graph.Legend');

Rickshaw.Graph.Legend = function(args) {
Rickshaw.Graph.Legend = Rickshaw.Class.create( {

var element = this.element = args.element;
var graph = this.graph = args.graph;
className: 'rickshaw_legend',

var self = this;
initialize: function(args) {
this.element = args.element;
this.graph = args.graph;
this.naturalOrder = args.naturalOrder;

element.classList.add('rickshaw_legend');
this.element.classList.add(this.className);

var list = this.list = document.createElement('ul');
element.appendChild(list);
this.list = document.createElement('ul');
this.element.appendChild(this.list);

var series = graph.series
.map( function(s) { return s } );
this.render();

// we could bind this.render.bind(this) here
// but triggering the re-render would lose the added
// behavior of the series toggle
this.graph.onUpdate( function() {} );
},

render: function() {
var self = this;

while ( this.list.firstChild ) {
this.list.removeChild( this.list.firstChild );
}
this.lines = [];

var series = this.graph.series
.map( function(s) { return s } );

if (!this.naturalOrder) {
series = series.reverse();
}

series.forEach( function(s) {
self.addLine(s);
} );

if (!args.naturalOrder) {
series = series.reverse();
}

this.lines = [];
},

this.addLine = function (series) {
addLine: function (series) {
var line = document.createElement('li');
line.className = 'line';
if (series.disabled) {
Expand All @@ -2247,7 +2341,7 @@ Rickshaw.Graph.Legend = function(args) {
label.innerHTML = series.name;

line.appendChild(label);
list.appendChild(line);
this.list.appendChild(line);

line.series = series;

Expand All @@ -2256,22 +2350,18 @@ Rickshaw.Graph.Legend = function(args) {
}

var _line = { element: line, series: series };
if (self.shelving) {
self.shelving.addAnchor(_line);
self.shelving.updateBehaviour();
if (this.shelving) {
this.shelving.addAnchor(_line);
this.shelving.updateBehaviour();
}
if (self.highlighter) {
self.highlighter.addHighlightEvents(_line);
if (this.highlighter) {
this.highlighter.addHighlightEvents(_line);
}
self.lines.push(_line);
};

series.forEach( function(s) {
self.addLine(s);
} );
this.lines.push(_line);
return line;
}
} );

graph.onUpdate( function() {} );
};
Rickshaw.namespace('Rickshaw.Graph.RangeSlider');

Rickshaw.Graph.RangeSlider = Rickshaw.Class.create({
Expand Down Expand Up @@ -2407,6 +2497,8 @@ Rickshaw.Graph.Renderer = Rickshaw.Class.create( {
if (y > yMax) yMax = y;
} );

if (!series.length) return;

if (series[0].x < xMin) xMin = series[0].x;
if (series[series.length - 1].x > xMax) xMax = series[series.length - 1].x;
} );
Expand Down Expand Up @@ -2724,17 +2816,25 @@ Rickshaw.Graph.Renderer.Area = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
return factory;
},

render: function() {
render: function(args) {

args = args || {};

var graph = this.graph;
var series = args.series || graph.series;

graph.vis.selectAll('*').remove();
var vis = args.vis || graph.vis;
vis.selectAll('*').remove();

// insert or stacked areas so strokes lay on top of areas
var method = this.unstack ? 'append' : 'insert';

var nodes = graph.vis.selectAll("path")
.data(this.graph.stackedData)
var data = series
.filter(function(s) { return !s.disabled })
.map(function(s) { return s.stack });

var nodes = vis.selectAll("path")
.data(data)
.enter()[method]("svg:g", 'g');

nodes.append("svg:path")
Expand All @@ -2748,7 +2848,7 @@ Rickshaw.Graph.Renderer.Area = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
}

var i = 0;
graph.series.forEach( function(series) {
series.forEach( function(series) {
if (series.disabled) return;
series.path = nodes[0][i++];
this._styleSeries(series);
Expand Down Expand Up @@ -2847,6 +2947,13 @@ Rickshaw.Graph.Renderer.Multi = Rickshaw.Class.create( Rickshaw.Graph.Renderer,
} );
},

configure: function($super, args) {

args = args || {};
this.config = args;
$super(args);
},

domain: function($super) {

this.graph.stackData();
Expand Down Expand Up @@ -2895,6 +3002,13 @@ Rickshaw.Graph.Renderer.Multi = Rickshaw.Class.create( Rickshaw.Graph.Renderer,

var renderer = graph._renderers[series.renderer];

var config = {};

var defaults = [ this.defaults(), renderer.defaults(), this.config, this.graph ];
defaults.forEach(function(d) { Rickshaw.extend(config, d) });

renderer.configure(config);

renderGroups[series.renderer] = {
renderer: renderer,
series: [],
Expand Down
Loading

0 comments on commit 470b6f8

Please sign in to comment.