Skip to content

Commit f2dd8c6

Browse files
committed
Drop seed label on gamut plot and add white-point legend entry
1 parent 9649e67 commit f2dd8c6

5 files changed

Lines changed: 22 additions & 10 deletions

File tree

lib/color/gamut/svg.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,7 @@ defmodule Color.Gamut.SVG do
321321

322322
[
323323
"<circle cx=\"#{fmt(px)}\" cy=\"#{fmt(py)}\" r=\"7\" fill=\"#{hex}\" ",
324-
"stroke=\"#fff\" stroke-width=\"2\" />",
325-
"<text x=\"#{fmt(px + 10)}\" y=\"#{fmt(py + 4)}\" fill=\"#fff\" font-size=\"11\" ",
326-
"font-family=\"ui-monospace,monospace\">seed</text>"
324+
"stroke=\"#fff\" stroke-width=\"2\" />"
327325
]
328326
end
329327

lib/color/palette/visualizer.ex

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,23 @@ defmodule Color.Palette.Visualizer do
196196
projection: atom_default(Map.get(params, "projection"), [:xy, :uv], :uv),
197197
gamuts: gamuts,
198198
planckian: truthy?(Map.get(params, "planckian")),
199-
overlay_seed: truthy?(Map.get(params, "overlay_seed")),
200-
overlay_palette: truthy?(Map.get(params, "overlay_palette"))
199+
overlay_seed: checkbox_default(params, "overlay_seed", true),
200+
overlay_palette: checkbox_default(params, "overlay_palette", true)
201201
}
202202
end
203203

204+
# A checkbox that defaults to `default_on` on fresh page loads
205+
# but respects an explicit unchecked state after a form
206+
# submission. We rely on the form's hidden `submitted` field
207+
# to distinguish "never submitted" (fall back to default) from
208+
# "submitted without this checkbox" (user unchecked it).
209+
defp checkbox_default(params, key, default_on) do
210+
case Map.get(params, key) do
211+
nil -> not Map.has_key?(params, "submitted") and default_on
212+
value -> truthy?(value)
213+
end
214+
end
215+
204216
@gamut_atoms %{
205217
"SRGB" => :SRGB,
206218
"P3_D65" => :P3_D65,

lib/color/palette/visualizer/gamut_view.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ defmodule Color.Palette.Visualizer.GamutView do
168168
")</span></li>"
169169
]
170170
end),
171+
"<li><span class=\"vz-legend-swatch\" ",
172+
"style=\"background:#60a5fa;border-radius:50%;border:1px solid rgba(255,255,255,0.4)\"></span>",
173+
"White point of each gamut (dot inside its triangle)</li>",
171174
if show_planck do
172175
[
173176
"<li><span class=\"vz-legend-swatch\" style=\"background:#fbbf2433;border:1px dashed #fbbf24\"></span>Planckian locus (1500 – 20 000 K)</li>"

test/gamut_svg_test.exs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ defmodule Color.Gamut.SVGTest do
5555
refute svg =~ "stroke-dasharray=\"3,3\""
5656
end
5757

58-
test "seed overlay plots a labelled dot" do
58+
test "seed overlay plots a dot filled with the seed colour" do
5959
svg = SVG.render(seed: "#ff0000")
60-
assert svg =~ ~s(>seed</text>)
61-
assert svg =~ "#ff0000"
60+
assert svg =~ ~s(fill="#ff0000")
6261
end
6362

6463
test "palette overlay adds a circle per stop with <title>" do

test/palette_visualizer_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,12 @@ defmodule Color.Palette.VisualizerTest do
239239
assert on.resp_body =~ "stroke-dasharray=\"3,3\""
240240
end
241241

242-
test "overlay_seed plots a seed dot with label" do
242+
test "overlay_seed plots a seed dot and adds a legend entry" do
243243
conn =
244244
conn(:get, "/gamut?overlay_seed=1&seed=%23ff0000&submitted=1")
245245
|> Color.Palette.Visualizer.call(@opts)
246246

247-
assert conn.resp_body =~ ~s(>seed</text>)
247+
assert conn.resp_body =~ ~s(fill="#ff0000")
248248
assert conn.resp_body =~ "Seed:"
249249
end
250250

0 commit comments

Comments
 (0)