diff --git a/demos/index.php b/demos/index.php index fe3e7de..f0c0289 100644 --- a/demos/index.php +++ b/demos/index.php @@ -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')); }); diff --git a/src/Chart.php b/src/Chart.php index 530769a..38093de 100644 --- a/src/Chart.php +++ b/src/Chart.php @@ -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]), ]), ], ], diff --git a/src/PieChart.php b/src/PieChart.php index 67a0125..9741b64 100644 --- a/src/PieChart.php +++ b/src/PieChart.php @@ -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]), ]), ], ], diff --git a/src/ScatterChart.php b/src/ScatterChart.php index 5cc1f32..25cf96c 100644 --- a/src/ScatterChart.php +++ b/src/ScatterChart.php @@ -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]), ]), ], ],