vega-lite icon indicating copy to clipboard operation
vega-lite copied to clipboard

Time unit marks repeat unnecessarily on the axis

Open colmanhumphrey opened this issue 2 years ago • 6 comments

When plotting by say Year or Quarter, the axis marks will often just repeat the same thing multiple times, when that seems to provide no benefit.

Here's an example:

CleanShot 2022-06-08 at 12 59 17@2x

I'm plotting distinct counts (here, the same as just counts) against year. You can see that the x-axis has 2021 2021 2021 2021 2022 2022 etc. Similarly if you change the time unit to quarter you see the same thing:

CleanShot 2022-06-08 at 13 00 51@2x

Thanks!

colmanhumphrey avatar Jun 08 '22 17:06 colmanhumphrey

No idea if this is a bug or not but you can get your desired behaviour by changing the type to ordinal.

Editor

image

PBI-David avatar Jun 08 '22 17:06 PBI-David

Thanks @PBI-David , definitely avoids the problem here, although if you have a gap in the middle, it's ignored, e.g. if you have no Q3, it just goes straight from Q2 to Q4:

CleanShot 2022-06-08 at 14 42 20@2x

(link)

But temporal does what I consider the right thing here (maybe):

CleanShot 2022-06-08 at 14 43 04@2x

colmanhumphrey avatar Jun 08 '22 18:06 colmanhumphrey

Yeah, fair point. You'd have to back fill your date dimension with a full set of dates for this to work as you want. I'll be interested to hear what the devs have to say.

PBI-David avatar Jun 08 '22 19:06 PBI-David

Actually, tickCount in the axis seems to do the trick.

Editor

image

PBI-David avatar Jun 08 '22 19:06 PBI-David

Oh nice @PBI-David, that's pretty good. Funny that you can do it for quarter too, but the editor complains! So basically the solution here is maybe either some sort of "smarter" defaults, or maybe at least a minimum tick count (bounded by max displayable bars plus one).

colmanhumphrey avatar Jun 08 '22 20:06 colmanhumphrey

Yes, not sure why the editor complains about quarter. I also can't get tickBand:center working for some reason. Let's see what the devs say.

PBI-David avatar Jun 08 '22 20:06 PBI-David