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

Add Plotting + Chart Library #92

Merged
merged 37 commits into from
Jul 27, 2023
Merged

Add Plotting + Chart Library #92

merged 37 commits into from
Jul 27, 2023

Conversation

johannes-wolf
Copy link
Member

@johannes-wolf johannes-wolf commented Jul 21, 2023

This PR adds a plotting plot, chart, axes and palette library.

@johannes-wolf johannes-wolf added the feature 🎁 Feature Request label Jul 26, 2023
@johannes-wolf johannes-wolf changed the title Add Plotting Library Add Plotting + Chart Library Jul 26, 2023
manual.typ Show resolved Hide resolved
manual.typ Outdated Show resolved Hide resolved
plot.typ Outdated Show resolved Hide resolved
plot.typ Outdated Show resolved Hide resolved
plot.typ Outdated Show resolved Hide resolved
manual.typ Outdated Show resolved Hide resolved
manual.typ Outdated Show resolved Hide resolved
manual.typ Outdated Show resolved Hide resolved
manual.typ Outdated Show resolved Hide resolved
manual.typ Outdated
Comment on lines 1262 to 1436
#def-arg("epigraph", "b",
[If true, fill the epigraph of the function (style key: `epigraph`)])
#def-arg("hypograph", "b",
[If true, fill the hypograph of the function (style key: `hypograph`)])
#def-arg("fill", "b",
[If true, fill the function (style key: `fill`)])
Copy link
Member

Choose a reason for hiding this comment

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

Could these options be set through style, if the fill is none the filling operation doesn't occur?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was wondering how to use style in code where we have no context, as we can not get inherited style values. This means using style would not work as expected.

I have changed this a bit in the new version.

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking a bit more about this and I think we have a children-ctx key that should be a function that accepts ctx. We could allow a group's body be that function.

Copy link
Member Author

@johannes-wolf johannes-wolf Jul 26, 2023

Choose a reason for hiding this comment

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

This is already possible, by just passing a function to a group.
But how should e.g. epigraph be set? like set-style(plot: (epigraph: red))?

Copy link
Member

@fenjalien fenjalien left a comment

Choose a reason for hiding this comment

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

The api feels a lot cleaner now and wow thoughs graphs :) However it would be good to get the styling to work in a similar manner to set-style.

I've focused my review mostly on the design of the api in the manual. I don't mind how its been implemented in the lib files unless there is something specific you want me to look over.

manual.typ Outdated
```

Note: You can pass `content` a function of the form `ctx => array` that returns the groups children. This way you get access to the groups context object.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think having the return type array is very clear as we don't explain anywhere that actually the draw functions return arrays that implicitly get joined. I also think we should rename content to body as you can't use Typst's content. Maybe just say "body can also be function takes a single parameter, a dictionary that describes the group's current context such as styling".

We should also start making some separate developer documentation for the context dictionary but I'm not to bothered about it right now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but we should first generate function docs from the code doc. I do not like having both.

manual.typ Outdated Show resolved Hide resolved
manual.typ Outdated
Comment on lines 1398 to 1412
#def-arg("axis-style", "s?",
[Axis style, either "scientific" or "school-book"])
#def-arg("..options", "any",
[Axis options in the form `<axis-name>-<option>`. The possible options are:
#box[
/ label : The axis label
/ min: Axis min. value
/ max: Axis max. value
/ ticks: List of tick values or value/label tuples
/ tick-step: Tick step or `none`
/ minor-tick-step: Minor tick step or `none`
/ decimals: Number of tick label decimal digits
/ unit: Tick label suffix
]
])
Copy link
Member

Choose a reason for hiding this comment

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

Could the axes use a similar input to styling? As in nested dictionaries:

plot(
  axes: (
    x: (
      label: "X",
      ...
     ),
    y: ...
  )
)

You could then allow options to be applied to both axes by allowing them in the base of the axes dict or through a default dict.

plot(
  axes: (
   // Applies to all axes
  ticks: ...
   // or if you want to keep axis names clear
   default: (
      ticks: ...
    ),
   // An axis
    y: ...
  )
)

This might even allow them to be set through set-style?t

Copy link
Member

Choose a reason for hiding this comment

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

You might also want to group tick options like step, minor-step, values etc.

Copy link
Member Author

@johannes-wolf johannes-wolf Jul 26, 2023

Choose a reason for hiding this comment

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

I am not sure if that is good, as it comes with no real benefit. Tikz also uses this "flat" approach, which I find is fast to type and looks a bit cleaner.

manual.typ Outdated Show resolved Hide resolved
manual.typ Outdated Show resolved Hide resolved
manual.typ Outdated Show resolved Hide resolved
manual.typ Show resolved Hide resolved
tests/chart/test.typ Outdated Show resolved Hide resolved
tests/plot/ref.png Outdated Show resolved Hide resolved
gallery/barchart.typ Outdated Show resolved Hide resolved
@johannes-wolf johannes-wolf force-pushed the plotting-lib branch 3 times, most recently from 8ba953b to db0ad40 Compare July 26, 2023 17:55
@johannes-wolf johannes-wolf merged commit 7e00ead into master Jul 27, 2023
2 checks passed
@johannes-wolf johannes-wolf deleted the plotting-lib branch July 27, 2023 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🎁 Feature Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants