Added resize handler to resize the chart when resizing the window, added global ajax error handler.
This commit is contained in:
parent
d044300680
commit
68c487b91d
@ -41,6 +41,7 @@ var ListViewModel = function() {
|
||||
self.selectedItem = ko.observable();
|
||||
self.savedItem = ko.observable();
|
||||
self.itemToRemove = ko.observable();
|
||||
self.chart = null;
|
||||
|
||||
self.entriesChart = ko.computed(function() {
|
||||
var entries = self.entries().slice().reverse();
|
||||
@ -355,18 +356,7 @@ ko.bindingHandlers.dateValue = {
|
||||
}
|
||||
};
|
||||
|
||||
ko.bindingHandlers.chart = {
|
||||
init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
|
||||
// empty - left as placeholder if needed later
|
||||
},
|
||||
|
||||
update: function (element, valueAccessor, allBindingsAccessor, viewModel) {
|
||||
var unwrap = ko.utils.unwrapObservable;
|
||||
var dataSource = valueAccessor();
|
||||
|
||||
//var entries = dataSource ? unwrap(dataSource) : null;
|
||||
var entries = dataSource ? unwrap(dataSource) : null;
|
||||
|
||||
drawChart = function(entries, element) {
|
||||
if(entries && entries.length > 0) {
|
||||
var firstDate, lastDate;
|
||||
var chartValues = [[], []];
|
||||
@ -388,7 +378,7 @@ ko.bindingHandlers.chart = {
|
||||
$(element).html("");
|
||||
|
||||
// plot chart
|
||||
$.jqplot(element.id, chartValues, {
|
||||
jqplot = $.jqplot(element.id, chartValues, {
|
||||
axes:{
|
||||
xaxis:{
|
||||
renderer:$.jqplot.DateAxisRenderer,
|
||||
@ -419,12 +409,33 @@ ko.bindingHandlers.chart = {
|
||||
//candleStick: true
|
||||
}}],
|
||||
});//*/
|
||||
}
|
||||
|
||||
$(window).resize(function() {
|
||||
jqplot.replot({resetAxes: true});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var viewModel = new ListViewModel();
|
||||
ko.bindingHandlers.chart = {
|
||||
init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
|
||||
// empty - left as placeholder if needed later
|
||||
},
|
||||
|
||||
update: function (element, valueAccessor, allBindingsAccessor, viewModel) {
|
||||
var unwrap = ko.utils.unwrapObservable;
|
||||
var dataSource = valueAccessor();
|
||||
|
||||
//var entries = dataSource ? unwrap(dataSource) : null;
|
||||
var entries = dataSource ? unwrap(dataSource) : null;
|
||||
drawChart(entries, element);
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ajaxError(function(event, xhr, settings) {
|
||||
message("error", "Error.", xhr.statusText);
|
||||
});
|
||||
|
||||
var viewModel = new ListViewModel();
|
||||
ko.applyBindings(viewModel);
|
||||
|
||||
$(viewModel.loadAccounts);
|
||||
|
Loading…
Reference in New Issue
Block a user