'use strict'; Ox.Chart = function(options, self) { self = self || {}; var that = Ox.Element({}, self) .defaults({ color: [128, 128, 128], data: {}, formatKey: null, keyAlign: 'right', keyWidth: 128, rows: 1, sort: {key: 'value', operator: '-'}, title: '', width: 512 }) .options(options || {}) .addClass('OxChart') .css({ width: self.options.width + 'px', height: 16 + Ox.len(self.options.data) * 16 + 'px', overflowY: 'hidden' }); self.sort = {}; Ox.forEach(self.options.data, function(value, key) { self.sort[key] = key.replace(/(\d+)/g, function(number) { return Ox.pad(number, 16); }); }); self.keys = Object.keys(self.options.data); self.items = self.keys.map(function(key) { return {key: key, value: self.options.data[key]}; }) .sort(function(a, b) { var key = self.options.sort.key, aValue = key == 'key' ? self.sort[a.key] : a.value, bValue = key == 'key' ? self.sort[b.key] : b.value; return aValue < bValue ? (self.options.sort.operator == '+' ? -1 : 1) : aValue > bValue ? (self.options.sort.operator == '+' ? 1 : -1) : self.sort[a.key] < self.sort[b.key] ? -1 : self.sort[a.key] > self.sort[b.key] ? 1 : 0; }); self.values = self.items.map(function(item) { return item.value; }); self.max = Ox.max(self.values); self.sum = Ox.sum(self.values); self.valueWidth = self.options.width - self.options.keyWidth; self.$title = Ox.Bar({size: 16}) .append( $('