Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Line Chart ticks.callback being overriden when passed in #158

Open
zenlex opened this issue May 8, 2023 · 1 comment
Open

[BUG] Line Chart ticks.callback being overriden when passed in #158

zenlex opened this issue May 8, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@zenlex
Copy link

zenlex commented May 8, 2023

Describe the bug
I've passed in a custom callback to a Line Chart for the yAxes tick labels and it is being ignored.

To Reproduce
Steps to reproduce the behavior:

  1. Set ->options('scales => [ 'yAxes' => ['ticks' => ['callback' => 'function(value){return '$' + value}']]]) (or any other callback)

Expected behavior
Y-axis tick labels should be customized based on the callback return value

Screenshots
If applicable, add screenshots to help explain your problem.

Dependencies Version (please complete the following information):

  • Laravel Version: 9.11
  • Nova Version: 4.22
  • Nova-ChartJS Version: 0.4.0

Desktop (please complete the following information):

  • OS: Mac OS
  • Browser firefox
  • Version

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.
I believe the issue is that in the underlying StripeChart.vue on line 126, ticks.callback is being set to a default implementation AFTER ...this.card.options.scales?.yAxes?.ticks || {} is set on line 121, so any attempt to set the callback would be overwritten by the default implementation. Setting the default implementation first before the spread or checking for the existence of one before overwriting should fix this I believe. I did not look at the other chart types to see if the problem was consistent.

@zenlex zenlex added the bug Something isn't working label May 8, 2023
@zenlex
Copy link
Author

zenlex commented May 9, 2023

Confirmed was able to fix it in a test case by adding the following after this.options gets set in fillData()

  // custom callback override
		  if(this.options.scales?.yAxes?.ticks?.callback != undefined && this.options.scales.yAxes.ticks.callback.search("function") != -1){
			  eval("this.options.scales.yAxes.ticks.callback="+this.options.scales.yAxes.ticks.callback);
		  }

Looks like this is common across many if not all the components that have this option. Happy to open a PR if desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant