Updated the sold evolution graph type.

This commit is contained in:
Alexis Lahouze 2013-01-24 01:04:01 +01:00
parent 2916f58ead
commit f862c242c5

View File

@ -176,46 +176,10 @@ var ListViewModel = function() {
// We assume that entries are sorted by value date descending.
var entries = unwrap(self.entries).slice().reverse();
// First pass: get open, high, low and close values for each day.
var chartValuesTmp = {};
$.each(entries, function(index, entry) {
//var date = entry.value_date() ? entry.value_date().toString() : null;
var date = unwrap(entry.value_date);
var value = unwrap(entry.value) ? Number(unwrap(entry.value())) : null;
if(date && value) {
var values = {};
var sold = Number(unwrap(entry.sold));
var open = Number((sold - value).toFixed(2));
values['open'] = open;
values['high'] = sold > open ? sold : open;
values['low'] = sold < open ? sold : open;
values['close'] = sold;
if(chartValuesTmp[date]) {
var oldValues = chartValuesTmp[date];
if(oldValues['high'] > values['high']) {
values['high'] = oldValues['high'];
}
if(oldValues['low'] < values['low']) {
values['low'] = oldValues['low'];
}
values['open'] = oldValues['open'];
}
chartValuesTmp[date] = values;
}
});
// Second pass: transform to an array readable by jqplot OHLC renderer.
// Transform to an array readable by jqplot Line renderer.
var chartValues = [];
$.each(chartValuesTmp, function(key, value) {
chartValues.push([key, value['open'], value['high'], value['low'], value['close']]);
$.each(entries, function(index, entry) {
chartValues.push([unwrap(entry.value_date), Number(unwrap(entry.sold))]);
});
return chartValues;
@ -468,6 +432,8 @@ drawChart = function(entries, element) {
var firstDate = new Date(Date.parse(entries[0][0]).valueOf() - day).format('yyyy-mm-dd');
var lastDate = new Date(Date.parse(entries[entries.length -1][0]).valueOf() + day).format('yyyy-mm-dd');
console.debug(entries)
// Plot chart, and store it in a window parameter for resize callback (need to be done better than it...)
window.chart = $.jqplot(element.id, [entries], {
// Title of the chart
@ -499,15 +465,18 @@ drawChart = function(entries, element) {
// Highlighter parameters
highlighter: {
show: true,
yvalues: 4,
formatString: '<table class="jqplot-highlighter"><tr><td>date:</td><td>%s</td></tr><tr><td>open:</td><td>%s</td></tr><tr><td>hi:</td><td>%s</td></tr><tr><td>low:</td><td>%s</td></tr><tr><td>close:</td><td>%s</td></tr></table>'
//yvalues: 4,
formatString: '<table class="jqplot-highlighter"><tr><td>date:</td><td>%s</td></tr><tr><td>sold:</td><td>%s</td></tr>'
},
// Series parameters
series: [{
// We use the OHLC (open, high, low, close) rendered.
renderer:$.jqplot.OHLCRenderer,
//renderer:$.jqplot.OHLCRenderer,
color: "blue",
rendererOptions: {
smooth: true,
}
}],
// To display horizontal (0) and vertical (today) lines