浏览代码

Huge layout improvements

Kirk Trombley 3 年之前
父节点
当前提交
01bc7667af
共有 3 个文件被更改,包括 144 次插入141 次删除
  1. 45 32
      nearest.css
  2. 96 101
      nearest.html
  3. 3 8
      nearest.js

+ 45 - 32
nearest.css

@@ -1,6 +1,7 @@
 :root {
     --highlight: #ddd;
     --background: #222;
+    --tile-width: 480px;
 }
 
 body {
@@ -33,6 +34,10 @@ body {
     align-items: stretch;
 }
 
+.center-text {
+    text-align: center;
+}
+
 .config {
     width: 100%;
     margin-bottom: 16px;
@@ -44,7 +49,7 @@ body {
     align-items: center;
 }
 
-.dropdown > select, input {
+.dropdown > select {
     margin-top: 8px;
     margin-right: 8px;
     margin-left: 8px;
@@ -70,15 +75,19 @@ body {
     display: none;
 }
 
-#reveal-definitions:checked~.definitions {
-    display: flex;
+#reveal-definitions:checked ~ .definitions {
+    display: block;
+}
+
+#reveal-definitions:checked ~ * > .definitions {
+    display: block;
 }
 
-#reveal-definitions:checked~#reveal-def-label > #reveal-def-hide {
+#reveal-definitions:checked ~ #reveal-def-label > #reveal-def-hide {
     display: block;
 }
 
-#reveal-definitions:checked~#reveal-def-label > #reveal-def-show {
+#reveal-definitions:checked ~ #reveal-def-label > #reveal-def-show {
     display: none;
 }
 
@@ -94,6 +103,9 @@ body {
 
 .definitions {
     display: none;
+    /* evil trick to allow running into margins */
+    max-width: 0px;
+    overflow: visible;
 }
 
 .math-section {
@@ -136,10 +148,6 @@ body {
     max-width: 10em;
 }
 
-#cluster-mean-warning {
-    margin-top: 4px;
-}
-
 #bulba-wrapper {
     display: flex;
     justify-content: center;
@@ -150,21 +158,8 @@ label {
 }
 
 .hideable_control {
-    /* container + control, copied to a single class for toggling */
     display: flex;
     flex-flow: row nowrap;
-    justify-content: space-between;
-    align-items: flex-start;
-    height: 32px;
-    align-items: flex-end;
-}
-
-.hideable_control > label {
-    padding-right: 2em;
-}
-
-.hideable_control > input {
-    flex: 0 0 50%;
 }
 
 .hideable_control--hidden {
@@ -175,24 +170,42 @@ label {
     list-style-type: none;
     padding: 0;
     margin: 0;
-    margin-top: 16px;
+    margin-top: 8px;
     width: 100%;
 }
 
-.bypkmn {
-    margin-top: 16px;
-    padding-right: 8px;
-    min-width: 500px;
-}
-
 #search-space-button {
     width: 3em;
 }
 
+#controls {
+    max-width: var(--tile-width);
+    display: grid;
+    gap: 4px 16px;
+    grid:
+        "bulb qvec qvec"
+        "inpt qvec qvec"
+        "rand liml limt"
+        "metr objf objf" 3em
+        "clst scal scal"
+        ".    iner coef"
+        ".    norm coef"
+        "warn warn warn"
+        "togg togg .   "
+        "defs clsd clsd"
+        "srch name btns"
+        "rslt rslt rslt"
+        /10em 10em 1fr
+    ;
+    justify-items: stretch;
+    align-items: center;
+    margin-right: 60px;
+}
+
 /* Pokemon Tile */
 
 .pkmn_tile {
-    width: 480px;
+    width: var(--tile-width);
     display: grid;
     gap: 2px 2px;
     margin-top: 4px;
@@ -211,8 +224,8 @@ label {
     font-size: 12px;
     display: grid;
     grid:
-        ".     mu  mus mud"
-        ".     in  mut mup"
+        ".     mu  mus mut"
+        ".     in  mud mup"
         /0.1fr 3fr 1fr 1fr
     ;
     gap: 2px 2px;

+ 96 - 101
nearest.html

@@ -17,115 +17,110 @@
 <body>
     <noscript>Requires javascript</noscript>
     <div class="container start-justified">
-        <div id="left-panel" class="padded panel">
-            <form class="panel config" onsubmit="event.preventDefault()">
-                <div class="container control config">
-                    <div id="bulba-wrapper">
-                        <img src="https://img.pokemondb.net/sprites/sword-shield/icon/bulbasaur.png" />
-                    </div>
-                    <button class="padded" type="button" onclick="onRandomColor()">Random Color</button>
-                    <input size="7" maxlength="7" id="color-input" oninput="onColorChanged()" />
-                </div>
-
-                <div class="container dropdowns">
-                    <div class="panel dropdown">
-                        <label for="metric">Scoring Metric:</label>
-                        <select type="checkbox" onchange="onMetricChanged()" id="metric">
-                            <option selected>RMS Deviation (σ)</option>
-                            <option>Mean Angle (θ)</option>
-                            <option>Mean Distance (δ)</option>
-                            <option>Hue Angle (ϕ)</option>
-                            <option>Max Inertia (I)</option>
-                            <option>Custom Metric</option>
-                        </select>
-                    </div>
-                    <div class="panel dropdown">
-                        <label for="image-mean">Cluster:</label>
-                        <select type="checkbox" onchange="onClusterChoiceChanged()" id="image-summary">
-                            <option selected>All Pixels</option>
-                            <option>Biggest (M)</option>
-                            <option>Smallest (m)</option>
-                            <option>Best (α)</option>
-                            <option>Worst (ω)</option>
-                        </select>
-                    </div>
-
-                    <div class="panel dropdown">
-                        <label for="num-poke">
-                            Search limit: <span id="num-poke-display">10</span>
-                        </label>
-                        <input type="range" min="1" max="100" value="10" oninput="onLimitChanged(true)" onchange="onLimitChanged()" id="num-poke">
-                    </div>
-                </div>
-
-                <div id="cluster-mean-warning" class="container center-justified hide">
-                    Warning: RMS and inertia have little meaning when clusters are used
-                </div>
-
-                <div class="container control hide">
-                    <label for="scale-by-cluster-size">Scale measure by cluster size:</label>
-                    <input type="checkbox" checked oninput="onScaleByClusterChanged()" id="scale-by-cluster-size">
-                </div>
-
-                <div class="hideable_control hideable_control--hidden">
-                    <label for="include-x">Include inertia:</label>
-                    <input type="checkbox" checked oninput="onCustomControlsChanged()" id="include-x">
-                </div>
-
-                <div class="hideable_control hideable_control--hidden">
-                    <label for="norm-q-y">Normalize q and μ:</label>
-                    <input type="checkbox" oninput="onCustomControlsChanged()" id="norm-q-y">
-                </div>
-
-                <div class="hideable_control hideable_control--hidden">
-                    <label for="close-coeff">Closeness coefficient: <span id="close-coeff-display">2</span></label>
-                    <input type="range" min="0" max="10" value="2" step="0.1" oninput="onCustomControlsChanged()" id="close-coeff">
-                </div>
-            </form>
-            
-            <div class="panel math-section">
-                <input type="checkbox" checked id="reveal-definitions" role="button">
-    
-                <label id="reveal-def-label" for="reveal-definitions" style="width: 300px">
-                    <div id="reveal-def-show">Show Definitions ►</div>
-                    <div id="reveal-def-hide">Hide Definitions ▼</div>
+        <form id="controls" onsubmit="event.preventDefault()">
+            <img style="grid-area: bulb; justify-self: center;" src="https://img.pokemondb.net/sprites/sword-shield/icon/bulbasaur.png" />
+            <input style="grid-area: inpt;" maxlength="7" id="color-input" oninput="onColorChanged()" />
+            <button style="grid-area: rand;" type="button" onclick="onRandomColor()">
+                Random Color
+            </button>
+            <label for="num-poke" style="grid-area: liml">
+                Search limit: <span id="num-poke-display">10</span>
+            </label>
+            <input 
+                id="num-poke" style="grid-area: limt;"
+                type="range" min="1" max="100" value="10" 
+                oninput="onLimitChanged(true)" onchange="onLimitChanged()" 
+            >
+            <div style="grid-area: qvec; justify-self: start; align-self: end;">
+                <div id="q-vec-jab"></div>
+                <div id="q-vec-rgb"></div>
+            </div>
+            <span id="obj-fn" style="grid-area: objf;"></span>
+            <div class="panel" style="grid-area: metr;">
+                <label for="metric" style="text-align: center;">
+                    Scoring Metric:
+                </label>
+                <select type="checkbox" onchange="onMetricChanged()" id="metric">
+                    <option selected>RMS Deviation (σ)</option>
+                    <option>Mean Angle (θ)</option>
+                    <option>Mean Distance (δ)</option>
+                    <option>Hue Angle (ϕ)</option>
+                    <option>Max Inertia (I)</option>
+                    <option>Custom Metric</option>
+                </select>
+            </div>
+            <div class="panel" style="grid-area: clst;">
+                <label for="image-mean" class="center-text">
+                    Cluster:
                 </label>
+                <select type="checkbox" onchange="onClusterChoiceChanged()" id="image-summary">
+                    <option selected>All Pixels</option>
+                    <option>Biggest (M)</option>
+                    <option>Smallest (m)</option>
+                    <option>Best (α)</option>
+                    <option>Worst (ω)</option>
+                </select>
+            </div>
+            <div id="cluster-mean-warning" class="center-text hide" style="grid-area: warn;">
+                Warning: RMS and inertia have little meaning when clusters are used
+            </div>
+            <div style="grid-area: scal; align-self: end; padding-bottom: 2px;" class="hide">
+                <label for="scale-by-cluster-size">
+                    Scale measure by cluster size:
+                </label>
+                <input type="checkbox" checked oninput="onScaleByClusterChanged()" id="scale-by-cluster-size">
+            </div>
+            <input type="checkbox" id="reveal-definitions" role="button">
+            <label 
+                id="reveal-def-label" for="reveal-definitions" 
+                style="grid-area: togg;"
+            >
+                <div id="reveal-def-show">Show Definitions ►</div>
+                <div id="reveal-def-hide">Hide Definitions ▼</div>
+            </label>
+            <div style="grid-area: defs; align-self: start; padding-left: 1em;">
+                <div class="definitions" id="main-definition"></div>
+            </div>
+            <div style="grid-area: clsd; align-self: start;">
+                <div class="definitions" id="cluster-definition"></div> 
+            </div>
 
-                <div class="definitions">Statistics</div>
-                <div class="container definitions">
-                    <div id="main-definition"></div>
-                    <div id="angle-definition"></div>
-                </div>
-                <div id="rms-definition" class="container center-aligned center-justified definitions"></div>
-                <hr class="definitions">
-                <div class="definitions">Clusters</div>
-                <div id="cluster-definition" class="definitions"></div>
+            <div class="hideable_control hideable_control--hidden" style="grid-area: iner;">
+                <input type="checkbox" checked oninput="onCustomControlsChanged()" id="include-x">
+                <label for="include-x">Include Inertia</label>
             </div>
 
-            <div class="panel math-section">
-                <div class="container center-aligned">
-                    <div id="q-vec-jab"></div>
-                    <div id="q-vec-rgb"></div>
-                </div>
+            <div class="hideable_control hideable_control--hidden" style="grid-area: norm;">
+                <input type="checkbox" oninput="onCustomControlsChanged()" id="norm-q-y">
+                <label for="norm-q-y">Normalize q and μ</label>
+            </div>
 
-                <div class="container center-aligned start-justified">
-                    <span class="eqn-label">Optimizing:</span>
-                    <span id="obj-fn"></span>
-                </div>
+            <div 
+                class="hideable_control hideable_control--hidden" 
+                style="grid-area: coef; flex-direction: column;"
+            >
+                <label for="close-coeff">
+                    Closeness: <span id="close-coeff-display">2</span>
+                </label>
+                <input 
+                    type="range" min="0" max="10" value="2" step="0.1" 
+                    oninput="onCustomControlsChanged()" id="close-coeff"
+                >
             </div>
 
-            <div class="panel bypkmn">
-                <form class="container control" onsubmit="event.preventDefault()">
-                    <label for="pokemon-name">Search By Pokemon</label>
-                    <button class="padded" type="button" onclick="onRandomPokemon()">Random</button>
-                    <input id="pokemon-name" size="15" oninput="onSearchChanged()">
-                    <button id="search-space-button" type="button" onclick="onSearchSpaceChanged()">
-                        <span id="search-space-display">RGB</span>
-                    </button>
-                </form>
-                <ul id="search-list" class="pkmn-list"></ul>
+            <label style="grid-area: srch;" for="pokemon-name">Search By Pokemon</label>
+            <input style="grid-area: name;" id="pokemon-name" size="15" oninput="onSearchChanged()">
+            <div style="grid-area: btns;">
+                <button class="padded" type="button" onclick="onRandomPokemon()">
+                    Random
+                </button>
+                <button id="search-space-button" type="button" onclick="onSearchSpaceChanged()">
+                    <span id="search-space-display">RGB</span>
+                </button>
             </div>
-        </div>
+            <ul id="search-list" style="grid-area: rslt;" class="pkmn-list"></ul>
+        </form>
+
         <div class="padded panel">
             <div class="title">CIECAM02 Uniform Color Space (Jab)</div>
             <ul id="best-list-jab" class="pkmn-list"></ul>

+ 3 - 8
nearest.js

@@ -214,18 +214,13 @@ const mathDefinitions = {
       \vec{\mu}\left(P\right) &= \frac{1}{\left|P\right|}\sum_{p\in P}{\vec{p}} \\
       I\left(P\right) &= \frac{1}{\left|P\right|}\sum_{p\in P}{\left|\left|\vec{p}\right|\right|^2} \\
       \delta\left(P\right) &= \left|\left| \vec{q} - \vec{\mu}\left(P\right) \right|\right| \\
-    \end{aligned}
-  `,
-  "angle-definition": String.raw`
-    \begin{aligned}
       \theta\left(P\right) &= \angle \left(\vec{q}, \vec{\mu}\left(P\right)\right) \\
       \vec{x}_{\perp} &= \text{oproj}_{\left\{\vec{J}, \vec{L}\right\}}{\vec{x}} \\
-      \phi\left(P\right) &= \angle \left(\vec{q}_{\perp}, \vec{\mu}\left(P\right)_{\perp} \right)
+      \phi\left(P\right) &= \angle \left(\vec{q}_{\perp}, \vec{\mu}\left(P\right)_{\perp} \right) \\
+      \sigma\left(P\right) &= \sqrt{E\left[\left(\vec{q} - P\right)^2\right]} \\
+        &= \sqrt{\frac{1}{|P|}\sum_{p \in P}{\left|\left|\vec{p} - \vec{q}\right|\right|^2}}
     \end{aligned}
   `,
-  "rms-definition": String.raw`
-    \sigma\left(P\right) = \sqrt{E\left[\left(\vec{q} - P\right)^2\right]} = \sqrt{\frac{1}{|P|}\sum_{p \in P}{\left|\left|\vec{p} - \vec{q}\right|\right|^2}}
-  `,
   "cluster-definition": String.raw`
     \begin{aligned}
       \left\{P_1, P_2, P_3\right\} &= ${mathArgBest("max", String.raw`\left\{P_1, P_2, P_3\right\}`)} \sum_{i=1}^3 \sum_{p\inP_i} \left|\left| \vec{p} - \vec{\mu}\left(P_i\right) \right|\right|^2 \\