Permalink
Browse files

Merge pull request #91 from beezly/stacked-charts

Stacked charts
  • Loading branch information...
auxesis committed Mar 24, 2012
2 parents e87d8eb + 29fb910 commit d2363931a0eaace56ffaedac1b2ee02e3fd12ee7
Showing with 49 additions and 2 deletions.
  1. +49 −2 lib/visage-app/public/javascripts/graph.js
@@ -1,3 +1,19 @@
+function setStacked(chart, stacking) {
+ for(var i=0;i<chart.series.length;i++)
+ {
+ var serie = chart.series[0];
+ var newSeries = {
+ type: stacking ? 'area' : 'line',
+ name: serie.name,
+ color: serie.color,
+ data: serie.options.data,
+ stacking: stacking ? 'normal' : null,
+ }
+ chart.addSeries(newSeries, false, false);
+ serie.remove();
+ }
+}
+
function formatSeriesLabel(labels) {
var host = labels[0],
plugin = labels[1],
@@ -149,7 +165,8 @@ var VisageBase = new Class({
options: {
secureJSON: false,
httpMethod: 'get',
- live: false
+ live: false,
+ stacked: false
},
initialize: function(element, host, plugin, options) {
this.parentElement = element;
@@ -447,7 +464,7 @@ var VisageGraph = new Class({
layout: 'horizontal',
align: 'center',
verticalAlign: 'top',
- y: 275,
+ y: 250,
borderWidth: 0,
labelFormatter: function() {
return formatSeriesLabel(this.name)
@@ -555,6 +572,23 @@ var VisageGraph = new Class({
}
});
+ var stackedToggler = new Element('input', {
+ 'type': 'checkbox',
+ 'id': this.parentElement + '-stacked',
+ 'name': 'stacked',
+ 'checked': this.options.stacked,
+ 'events': {
+ 'click': function() {
+ this.options.stacked = !this.options.stacked
+ setStacked(this.chart, this.options.stacked)
+ }.bind(this)
+ },
+ 'styles': {
+ 'margin-right': '4px',
+ 'cursor': 'pointer'
+ }
+ });
+
var liveLabel = new Element('label', {
'for': this.parentElement + '-live',
'html': 'Live',
@@ -566,6 +600,17 @@ var VisageGraph = new Class({
}
});
+ var stackedLabel = new Element('label', {
+ 'for': this.parentElement + '-stacked',
+ 'html': 'Stacked',
+ 'styles': {
+ 'font-family': 'sans-serif',
+ 'font-size': '11px',
+ 'margin-right': '8px',
+ 'cursor': 'pointer'
+ }
+ });
+
var exportLink = new Element('a', {
'href': this.dataURL(),
'html': 'Export data',
@@ -595,6 +640,8 @@ var VisageGraph = new Class({
form.grab(exportLink)
form.grab(liveToggler)
form.grab(liveLabel)
+ form.grab(stackedToggler)
+ form.grab(stackedLabel)
form.grab(select)
container.grab(form, 'top')
},

0 comments on commit d236393

Please sign in to comment.