defmodule MicrowavepropWeb.Components.SkewTChart do @moduledoc """ Function component that renders a skew-T log-P diagram from a pressure-level profile (list of `%{"pres", "tmpc", "dwpc"}` maps). Returns empty output when the profile has fewer than three usable levels. """ use Phoenix.Component alias MicrowavepropWeb.SkewT attr :profile, :list, required: true @spec skew_t_chart(map()) :: Phoenix.LiveView.Rendered.t() def skew_t_chart(assigns) do chart = SkewT.build(assigns.profile) usable_points = if chart, do: length(chart.t_points), else: 0 assigns = assign(assigns, chart: chart, usable_points: usable_points) ~H"""
= 2} class="mt-3">
Skew-T log-P
<%!-- Plot background --%> <%!-- Clip background curves to the plot area so skewed lines don't bleed over the axes. --%> <%!-- Dry adiabats (orange curves) --%> <%!-- Mixing ratio lines (dashed teal) --%> <%!-- Isotherms (gray) --%> <%!-- Isobars (gray, across plot) --%> <%!-- Dewpoint trace --%> <%!-- Temperature trace --%> <%!-- Pressure axis labels (left side) --%> {bar.label} <%!-- Temperature axis labels (bottom, only those inside the visible band) --%> = -40 && iso.t_c <= 40 && rem(iso.t_c, 20) == 0} x={iso.label_x} y={iso.label_y} font-size="10" text-anchor="middle" fill="currentColor" class="text-base-content/60" > {iso.t_c}°C <%!-- Legend --%> Temperature Dewpoint
Orange curves: dry adiabats · dashed teal: saturation mixing ratio · thin gray: isotherms and isobars
""" end end