Created
May 16, 2016 22:29
-
-
Save pplanel/b5f4731c1556cb82c7489d88eedec175 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(GOAL){ | |
function generateSeriesByGoal(goal, timeframe){ | |
var newSeries = []; | |
var metaDividida = goal / timeframe; | |
for(var i = 0; i < timeframe; i++){ | |
newSeries[i] = metaDividida; | |
} | |
return newSeries; | |
} | |
var x_series = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; | |
function recalculo(series, index, value, old_value) { | |
var data = series.data; // Array de valores atuais | |
var tempData = []; | |
var tempData = series; | |
// for (var i = data.length - 1; i >= 0; i--) { | |
// if(i != index){ | |
// // TODO(pplanel): Pegar valor anterior do ponto modificado | |
// if(tempData[i].y < 0) tempData[i].y = 0; | |
// if(value > old_value){ | |
// tempData[i].y -= (old_value - value); | |
// }else{ | |
// tempData[i].y += (old_value - value); | |
// } | |
// } | |
// }; | |
return tempData; | |
} | |
var chart = new Highcharts.Chart({ | |
chart:{ | |
renderTo:"container", | |
type:"areaspline" | |
}, | |
xAxis: { | |
categories: x_series | |
}, | |
series:[{ | |
name: "Meta", | |
draggableY: true, | |
dragMinY: 0 | |
}], | |
plotOptions: { | |
series:{ | |
point:{ | |
events:{ | |
drag:function(e){ | |
if(this.y > GOAL) { | |
this.y = GOAL; | |
return false; | |
} | |
}, | |
drop:function(){ | |
var series = recalculo(this.series, this.index, this.y, this.series.dataMax); | |
this.series.setData(series); | |
return false; | |
} | |
} | |
} | |
} | |
}, | |
line: { | |
cursor: 'ns-resize' | |
} | |
}); | |
// inicializa dataset | |
chart.series[0].setData(generateSeriesByGoal(GOAL, x_series.length)); | |
})(120000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment