Skip to content

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.

2 participants