Ox.Chart: add 'limit' option

This commit is contained in:
rlx 2012-10-05 11:19:22 +00:00
parent 83413674a5
commit dc03bb506a

View file

@ -8,6 +8,7 @@ Ox.Chart <f> Bar Chart
formatKey <f|null> Format function for keys formatKey <f|null> Format function for keys
keyAlign <s|'right'> Alignment of keys keyAlign <s|'right'> Alignment of keys
keyWidth <n|128> Width of keys keyWidth <n|128> Width of keys
limit <n|0> Number of items, or 0 for all
rows <n|1> undocumented rows <n|1> undocumented
sort <o|{key: 'value', operator: '-'}> Sort sort <o|{key: 'value', operator: '-'}> Sort
title <s|''> Chart title title <s|''> Chart title
@ -26,6 +27,7 @@ Ox.Chart = function(options, self) {
formatKey: null, formatKey: null,
keyAlign: 'right', keyAlign: 'right',
keyWidth: 128, keyWidth: 128,
limit: 0,
rows: 1, rows: 1,
sort: {key: 'value', operator: '-'}, sort: {key: 'value', operator: '-'},
sortKey: null, sortKey: null,
@ -39,12 +41,7 @@ Ox.Chart = function(options, self) {
renderChart(); renderChart();
} }
}) })
.addClass('OxChart') .addClass('OxChart');
.css({
width: self.options.width + 'px',
height: 16 + Ox.len(self.options.data) * 16 + 'px',
overflowY: 'hidden'
});
self.valueWidth = self.options.width - self.options.keyWidth; self.valueWidth = self.options.width - self.options.keyWidth;
@ -113,6 +110,9 @@ Ox.Chart = function(options, self) {
: key == 'value' && self.sort[a.key] > self.sort[b.key] ? 1 : key == 'value' && self.sort[a.key] > self.sort[b.key] ? 1
: 0; : 0;
}); });
if (self.options.limit) {
self.items = self.items.slice(0, self.options.limit);
}
if (self.options.rows == 2) { if (self.options.rows == 2) {
self.row = 0; self.row = 0;
@ -168,6 +168,11 @@ Ox.Chart = function(options, self) {
} }
function renderChart() { function renderChart() {
that.css({
width: self.options.width + 'px',
height: 16 + self.items.length * 16 + 'px',
overflowY: 'hidden'
});
return Ox.TableList({ return Ox.TableList({
columns: getColumns(), columns: getColumns(),
items: self.items, items: self.items,