Apply format currency to tAxes
This commit is contained in:
parent
bcc97e3d72
commit
68e788505a
@ -95,57 +95,6 @@ trait Charts
|
||||
];
|
||||
}
|
||||
|
||||
public function formatMoney($str){
|
||||
return new Raw(
|
||||
"
|
||||
const moneySettings = {
|
||||
decimal: '" . config('money.' . setting('default.currency') . '.decimal_mark') . "',
|
||||
thousands: '". config('money.' . setting('default.currency') . '.thousands_separator') . "',
|
||||
symbol: '" . config('money.' . setting('default.currency') . '.symbol') . "',
|
||||
isPrefix: '" . config('money.' . setting('default.currency') . '.symbol_first') . "',
|
||||
precision: '" . config('money.' . setting('default.currency') . '.precision') . "',
|
||||
};
|
||||
|
||||
const $str = function (input, opt = moneySettings) {
|
||||
function fixed (precision) {
|
||||
return Math.max(0, Math.min(precision, 20));
|
||||
};
|
||||
|
||||
function toStr(value) {
|
||||
return value ? value.toString() : '';
|
||||
};
|
||||
|
||||
function numbersToCurrency(numbers, precision) {
|
||||
var exp = Math.pow(10, precision);
|
||||
var float = parseFloat(numbers) / exp;
|
||||
|
||||
return float.toFixed(fixed(precision));
|
||||
};
|
||||
|
||||
function joinIntegerAndDecimal (integer, decimal, separator) {
|
||||
return decimal ? integer + separator + decimal : integer;
|
||||
};
|
||||
|
||||
if (typeof input === 'number') {
|
||||
input = input.toFixed(fixed(opt.precision));
|
||||
};
|
||||
|
||||
var negative = input.indexOf('-') >= 0 ? '-' : '';
|
||||
var numbers = toStr(input).replace(/\D+/g, '') || '0';
|
||||
var currency = numbersToCurrency(numbers, opt.precision);
|
||||
var parts = toStr(currency).split('.');
|
||||
var integer = parts[0].replace(/(\d)(?=(?:\d{3})+\b)/gm, opt.thousands);;
|
||||
var decimal = parts[1];
|
||||
|
||||
if(opt.isPrefix) {
|
||||
return opt.symbol + negative + joinIntegerAndDecimal(integer, decimal, opt.decimal)
|
||||
}
|
||||
|
||||
return negative + joinIntegerAndDecimal(integer, decimal, opt.decimal) + opt.suffix;
|
||||
}"
|
||||
);
|
||||
}
|
||||
|
||||
public function getLineChartOptions()
|
||||
{
|
||||
return [
|
||||
@ -160,6 +109,52 @@ trait Charts
|
||||
'position' => 'nearest',
|
||||
'callbacks' => [
|
||||
'label' => new Raw("function(tooltipItem, data) {
|
||||
const moneySettings = {
|
||||
decimal: '" . config('money.' . setting('default.currency') . '.decimal_mark') . "',
|
||||
thousands: '". config('money.' . setting('default.currency') . '.thousands_separator') . "',
|
||||
symbol: '" . config('money.' . setting('default.currency') . '.symbol') . "',
|
||||
isPrefix: '" . config('money.' . setting('default.currency') . '.symbol_first') . "',
|
||||
precision: '" . config('money.' . setting('default.currency') . '.precision') . "',
|
||||
};
|
||||
|
||||
const formattedCurrency = function (input, opt = moneySettings) {
|
||||
function fixed (precision) {
|
||||
return Math.max(0, Math.min(precision, 20));
|
||||
};
|
||||
|
||||
function toStr(value) {
|
||||
return value ? value.toString() : '';
|
||||
};
|
||||
|
||||
function numbersToCurrency(numbers, precision) {
|
||||
var exp = Math.pow(10, precision);
|
||||
var float = parseFloat(numbers) / exp;
|
||||
|
||||
return float.toFixed(fixed(precision));
|
||||
};
|
||||
|
||||
function joinIntegerAndDecimal (integer, decimal, separator) {
|
||||
return decimal ? integer + separator + decimal : integer;
|
||||
};
|
||||
|
||||
if (typeof input === 'number') {
|
||||
input = input.toFixed(fixed(opt.precision));
|
||||
};
|
||||
|
||||
var negative = input.indexOf('-') >= 0 ? '-' : '';
|
||||
var numbers = toStr(input).replace(/\D+/g, '') || '0';
|
||||
var currency = numbersToCurrency(numbers, opt.precision);
|
||||
var parts = toStr(currency).split('.');
|
||||
var integer = parts[0].replace(/(\d)(?=(?:\d{3})+\b)/gm, opt.thousands);;
|
||||
var decimal = parts[1];
|
||||
|
||||
if(opt.isPrefix == 1) {
|
||||
return opt.symbol + negative + joinIntegerAndDecimal(integer, decimal, opt.decimal)
|
||||
}
|
||||
|
||||
return negative + joinIntegerAndDecimal(integer, decimal, opt.decimal) + opt.symbol;
|
||||
};
|
||||
|
||||
return formattedCurrency(tooltipItem.yLabel, moneySettings);
|
||||
}")
|
||||
],
|
||||
@ -169,8 +164,53 @@ trait Charts
|
||||
'ticks' => [
|
||||
'beginAtZero' => true,
|
||||
'callback' => new Raw("function(value, index, values) {
|
||||
|
||||
return '" . config('money.' . setting('default.currency') . '.symbol') . "' + value;
|
||||
const moneySettings = {
|
||||
decimal: '" . config('money.' . setting('default.currency') . '.decimal_mark') . "',
|
||||
thousands: '". config('money.' . setting('default.currency') . '.thousands_separator') . "',
|
||||
symbol: '" . config('money.' . setting('default.currency') . '.symbol') . "',
|
||||
isPrefix: '" . config('money.' . setting('default.currency') . '.symbol_first') . "',
|
||||
precision: '" . config('money.' . setting('default.currency') . '.precision') . "',
|
||||
};
|
||||
|
||||
const formattedCurrency = function (input, opt = moneySettings) {
|
||||
function fixed (precision) {
|
||||
return Math.max(0, Math.min(precision, 20));
|
||||
};
|
||||
|
||||
function toStr(value) {
|
||||
return value ? value.toString() : '';
|
||||
};
|
||||
|
||||
function numbersToCurrency(numbers, precision) {
|
||||
var exp = Math.pow(10, precision);
|
||||
var float = parseFloat(numbers) / exp;
|
||||
|
||||
return float.toFixed(fixed(precision));
|
||||
};
|
||||
|
||||
function joinIntegerAndDecimal (integer, decimal, separator) {
|
||||
return decimal ? integer + separator + decimal : integer;
|
||||
};
|
||||
|
||||
if (typeof input === 'number') {
|
||||
input = input.toFixed(fixed(opt.precision));
|
||||
};
|
||||
|
||||
var negative = input.indexOf('-') >= 0 ? '-' : '';
|
||||
var numbers = toStr(input).replace(/\D+/g, '') || '0';
|
||||
var currency = numbersToCurrency(numbers, opt.precision);
|
||||
var parts = toStr(currency).split('.');
|
||||
var integer = parts[0].replace(/(\d)(?=(?:\d{3})+\b)/gm, opt.thousands);;
|
||||
var decimal = parts[1];
|
||||
|
||||
if(opt.isPrefix == 1) {
|
||||
return opt.symbol + negative + joinIntegerAndDecimal(integer, decimal, opt.decimal)
|
||||
} else {
|
||||
return negative + joinIntegerAndDecimal(integer, decimal, opt.decimal) + opt.symbol;
|
||||
}
|
||||
};
|
||||
|
||||
return formattedCurrency(value, moneySettings);
|
||||
}"),
|
||||
],
|
||||
]
|
||||
@ -182,9 +222,6 @@ trait Charts
|
||||
'ticks' => [
|
||||
'padding' => 10,
|
||||
'fontColor' => '#9e9e9e',
|
||||
'callback' => new Raw("function(value, index, values) {
|
||||
return '" . config('money.' . setting('default.currency') . '.symbol') . "' + value;
|
||||
}"),
|
||||
]],
|
||||
'gridLines' => [
|
||||
'drawBorder' => false,
|
||||
@ -212,4 +249,3 @@ trait Charts
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user