app.component('dashboard', { controller: ['$filter', 'API', function($filter, API) { let ctrl = this; ctrl.granularity = "monthly"; ctrl.account_selection = "depth"; let is_monthly = () => { return ctrl.granularity == "monthly"; }; ctrl.compute_selected_accounts = () => { ctrl.graphed_accounts = _.chain(ctrl.main_accounts_depths) .map((account) => { if (account.depth < 1) { return null; } else { return _(ctrl.raw_accounts) .select((account2) => { return account2[0] == account.name && account2.length == account.depth; }) .map((account3) => { return account3.join(":"); }); } }) .compact() .flatten() .value(); ctrl.retrieve_graph_values(ctrl.graphed_accounts); }; ctrl.retrieve_graph_values = (categories) => { API.graph_values("", ctrl.granularity, categories.join(" ")) .then((response) => { ctrl.periods = []; _.chain(response.data) .reduce((memo, cat) => { return cat.length > memo.length ? cat : memo; }, []) .pluck('date') .each((date) => { _(response.data).each((cat) => { let value = _(cat).find({ date: date }); if (_(value).isUndefined()) { cat.push({ date: date, amount: 0, currency: _(cat).first().currency }); } }); }) .each((cat) => { cat = _(cat).sortBy((month) => { return month.date; }); }); ctrl.graphique = { options: { chart: { type: 'multiBarChart', height: 450, stacked: true, showControls: true, showLegend: true, showLabels: true, showValues: true, showYAxis: true, duration: 500, reduceXTicks: false, rotateLabels: -67, labelSunbeamLayout: true, useInteractiveGuideline: true, interactiveLayer: { dispatch: { elementClick: (t) => { console.log(ctrl.period) ctrl.period = t.pointXValue; console.log(ctrl.period) } }, tooltip: { contentGenerator: function(e) { let format_line = (serie) => { return `
Total | ${e.series.reduce((memo, serie) => { return memo + serie.value; }, 0)} |