GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( f7eb78...e47b21 )
by James
13:02 queued 08:20
created

charts.defaults.js ➔ formatLabel   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
dl 0
loc 44
rs 8.8571
nop 2

1 Function

Rating   Name   Duplication   Size   Complexity  
B charts.defaults.js ➔ ... ➔ words.forEach 0 36 6
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) {
0 ignored issues
show
Unused Code introduced by
The parameter values is not used and could be removed.

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.

Loading history...
Unused Code introduced by
The parameter index is not used and could be removed.

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.

Loading history...
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
};