2016-12-23 07:02:45 +01:00
|
|
|
/*
|
|
|
|
* charts.defaults.js
|
2017-10-21 08:40:00 +02:00
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
2016-12-23 07:02:45 +01:00
|
|
|
*
|
2017-10-21 08:40:00 +02:00
|
|
|
* This file is part of Firefly III.
|
2016-12-23 07:02:45 +01:00
|
|
|
*
|
2017-10-21 08:40:00 +02:00
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2016-12-23 07:02:45 +01:00
|
|
|
*/
|
|
|
|
|
2017-01-02 10:34:01 +01:00
|
|
|
/** global: accounting */
|
|
|
|
|
2017-12-03 09:27:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes a string phrase and breaks it into separate phrases no bigger than 'maxwidth', breaks are made at complete words.
|
|
|
|
* https://stackoverflow.com/questions/21409717/chart-js-and-long-labels
|
|
|
|
*
|
|
|
|
* @param str
|
|
|
|
* @param maxwidth
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
|
|
|
function formatLabel(str, maxwidth){
|
|
|
|
var sections = [];
|
|
|
|
var words = str.split(" ");
|
|
|
|
var temp = "";
|
|
|
|
|
|
|
|
words.forEach(function(item, index){
|
|
|
|
if(temp.length > 0)
|
|
|
|
{
|
|
|
|
var concat = temp + ' ' + item;
|
|
|
|
|
|
|
|
if(concat.length > maxwidth){
|
|
|
|
sections.push(temp);
|
|
|
|
temp = "";
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if(index === (words.length-1))
|
|
|
|
{
|
|
|
|
sections.push(concat);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
temp = concat;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(index === (words.length-1))
|
|
|
|
{
|
|
|
|
sections.push(item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(item.length < maxwidth) {
|
|
|
|
temp = item;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sections.push(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return sections;
|
|
|
|
}
|
|
|
|
|
2016-11-16 20:35:25 +01:00
|
|
|
var defaultChartOptions = {
|
2017-02-11 17:38:04 -03:00
|
|
|
elements: {
|
2017-02-12 12:21:44 +01:00
|
|
|
line: {
|
2017-02-11 17:38:04 -03:00
|
|
|
cubicInterpolationMode: 'monotone'
|
|
|
|
}
|
|
|
|
},
|
2016-11-16 20:35:25 +01:00
|
|
|
scales: {
|
|
|
|
xAxes: [
|
|
|
|
{
|
|
|
|
gridLines: {
|
|
|
|
display: false
|
2017-12-03 09:27:54 +01:00
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
// Include a dollar sign in the ticks
|
|
|
|
callback: function (value, index, values) {
|
|
|
|
return formatLabel(value, 20);
|
|
|
|
}
|
2016-11-16 20:35:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
yAxes: [{
|
|
|
|
display: true,
|
|
|
|
ticks: {
|
2017-01-02 10:34:01 +01:00
|
|
|
callback: function (tickValue) {
|
2016-11-16 20:35:25 +01:00
|
|
|
"use strict";
|
|
|
|
return accounting.formatMoney(tickValue);
|
|
|
|
|
|
|
|
},
|
|
|
|
beginAtZero: true
|
|
|
|
}
|
|
|
|
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
tooltips: {
|
|
|
|
mode: 'label',
|
|
|
|
callbacks: {
|
|
|
|
label: function (tooltipItem, data) {
|
|
|
|
"use strict";
|
2017-04-15 17:26:03 +02:00
|
|
|
return data.datasets[tooltipItem.datasetIndex].label + ': ' +
|
|
|
|
accounting.formatMoney(tooltipItem.yLabel, data.datasets[tooltipItem.datasetIndex].currency_symbol);
|
2016-11-16 20:35:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var defaultPieOptions = {
|
|
|
|
tooltips: {
|
|
|
|
callbacks: {
|
|
|
|
label: function (tooltipItem, data) {
|
|
|
|
"use strict";
|
|
|
|
var value = data.datasets[0].data[tooltipItem.index];
|
|
|
|
return data.labels[tooltipItem.index] + ': ' + accounting.formatMoney(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
maintainAspectRatio: true,
|
|
|
|
responsive: true
|
|
|
|
};
|