timbod7 / haskell-chart

A 2D charting library for haskell
430 stars 85 forks source link

Discrete bar chart labels #175

Open zpalmtree opened 7 years ago

zpalmtree commented 7 years ago

Hiya,

I'm using your chart library to make a bar chart, and it works great, except for one thing - I can't work out how to make every bar labeled. I'm sure this is pretty easy, but I always find libraries which use lens a lot quite hard to decipher. Here's my code:

chart :: Map Card Int -> Renderable ()
chart mapping = toRenderable layout
    where barChart = plot_bars_values .~ addIndexes y_axis_values
                   $ def

          layout = layout_title .~ "Number of cards drawn"
                 $ layout_x_axis . laxis_generate .~ autoIndexAxis x_axis_labels
                 $ layout_plots .~ [plotBars barChart]
                 $ def

          list = toAscList mapping
          x_axis_labels = map (show . fst) list
          y_axis_values = map (\x -> [snd x]) list

And here's what it looks like:

shuffle tester_001

I want each bar to be labelled with it's card name, whereas at the moment it looks like it's creating a range and labeling one every so often. I imagine it'll be a bit cramped with every card being labelled, but I'll handle that when I get to it.

Thanks.

timbod7 commented 6 years ago

There's logic inside the axis display code that decides which labels to show such that there are no overlaps. I'd be happy to accept a PR to make this behaviour optional.

zpalmtree commented 6 years ago

@timbod7 Thanks for the reply. Is it possible to make the labels vertical to save space instead?

zpalmtree commented 6 years ago

For now I just worked around it by condensing my labels and increasing the chart size, which works OK.

shuffle tester_001