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 | str = String(str); |
||
35 | var words = str.split(" "); |
||
36 | var temp = ""; |
||
37 | |||
38 | words.forEach(function (item, index) { |
||
39 | if (temp.length > 0) { |
||
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 | sections.push(concat); |
||
49 | return; |
||
50 | } |
||
51 | else { |
||
52 | temp = concat; |
||
53 | return; |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | |||
58 | if (index === (words.length - 1)) { |
||
59 | sections.push(item); |
||
60 | return; |
||
61 | } |
||
62 | |||
63 | if (item.length < maxwidth) { |
||
64 | temp = item; |
||
65 | } |
||
66 | else { |
||
67 | sections.push(item); |
||
68 | } |
||
69 | |||
70 | }); |
||
71 | |||
72 | return sections; |
||
73 | } |
||
74 | |||
75 | var defaultChartOptions = { |
||
76 | elements: { |
||
77 | line: { |
||
78 | cubicInterpolationMode: 'monotone' |
||
79 | } |
||
80 | }, |
||
81 | scales: { |
||
82 | xAxes: [ |
||
83 | { |
||
84 | gridLines: { |
||
85 | display: false |
||
86 | }, |
||
87 | ticks: { |
||
88 | // Include a dollar sign in the ticks |
||
89 | callback: function (value, index, values) { |
||
0 ignored issues
–
show
|
|||
90 | return formatLabel(value, 20); |
||
91 | } |
||
92 | } |
||
93 | } |
||
94 | ], |
||
95 | yAxes: [{ |
||
96 | display: true, |
||
97 | ticks: { |
||
98 | callback: function (tickValue) { |
||
99 | "use strict"; |
||
100 | return accounting.formatMoney(tickValue); |
||
101 | |||
102 | }, |
||
103 | beginAtZero: true |
||
104 | } |
||
105 | |||
106 | }] |
||
107 | }, |
||
108 | tooltips: { |
||
109 | mode: 'label', |
||
110 | callbacks: { |
||
111 | label: function (tooltipItem, data) { |
||
112 | "use strict"; |
||
113 | return data.datasets[tooltipItem.datasetIndex].label + ': ' + |
||
114 | accounting.formatMoney(tooltipItem.yLabel, data.datasets[tooltipItem.datasetIndex].currency_symbol); |
||
115 | } |
||
116 | } |
||
117 | } |
||
118 | }; |
||
119 | |||
120 | var defaultPieOptions = { |
||
121 | tooltips: { |
||
122 | callbacks: { |
||
123 | label: function (tooltipItem, data) { |
||
124 | "use strict"; |
||
125 | var value = data.datasets[0].data[tooltipItem.index]; |
||
126 | return data.labels[tooltipItem.index] + ': ' + accounting.formatMoney(value); |
||
127 | } |
||
128 | } |
||
129 | }, |
||
130 | maintainAspectRatio: true, |
||
131 | responsive: true |
||
132 | }; |
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.