diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-04-13 10:05:01 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-04-13 10:05:01 -0400 |
| commit | b2220e82c0d10e85442a53b574dc3c9f1b9ac63b (patch) | |
| tree | f2417f99323efeee797aab193bd530578bf74d01 /src | |
| parent | 1fffae50b765419864451975ef1049aa4a6ec08a (diff) | |
Avoid rescaling plot if aspect ratio is small
Diffstat (limited to 'src')
| -rw-r--r-- | src/p.bqn | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -1,7 +1,7 @@ # Plot -dim← 2⥊384 -pad← 2⥊10 +width ← 384 +pad ← 2⥊10 ps ← At "class=red|style=fill:none|stroke-width=1" rc ← At "class=code|stroke-width=1|rx=5" @@ -10,8 +10,13 @@ gr ← "g" At "font-family=BQN,monospace|font-size=18px" Plot ← { "•Plot: 𝕨 and 𝕩 must be lists of numbers" ! 𝕨 ⊢⊘∧○((1==)◶⟨0,∧´@⊸>⟩) 𝕩 "•Plot: 𝕨 and 𝕩 must have the same length" ! 𝕨 1⊘≡○≠ 𝕩 - Norm ← ÷⟜(⌈´)·-⟜(⌊´)1e300(⊣-⊸⌈⌊)⊢ - path ← 'M'⌾⊑ ∾⥊⍉ "L " ∾¨ FmtNum dim × (𝕨 ↕∘≠⊘⊣ 𝕩) ≍⟜¬○Norm 𝕩 + xy ← 1e300 (⊣-⊸⌈⌊) ⟨𝕨↕∘≠⊘⊣𝕩, 𝕩⟩ # default x and clip + bounds ← (-˜`⌊´≍⌈´)¨ xy # min and range + ar ← 1⍟((÷4)⊸>∨1.5⊸<) ÷˜´ 1⊑¨bounds # height÷width + dim ← width (⊣≍×) ar + scale ← {𝕩÷˜𝕨-˜⊢}´¨ bounds + p ← dim × ≍⟜¬´ scale {𝕎𝕩}¨ xy + path ← 'M'⌾⊑ ∾⥊⍉ "L " ∾¨ FmtNum p ((-pad)∾dim+2×pad) SVG gr Enc ⟨ "rect" Elt rc∾(Pos-pad÷2)∾"width"‿"height"≍˘FmtNum dim+pad ("path" Elt ps∾"d"≍○<⊢) path |
