Allow javascript callback for chart options
The idea is by wrapping javascript callback inside !! then we remove the rendered "!! and !!" in the frontend.
For example:
public static ?array $options = [
'scales' => [
'x' => [
'ticks' => [
'callback' => "!!
function(value, index, ticks) {
return '$' + value;
}
!!"
],
],
],
];
I know the code is ugly but if someone can make better PR please do it. Chart.js brings a lot of functionalities through callbacks.
Anyone can improve if !! or create better PR if this is not acceptable.
Well I don't expect too much that this PR will be accepted. At least the idea must go on.
Yeah I'm not going to merge this solution, but I can suggest another that you can implement.
Allow the getOptions() method to return a string instead, and then check if it's a string or an array before passing it to json_encode(). That way the user can provide their own pre-encoded JSON with callbacks and everything, that gets passed directly to the view.