Skip to content

Commit

Permalink
Fix JS expression for chart label typo (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrecek234 authored Nov 23, 2023
1 parent 3d59bc4 commit 5148d0a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion demos/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

$m = new Model(new Persistence\Array_($t));
$m->addFields(['name', 'sales_cash', 'sales_bank', 'sales', 'purchases', 'profit']);
$m->onHook(Model::HOOK_AFTER_LOAD, function (Model $m) {
$m->onHook(Model::HOOK_AFTER_LOAD, static function (Model $m) {
$m->set('sales', $m->get('sales_cash') + $m->get('sales_bank'));
$m->set('profit', $m->get('sales') - $m->get('purchases'));
});
Expand Down
10 changes: 5 additions & 5 deletions src/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@ public function setCurrencyLabel(string $char = '€', string $axis = 'y', int $
'callbacks' => [
'label' => new JsFunction(['context'], [
new JsExpression(<<<'EOF'
let label = context.dataset.label || "";
let label = context.dataset.label || '';
// let value = context.parsed.y; // or x (horizontal) or r (radar) etc
let value = context.formattedValue.replace(/,/, "");
let value = context.formattedValue.replace(/,/, '');
if (label) {
label += ": ";
label += ': ';
}
return label + (value ? "' . $char . ' " + Number(value).toLocaleString(undefined, {minimumFractionDigits: ' . $digits . ', maximumFractionDigits: ' . $digits . '}) : "No Data");
EOF),
return label + (value ? [char] + Number(value).toLocaleString(undefined, {minimumFractionDigits: [digits], maximumFractionDigits: [digits]}) : 'No Data');
EOF, ['char' => $char, 'digits' => $digits]),
]),
],
],
Expand Down
10 changes: 5 additions & 5 deletions src/PieChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public function setCurrencyLabel(string $char = '€', string $axis = 'y', int $
'callbacks' => [
'label' => new JsFunction(['context'], [
new JsExpression(<<<'EOF'
let label = context.dataset.label || "";
let label = context.dataset.label || '';
// let value = context.parsed; // y or x (horizontal) or r (radar) etc
let value = context.formattedValue.replace(/,/, "");
let value = context.formattedValue.replace(/,/, '');
if (label) {
label += ": ";
label += ': ';
}
return label + (value ? "' . $char . ' " + Number(value).toLocaleString(undefined, {minimumFractionDigits: ' . $digits . ', maximumFractionDigits: ' . $digits . '}) : "No Data");
EOF),
return label + (value ? [char] + Number(value).toLocaleString(undefined, {minimumFractionDigits: [digits], maximumFractionDigits: [digits]}) : 'No Data');
EOF, ['char' => $char, 'digits' => $digits]),
]),
],
],
Expand Down
8 changes: 4 additions & 4 deletions src/ScatterChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public function setAxisTitles(string $xTitle = null, string $yTitle = null): voi
'callbacks' => [
'label' => new JsFunction(['context'], [
new JsExpression(<<<'EOF'
let label = context.dataset.label || "";
let label = context.dataset.label || '';
let value = context.parsed.y;
if (label) {
label += ": ";
label += ': ';
}
return label + (value ? Number(value).toLocaleString(undefined, {minimumFractionDigits: ' . $digits . ', maximumFractionDigits: ' . $digits . '}) : "No Data");
EOF),
return label + (value ? Number(value).toLocaleString(undefined, {minimumFractionDigits: [digits], maximumFractionDigits: [digits]}) : 'No Data');
EOF, ['digits' => $digits]),
]),
],
],
Expand Down

0 comments on commit 5148d0a

Please sign in to comment.