Updated the sold evolution graph type.
This commit is contained in:
parent
2916f58ead
commit
f862c242c5
@ -176,46 +176,10 @@ var ListViewModel = function() {
|
|||||||
// We assume that entries are sorted by value date descending.
|
// We assume that entries are sorted by value date descending.
|
||||||
var entries = unwrap(self.entries).slice().reverse();
|
var entries = unwrap(self.entries).slice().reverse();
|
||||||
|
|
||||||
// First pass: get open, high, low and close values for each day.
|
// Transform to an array readable by jqplot Line renderer.
|
||||||
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.
|
|
||||||
var chartValues = [];
|
var chartValues = [];
|
||||||
$.each(chartValuesTmp, function(key, value) {
|
$.each(entries, function(index, entry) {
|
||||||
chartValues.push([key, value['open'], value['high'], value['low'], value['close']]);
|
chartValues.push([unwrap(entry.value_date), Number(unwrap(entry.sold))]);
|
||||||
});
|
});
|
||||||
|
|
||||||
return chartValues;
|
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 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');
|
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...)
|
// 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], {
|
window.chart = $.jqplot(element.id, [entries], {
|
||||||
// Title of the chart
|
// Title of the chart
|
||||||
@ -499,15 +465,18 @@ drawChart = function(entries, element) {
|
|||||||
// Highlighter parameters
|
// Highlighter parameters
|
||||||
highlighter: {
|
highlighter: {
|
||||||
show: true,
|
show: true,
|
||||||
yvalues: 4,
|
//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>'
|
formatString: '<table class="jqplot-highlighter"><tr><td>date:</td><td>%s</td></tr><tr><td>sold:</td><td>%s</td></tr>'
|
||||||
},
|
},
|
||||||
|
|
||||||
// Series parameters
|
// Series parameters
|
||||||
series: [{
|
series: [{
|
||||||
// We use the OHLC (open, high, low, close) rendered.
|
// We use the OHLC (open, high, low, close) rendered.
|
||||||
renderer:$.jqplot.OHLCRenderer,
|
//renderer:$.jqplot.OHLCRenderer,
|
||||||
color: "blue",
|
color: "blue",
|
||||||
|
rendererOptions: {
|
||||||
|
smooth: true,
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
|
|
||||||
// To display horizontal (0) and vertical (today) lines
|
// To display horizontal (0) and vertical (today) lines
|
||||||
|
Loading…
Reference in New Issue
Block a user