mirror of
https://github.com/gwenhael-le-moine/ledgerrb.git
synced 2024-12-26 09:59:18 +01:00
cut in 2 components
Signed-off-by: Gwenhael Le Moine <gwenhael.le.moine@gmail.com>
This commit is contained in:
parent
3904fe8bf7
commit
27250b6fe1
2 changed files with 121 additions and 0 deletions
98
public/app/ts/components/bucket.ts
Normal file
98
public/app/ts/components/bucket.ts
Normal file
|
@ -0,0 +1,98 @@
|
|||
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
|
||||
}
|
||||
};
|
||||
|
||||
ctrl.$onChanges = (changes) => {
|
||||
if (changes.period && changes.period.currentValue != undefined) {
|
||||
API.balance({
|
||||
period: ctrl.period,
|
||||
categories: ctrl.categories,
|
||||
depth: ctrl.depth
|
||||
})
|
||||
.then((response) => {
|
||||
ctrl.raw_data = _(response.data)
|
||||
.sortBy((account) => { return account.amount; })
|
||||
.reverse();
|
||||
ctrl.raw_total = _(response.data).reduce((memo, account) => { return memo + account.amount; }, 0);
|
||||
|
||||
ctrl.total_detailed = _.chain(ctrl.raw_data)
|
||||
.groupBy((account) => {
|
||||
return account.account.split(':')[0];
|
||||
})
|
||||
.each((category) => {
|
||||
category.total = _(category).reduce((memo, account) => {
|
||||
return memo + account.amount;
|
||||
}, 0);
|
||||
})
|
||||
.value();
|
||||
ctrl.total_detailed = _.chain(ctrl.total_detailed)
|
||||
.keys()
|
||||
.map((key) => {
|
||||
return {
|
||||
account: key,
|
||||
amount: ctrl.total_detailed[key].total
|
||||
};
|
||||
})
|
||||
.value();
|
||||
|
||||
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: `
|
||||
<div class="bucket">
|
||||
<div class="tollbar">
|
||||
<span ng:repeat="account in $ctrl.total_detailed">{{account.account}} = {{account.amount | number:2}} €</span>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="graph">
|
||||
<nvd3 data="$ctrl.data"
|
||||
options="$ctrl.graph_options">
|
||||
</nvd3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
});
|
23
public/app/tsfmt.json
Normal file
23
public/app/tsfmt.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"baseIndentSize": 0,
|
||||
"indentSize": 2,
|
||||
"tabSize": 2,
|
||||
"indentStyle": 2,
|
||||
"newLineCharacter": "\n",
|
||||
"convertTabsToSpaces": true,
|
||||
"insertSpaceAfterCommaDelimiter": true,
|
||||
"insertSpaceAfterSemicolonInForStatements": true,
|
||||
"insertSpaceBeforeAndAfterBinaryOperators": true,
|
||||
"insertSpaceAfterConstructor": false,
|
||||
"insertSpaceAfterKeywordsInControlFlowStatements": true,
|
||||
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
|
||||
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": true,
|
||||
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": true,
|
||||
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
|
||||
"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": true,
|
||||
"insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": true,
|
||||
"insertSpaceAfterTypeAssertion": true,
|
||||
"insertSpaceBeforeFunctionParenthesis": false,
|
||||
"placeOpenBraceOnNewLineForFunctions": false,
|
||||
"placeOpenBraceOnNewLineForControlBlocks": false,
|
||||
}
|
Loading…
Reference in a new issue