Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Remove default axis overrride when custom ID is given.

Open LeeLenaleee opened this issue 2 years ago • 6 comments

Feature Proposal

Remove the default scale override for x/y axis if a different axis id is given.

In case you want to add a second x axis you need to add an empty x scale object which is weird. Also when adding a custom scale that chart.js does not know the kind of (because of first letter) it does appear as an extra y scale but as soon as you specify the place it replaces the current default x/y scale

Possible Implementation

No response

LeeLenaleee avatar Feb 22 '22 19:02 LeeLenaleee

Also when adding a custom scale that chart.js does not know the kind of (because of first letter) it does appear as an extra y scale but as soon as you specify the place it replaces the current default x/y scale

@LeeLenaleee maybe I'm wrong, but instead of specifying the position (as you have done here https://jsfiddle.net/Leelenaleee/3b27jqah/6/), you could set axis option, axis: 'x' and then you can use whatever ID you want.

stockiNail avatar Feb 22 '22 21:02 stockiNail

No I think you might understand it wrong, tried to explain it a bit better underneath here

Like the example you linked I want to add a second X axis, im totally fine with the original so don't need any config for that. So I add a scale config for axis x2. This would for my feeling create a second x axis or at least a new axis. But instead it overrides the default x scale.

scales: {
  x2: {} // overrides default x so still only 2 scales, 1 x and 1 y scales
}

If I instead make a scale (without any config) with an id that chart.js can not infer the type from like secondX it will create an extra scale and make it a y scale. So I have 2 y scales and 1 x scale. But as soon as I specify the axis field or position field it overrides the default y/x axis again.

scales: {
  secondX: {} // create extra y scale, 1 x and 2 y scales
}
scales: {
  secondX: { // overrides default x so still only 2 scales, 1 x and 1 y scales
    position: 'bottom', // Both the position and axis prop independintly make it override default scale
    axis: 'x'
  }
}

So only way to create a custom new scale (as far as my knowledge goes) is by adding an empty scale object for the default x/y scale which feels verry weird. Especially since if you make a scale ID chart.js cant infer without config to test if it renders it does render but then as soon as you add condig it stops rendering and makes it the default scale.

scales: {
  x: {}, // Feels weird and wrong that this needs to be done
  x2: {
    // All config
  }
}

LeeLenaleee avatar Feb 22 '22 23:02 LeeLenaleee

@LeeLenaleee sorry I misunderstood that and now it's clear! I didn't recognize that the second axis will override the default one and you are definitely right. I had the doubt about the usage of position instead of axis option.

stockiNail avatar Feb 23 '22 07:02 stockiNail

@LeeLenaleee I was thinking about this issue. Maybe you should remove the default scale override because I have seen many users which are using CHART.JS, assuming that this is the behavior. Nevertheless I agree with you that it's annoying to add an "empty" scale definition, only to maintain the default one.

Maybe new option could be added to the cartesian scales (for instance override or overrideDefault) where the user can specify that the new scales are on top to the default one.

override?: boolean // default `true`, as is today. In this way it could not be a breaking change

stockiNail avatar Feb 23 '22 19:02 stockiNail

when adding a custom scale that chart.js does not know the kind of (because of first letter) it does appear as an extra y scale

This one is a bug, it should override the default y-scale in that case (per current design).

kurkle avatar Feb 23 '22 19:02 kurkle

@LeeLenaleee @stockiNail @kurkle Hi guys. Could you please finalize the decision about this issue?

  • should we disable override at all?
  • do it by override option?
  • ...

dangreen avatar Jul 29 '22 09:07 dangreen

@LeeLenaleee @stockiNail @kurkle ping

dangreen avatar Aug 12 '22 19:08 dangreen

My preference goes to removing it so any scale ID except for x/y creates a second scale next to the main one.

@etimberg what is your opinion on this?

LeeLenaleee avatar Aug 12 '22 20:08 LeeLenaleee

If I understand correctly @LeeLenaleee this would create two x and two y axes:

const options = {
  scales: {
    x2: { type: 'category' },
    y2: { type: 'linear; },
  }
}

I think that could make sense. my one concern is that it makes upgrades harder to do because if someone set an ID before it will change and there's no way to have the case above make 2 axes because you can't delete x and y

etimberg avatar Aug 12 '22 22:08 etimberg

yes your config would indeed make 2 x and 2 y axes with the proposed change.

So if we do this I think we need to make it verry clear at the top of the migration guide.

LeeLenaleee avatar Aug 13 '22 06:08 LeeLenaleee

I encountered an example chart that was affected by this: v3 https://codepen.io/kurkle/pen/gOzzPvE v4 https://codepen.io/kurkle/pen/ExxdyXQ

Now you'd need to display: false on the unused default scales. Maybe we should at least change the display default to 'auto'?

kurkle avatar Oct 01 '22 10:10 kurkle