extjs-gpl
Version:
GPL licensed version of Sencha Ext JS
115 lines (96 loc) • 3.37 kB
JavaScript
Ext.define('KitchenSink.view.charts.column.BasicController', {
extend: 'Ext.app.ViewController',
alias: 'controller.column-basic',
onDownload: function() {
if (Ext.isIE8) {
Ext.Msg.alert('Unsupported Operation', 'This operation requires a newer version of Internet Explorer.');
return;
}
var chart = this.lookupReference('chart');
if (Ext.os.is.Desktop) {
chart.download({
filename: 'Redwood City Climate Data Chart'
});
} else {
chart.preview();
}
},
onReloadData: function() {
var chart = this.lookupReference('chart');
chart.getStore().refreshData();
},
// The 'target' here is an object that contains information
// about the target value when the drag operation on the column ends.
onEditTipRender: function (tooltip, item, target, e) {
tooltip.setHtml('Temperature °F: ' + target.yValue.toFixed(1));
},
onSeriesLabelRender: function (value) {
return value.toFixed(1);
},
onColumnEdit: function (chart, data) {
var threshold = 65,
delta = 20,
yValue = data.target.yValue,
coldness;
if (yValue < threshold) {
coldness = Ext.Number.constrain((threshold - yValue) / delta, 0, 1);
return {
fillStyle: 'rgba(133, 231, 252, ' + coldness.toString() + ')'
};
} else {
return {
fillStyle: 'none'
};
}
},
onAfterRender: function () {
var me = this,
chart = this.lookupReference('chart'),
axis = chart.getAxis(0),
store = chart.getStore();
function onAxisRangeChange() {
me.onAxisRangeChange(axis);
}
store.on({
datachanged: onAxisRangeChange,
update: onAxisRangeChange
});
},
onAxisRangeChange: function (axis, range) {
// this.lookupReference('chart') will fail here,
// as at the time of this call
// the chart is not yet in the component tree,
// so we have to use axis.getChart() instead.
var chart = axis.getChart(),
store = chart.getStore(),
sum = 0,
mean;
store.each(function (rec) {
sum += rec.get('highF');
});
mean = sum / store.getCount();
axis.setLimits({
value: mean,
line: {
title: {
text: 'Average high: ' + mean.toFixed(2) + '°F'
},
lineDash: [2,2]
}
});
},
itemAnimationDuration: 0,
// Disable item's animaton for editing.
onBeginItemEdit: function (chart, interaction, item) {
var itemsMarker = item.sprite.getMarker(item.category),
fx = itemsMarker.getTemplate().fx; // animation modifier
this.itemAnimationDuration = fx.getDuration();
fx.setDuration(0);
},
// Restore item's animation when editing is done.
onEndItemEdit: function (chart, interaction, item, target) {
var itemsMarker = item.sprite.getMarker(item.category),
fx = itemsMarker.getTemplate().fx;
fx.setDuration(this.itemAnimationDuration);
}
});