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

Bar element and barchart #31

Merged

Conversation

jamesrswift
Copy link
Collaborator

@jamesrswift jamesrswift commented Aug 1, 2024

Bar elements are reimplemented with a general solution, which allows explicit control over the placement of each bar in a series. The logic governing clustered and stacked bars can be passed onto the chart's implemented instead.

The element

The bar element has the following function signature:

cetz-plot.add.bar(
  data, // Array of unstructured data
  x-key: 0,
  y-key: 1,
  y-base-key: none, // Governs where the bottom of the bar should be drawn (for stacked)
  bar-width: 0.5, // This is the total width of the bar
  label: none,
  style: (:),
  axes: ("x", "y")
)

image

Suggest adding support for controlling the number of points along each edge of the bar, for better rendering in other axis styles (for example, more samples on the top horizontal line would allow it to be curved on a polar-2d axis style).

The chart

Still a work in progress, as I'm taking my time thinking of what people will want to show in a bar chart. I've generally only ever seen bars and error bars, so this is the general case I'll aim to support with the chart (and for more complicated things, it can be constructed manually through plot)

image

To do:

  • Add support for more samples along straight edges of a bar
  • Put more through into legend preview. It currently shows a half height full width box, so that it will be compatible with the error bar legend preview should it be needed.
  • Implement chart
    • Normal
    • Stacked
      • Colouring of stacked bars is not quite what I'd expect in a chart, order of colours in the legend should match top to bottom the order of colours in a stack.
    • Clustered
    • Stacked100
  • Make sure all bar-related sections in the manual are complete and up to date

@jamesrswift jamesrswift mentioned this pull request Aug 1, 2024
27 tasks
@jamesrswift jamesrswift marked this pull request as ready for review August 2, 2024 17:54
@jamesrswift jamesrswift changed the title (W.I.P) Bar element and bar chart Bar element and bar chart Aug 2, 2024
@jamesrswift jamesrswift changed the title Bar element and bar chart Bar element and barchart Aug 2, 2024
Copy link
Member

@johannes-wolf johannes-wolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old chart API had the option to auto size either the width for bars or the height for columns, that is gone, but I think is useful.

Please add (more) tests for clustered bar-charts.

I've got a fix ready for the non-compiling gallery images that depends on this PR.
You can also merge that commit into your branch: #32

src/charts/bar/clustered.typ Outdated Show resolved Hide resolved
src/charts/bar/clustered.typ Outdated Show resolved Hide resolved
src/charts/bar/stacked.typ Outdated Show resolved Hide resolved
src/charts/bar/stacked.typ Show resolved Hide resolved
@jamesrswift
Copy link
Collaborator Author

The old chart API had the option to auto size either the width for bars or the height for columns, that is gone, but I think is useful.

Autosizing would be great, can we add in a future PR, as it applies to charts more generally than just bar charts - and it would probably depend on the axis flipping we discussed

Please add (more) tests for clustered bar-charts.

Incoming :)

I've got a fix ready for the non-compiling gallery images that depends on this PR.
You can also merge that commit into your branch: #32

You know already that I'm a git noob, so suggest we pull that into the aggressive-refactor branch after this is merged

@jamesrswift
Copy link
Collaborator Author

In a future PR, we may want to add a "errorbar-style" arg but I don't think its essential

@johannes-wolf johannes-wolf self-requested a review August 5, 2024 16:51
@johannes-wolf johannes-wolf merged commit 9155ee8 into cetz-package:aggressive-refactoring Aug 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants