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

Add a way to control X axis width in rotated mode

Open m-gallesio opened this issue 1 year ago • 7 comments

Description

There does not seem to be a way to control the width of the X axis when the rotated flag is set to true. This is important when using long category labels. The equivalent in non-rotated mode should be axis.x.height which does work, but has no apparent effect in rotated mode.

Steps to check or reproduce

immagine

import "billboard.js/dist/billboard.css";
import bb from "billboard.js";

bb.generate({
  data: {
    x: "x",
    columns: [
	["x", "Some long category text which will be wrapped", "Some other very long category text", "Yet another long category name", "Again, a long category name"],
	["One", 30, 200, 100, 400],
	["Two", 90, 100, 140, 200]
    ],
    type: "bar",
  },
  axis: {
    rotated: true,
    x: {
      height: 100,
      type: "category"
    }
  },
  padding: {
    left: 200,
  },
  bindto: "#categoryData"
});

m-gallesio avatar Dec 06 '23 08:12 m-gallesio

@m-gallesio as the example provided, padding=200 will behave similarly as "axis.x.width", where will make have some space.

Probably if you need to display x axis text fully without line breaks, you can use axis.x.tick.multiline=false option.

image

netil avatar Dec 08 '23 02:12 netil

The problem with padding is that the free space is not optimized. I added it in the sample code to show how narrow the actually allocated space is. In our actual use case the (customer-provided) labels can be even longer than those I gave as samples, so just disabling multiline would not solve all cases.

m-gallesio avatar Dec 13 '23 13:12 m-gallesio

how about setting as padding.mode='fit'? Setting as is, will make chart elements to fully occupy the container. If needs add some space, can adjust by giving padding.left value and in this case the value will be applied relative from the initial(mode='fit') state.

  • https://jsfiddle.net/netil/k2eaLs7q/

netil avatar Dec 13 '23 13:12 netil

It does not really solve the underlying problem, which is an unbalancedly small space for the label Another approach I tried is using combining multiline with manual \ns instead of relying on the library to split the text, but multiline just ignores them.

m-gallesio avatar Dec 13 '23 13:12 m-gallesio

@m-gallesio, maybe there's misunderstanding on this. As the issue title "way to control X axis width in rotated mode",

image

if some option axis.x.width is provide, and assume setting width of x axis as below image

I don't get any visual difference on giving left padding. image

Can you provide a visual description? What is the usability for axis.x.width option?

netil avatar Dec 14 '23 02:12 netil

Making sure the text fills as much as the allocated space as possible: billboard_category_axis

m-gallesio avatar Dec 14 '23 08:12 m-gallesio

@m-gallesio, for that reason you can use axis.x.tick.width option.

  • https://jsfiddle.net/6gbt4syx/2/

netil avatar Jan 05 '24 06:01 netil

It works, thank you for your attention and sorry for the late response.

m-gallesio avatar Mar 08 '24 08:03 m-gallesio