app.component('bucket', { bindings: { categories: '<', period: '<' }, controller: ['$filter', 'API', function($filter, API) { let ctrl = this; ctrl.depth = 99; ctrl.graph_options = { chart: { type: 'multiBarHorizontalChart', height: 600, margin: { top: 20, right: 20, bottom: 20, left: 200 }, x: (d) => { return d.account; }, y: (d) => { return d.amount; }, valueFormat: (d) => { return `${d} €`; }, showYAxis: false, showValues: true, showLegend: true, showControls: false, showTooltipPercent: true, duration: 500, labelThreshold: 0.01, labelSunbeamLayout: true, labelsOutside: true, multibar: { dispatch: { elementClick: (event) => { API.register(ctrl.period, event.data.account) .then(function success(response) { let format_transaction = (transaction) => { return ` ${transaction.date} ${transaction.payee} ${transaction.amount} ${transaction.currency} `; }; swal({ title: response.data.key, html: ` ${response.data.values.map(function(transaction) { return format_transaction(transaction); }).join("")}
DatePayeeAmount
Total${event.data.amount} €
`}); }, function error(response) { alert("error!"); }); } } } } }; ctrl.$onChanges = (changes) => { if (changes.period && changes.period.currentValue != undefined) { API.balance(ctrl.period, ctrl.categories, ctrl.depth) .then((response) => { ctrl.raw_data = _(response.data) .sortBy((account) => { return account.name; }); ctrl.graph_options.chart.height = 60 + (25 * ctrl.raw_data.length); ctrl.data = ctrl.categories.split(' ').map((category) => { return { key: category, values: _(ctrl.raw_data).select((line) => { return line.account.match(`^${category}:.*`); }) } }) }); } }; } ], template: `
` });