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

Refactor plots #91

Merged
merged 6 commits into from
Nov 29, 2024
Merged

Refactor plots #91

merged 6 commits into from
Nov 29, 2024

Conversation

Peter9192
Copy link
Member

@Peter9192 Peter9192 commented Nov 26, 2024

This PR changes the way plots are constructed. A context manager is introduced that takes care of general sizing and styling of the plots. Indiviual plot elements like legend, axes, (grid)lines, et cetera can can access this context, but their API is limited to only the features that are relevant for them. This leads to a very sleek and modular design, e.g.:

    <ChartContainer>
      <Legend entries={data} />
      <Chart title="Thermodynamic diagram">
        <AxisBottom
          domain={() => [-45, 50]}
          tickValues={temperatureLines}
          tickFormat={d3.format(".0d")}
          label="Temperature [°C]"
        />
        <AxisLeft
          type="log"
          domain={() => [basep, topPressure]}
          tickValues={pressureLines}
          tickFormat={d3.format(".0d")}
          label="Pressure [hPa]"
        />
        <ClipPath />
        <For each={temperatureLines}>{(t) => SkewTGridLine(t)}</For>
        <For each={pressureLines}>{(p) => LogPGridLine(p)}</For>
        <For each={dryAdiabats}>{(d) => DryAdiabat(d)}</For>
        <For each={data()}>{(d) => Sounding(d)}</For>
      </Chart>
    </ChartContainer>

A big advantage of this is that (default) sizing and styling is now done in one place (the chartcontainer), and is consistent across all plot types.

@Peter9192
Copy link
Member Author

Apparently it makes a difference whether you use prop destructuring. Using props.chilren rather than children seems to have fixed the issue.

@Peter9192 Peter9192 marked this pull request as ready for review November 29, 2024 16:13
@Peter9192 Peter9192 merged commit 4337353 into main Nov 29, 2024
4 checks passed
@Peter9192 Peter9192 deleted the refactor-plots branch November 29, 2024 16:15
@Peter9192 Peter9192 mentioned this pull request Jan 13, 2025
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.

1 participant