1
|
|
|
/* |
2
|
|
|
* charts.defaults.js |
3
|
|
|
* Copyright (c) 2017 [email protected] |
4
|
|
|
* |
5
|
|
|
* This file is part of Firefly III. |
6
|
|
|
* |
7
|
|
|
* Firefly III is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* Firefly III is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
/** global: accounting */ |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Takes a string phrase and breaks it into separate phrases no bigger than 'maxwidth', breaks are made at complete words. |
26
|
|
|
* https://stackoverflow.com/questions/21409717/chart-js-and-long-labels |
27
|
|
|
* |
28
|
|
|
* @param str |
29
|
|
|
* @param maxwidth |
30
|
|
|
* @returns {Array} |
31
|
|
|
*/ |
32
|
|
|
function formatLabel(str, maxwidth){ |
33
|
|
|
var sections = []; |
34
|
|
|
var words = str.split(" "); |
35
|
|
|
var temp = ""; |
36
|
|
|
|
37
|
|
|
words.forEach(function(item, index){ |
38
|
|
|
if(temp.length > 0) |
39
|
|
|
{ |
40
|
|
|
var concat = temp + ' ' + item; |
41
|
|
|
|
42
|
|
|
if(concat.length > maxwidth){ |
43
|
|
|
sections.push(temp); |
44
|
|
|
temp = ""; |
45
|
|
|
} |
46
|
|
|
else{ |
47
|
|
|
if(index === (words.length-1)) |
48
|
|
|
{ |
49
|
|
|
sections.push(concat); |
50
|
|
|
return; |
51
|
|
|
} |
52
|
|
|
else{ |
53
|
|
|
temp = concat; |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if(index === (words.length-1)) |
60
|
|
|
{ |
61
|
|
|
sections.push(item); |
62
|
|
|
return; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if(item.length < maxwidth) { |
66
|
|
|
temp = item; |
67
|
|
|
} |
68
|
|
|
else { |
69
|
|
|
sections.push(item); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
}); |
73
|
|
|
|
74
|
|
|
return sections; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
var defaultChartOptions = { |
78
|
|
|
elements: { |
79
|
|
|
line: { |
80
|
|
|
cubicInterpolationMode: 'monotone' |
81
|
|
|
} |
82
|
|
|
}, |
83
|
|
|
scales: { |
84
|
|
|
xAxes: [ |
85
|
|
|
{ |
86
|
|
|
gridLines: { |
87
|
|
|
display: false |
88
|
|
|
}, |
89
|
|
|
ticks: { |
90
|
|
|
// Include a dollar sign in the ticks |
91
|
|
|
callback: function (value, index, values) { |
|
|
|
|
92
|
|
|
return formatLabel(value, 20); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
], |
97
|
|
|
yAxes: [{ |
98
|
|
|
display: true, |
99
|
|
|
ticks: { |
100
|
|
|
callback: function (tickValue) { |
101
|
|
|
"use strict"; |
102
|
|
|
return accounting.formatMoney(tickValue); |
103
|
|
|
|
104
|
|
|
}, |
105
|
|
|
beginAtZero: true |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
}] |
109
|
|
|
}, |
110
|
|
|
tooltips: { |
111
|
|
|
mode: 'label', |
112
|
|
|
callbacks: { |
113
|
|
|
label: function (tooltipItem, data) { |
114
|
|
|
"use strict"; |
115
|
|
|
return data.datasets[tooltipItem.datasetIndex].label + ': ' + |
116
|
|
|
accounting.formatMoney(tooltipItem.yLabel, data.datasets[tooltipItem.datasetIndex].currency_symbol); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
}; |
121
|
|
|
|
122
|
|
|
var defaultPieOptions = { |
123
|
|
|
tooltips: { |
124
|
|
|
callbacks: { |
125
|
|
|
label: function (tooltipItem, data) { |
126
|
|
|
"use strict"; |
127
|
|
|
var value = data.datasets[0].data[tooltipItem.index]; |
128
|
|
|
return data.labels[tooltipItem.index] + ': ' + accounting.formatMoney(value); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
}, |
132
|
|
|
maintainAspectRatio: true, |
133
|
|
|
responsive: true |
134
|
|
|
}; |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.