Browse Source

Cleanup more formatting, render q vectors

Kirk Trombley 3 years ago
parent
commit
555347d393
3 changed files with 68 additions and 114 deletions
  1. 31 7
      nearest.css
  2. 23 95
      nearest.html
  3. 14 12
      nearest.js

+ 31 - 7
nearest.css

@@ -1,5 +1,5 @@
 body {
-    width: 100vw;
+    width: 99%;
     padding-top: 4px;
     font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
 }
@@ -16,6 +16,10 @@ body {
     align-items: flex-start;
 }
 
+.start-justified {
+    justify-content: flex-start;
+}
+
 .panel {
     display: flex;
     flex-flow: column nowrap;
@@ -32,6 +36,22 @@ body {
     align-items: center;
 }
 
+.center-justified {
+    justify-content: center;
+}
+
+.math-section {
+    border: 4px solid #222;
+    padding: 1em;
+    padding-bottom: 0;
+    min-width: 90%;
+    align-self: center;
+}
+
+.qvecs {
+    align-items: flex-end;
+}
+
 #obj-fn {
     display: inline-flex;
     flex-flow: column nowrap;
@@ -105,10 +125,7 @@ body {
 }
 
 .bypkmn {
-    border-top: 4px solid #222;
-    border-right: 4px solid #222;
-    margin-top: 32px;
-    padding-top: 8px;
+    margin-top: 16px;
     padding-right: 8px;
     min-width: 500px;
 }
@@ -122,10 +139,17 @@ body {
     flex-flow: row nowrap;
     justify-content: flex-start;
     align-items: flex-start;
-    min-width: 500px;
     width: 100%;
 }
 
+.pokemon_tile-image-wrapper {
+    width: 60px;
+    height: 50px;
+    display: flex;
+    justify-content: center;
+    align-items: center;
+}
+
 .pokemon_tile-info_panel {
     display: flex;
     flex-flow: column nowrap;
@@ -151,7 +175,7 @@ body {
 
 .pokemon_tile-score_column {
     margin-left: 4px;
-    min-width: 10em;
+    min-width: 6em;
     display: flex;
     flex-flow: column nowrap;
 }

+ 23 - 95
nearest.html

@@ -16,7 +16,7 @@
 
 <body>
     <noscript>Requires javascript</noscript>
-    <div class="container">
+    <div class="container start-justified">
         <div id="left-panel" class="padded panel">
             <form class="panel config" onsubmit="onUpdate(event)">
                 <div class="container control">
@@ -48,100 +48,28 @@
                     <input type="range" min="1" max="100" value="10" oninput="onUpdate()" id="num-poke">
                 </div>
             </form>
-
-            <div class="container center-aligned">
-                <div>
-                    <math xmlns="http://www.w3.org/1998/Math/MathML">
-                        <semantics>
-                            <mrow>
-                                <mi>X</mi>
-                                <mrow>
-                                    <mo>(</mo>
-                                    <mi>P</mi>
-                                    <mo>)</mo>
-                                </mrow>
-                                <mo>=</mo>
-                                <mfrac>
-                                    <mn>1</mn>
-                                    <mrow>
-                                        <mo>|</mo>
-                                        <mi>P</mi>
-                                        <mo>|</mo>
-                                    </mrow>
-                                </mfrac>
-                                <munder>
-                                    <mo>∑</mo>
-                                    <mrow>
-                                        <mi>p</mi>
-                                        <mo>∊</mo>
-                                        <mi>P</mi>
-                                    </mrow>
-                                </munder>
-                                <msup>
-                                    <mrow>
-                                        <mo>|</mo>
-                                        <mrow>
-                                            <mo>|</mo>
-                                            <mover>
-                                                <mi>p</mi>
-                                                <mo stretchy="false">⇀</mo>
-                                            </mover>
-                                            <mo>|</mo>
-                                        </mrow>
-                                        <mo>|</mo>
-                                    </mrow>
-                                    <mn>2</mn>
-                                </msup>
-                            </mrow>
-                            <annotation encoding="TeX">X\\left(P\\right) = \\frac{1}{\\left|P\\right|}\\sum_{p\\in
-                                P}{\\left|\\left|\\vec{p}\\right|\\right|^2}</annotation>
-                        </semantics>
-                    </math>
-                </div>
-                <div>
-                    <math xmlns="http://www.w3.org/1998/Math/MathML">
-                        <semantics>
-                            <mrow>
-                                <mover>
-                                    <mi>Y</mi>
-                                    <mo stretchy="false">⇀</mo>
-                                </mover>
-                                <mrow>
-                                    <mo>(</mo>
-                                    <mi>P</mi>
-                                    <mo>)</mo>
-                                </mrow>
-                                <mo>=</mo>
-                                <mfrac>
-                                    <mn>1</mn>
-                                    <mrow>
-                                        <mo>|</mo>
-                                        <mi>P</mi>
-                                        <mo>|</mo>
-                                    </mrow>
-                                </mfrac>
-                                <munder>
-                                    <mo>∑</mo>
-                                    <mrow>
-                                        <mi>p</mi>
-                                        <mo>∊</mo>
-                                        <mi>P</mi>
-                                    </mrow>
-                                </munder>
-                                <mover>
-                                    <mi>p</mi>
-                                    <mo stretchy="false">⇀</mo>
-                                </mover>
-                            </mrow>
-                            <annotation encoding="TeX">Y\\left(P\\right) = \\frac{1}{\\left|P\\right|}\\sum_{p\\in
-                                P}{\\vec{p}}</annotation>
-                        </semantics>
-                    </math>
+            
+            <div class="panel math-section">
+                <div class="container center-aligned">
+                    <div class="panel">
+                        <div>
+                            <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>X</mi><mrow><mo>(</mo><mi>P</mi><mo>)</mo></mrow><mo>=</mo><mfrac><mn>1</mn><mrow><mo>|</mo><mi>P</mi><mo>|</mo></mrow></mfrac><munder><mo>∑</mo><mrow><mi>p</mi><mo>∊</mo><mi>P</mi></mrow></munder><msup><mrow><mo>|</mo><mrow><mo>|</mo><mover><mi>p</mi><mo stretchy="false">⇀</mo></mover><mo>|</mo></mrow><mo>|</mo></mrow><mn>2</mn></msup></mrow><annotation encoding="TeX">X\\left(P\\right) = \\frac{1}{\\left|P\\right|}\\sum_{p\\inP}{\\left|\\left|\\vec{p}\\right|\\right|^2}</annotation></semantics></math>
+                        </div>
+                        <div>
+                            <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover><mi>Y</mi><mo stretchy="false">⇀</mo></mover><mrow><mo>(</mo><mi>P</mi><mo>)</mo></mrow><mo>=</mo><mfrac><mn>1</mn><mrow><mo>|</mo><mi>P</mi><mo>|</mo></mrow></mfrac><munder><mo>∑</mo><mrow><mi>p</mi><mo>∊</mo><mi>P</mi></mrow></munder><mover><mi>p</mi><mo stretchy="false">⇀</mo></mover></mrow><annotation encoding="TeX">Y\\left(P\\right) = \\frac{1}{\\left|P\\right|}\\sum_{p\\inP}{\\vec{p}}</annotation></semantics></math>
+                        </div>
+                    </div>
+                    <div class="panel qvecs">
+                        <div id="q-vec-jab"></div>
+                        <div id="q-vec-rgb"></div>
+                    </div>
                 </div>
-            </div>
 
-            <div class="container center-aligned">
-                Minimizing: <span id="obj-fn">X(P) - 2q&sdot;Y(P)</span>
+                <div class="container center-aligned center-justified">
+                    <div class="panel">
+                        <span id="obj-fn"></span>
+                    </div>
+                </div>
             </div>
 
             <div class="panel bypkmn">
@@ -153,10 +81,10 @@
             </div>
         </div>
         <div class="padded panel">
-            <div class="title">CIECAM02 Uniform Color Space</div>
+            <div class="title">CIECAM02 Uniform Color Space (Jab)</div>
             <ul id="best-list-jab" class="pkmn-list"></ul>
         </div>
-        <div class="padded panel" style="flex: 1">
+        <div class="padded panel">
             <div class="title">sRGB Color Space</div>
             <ul id="best-list-rgb" class="pkmn-list"></ul>
         </div>

+ 14 - 12
nearest.js

@@ -72,7 +72,9 @@ const renderPokemon = (
   const pkmn = document.createElement("div");
   pkmn.setAttribute("class", "pokemon_tile");
   pkmn.innerHTML = `
-    <img src="${getSprite(name)}" />
+    <div class="pokemon_tile-image-wrapper">
+      <img src="${getSprite(name)}" />
+    </div>
     <div class="pokemon_tile-info_panel">
       <span class="pokemon_tile-pokemon_name">${titleName}</span>
       <div class="pokemon_tile-results">
@@ -122,7 +124,11 @@ const renderNorm = vec => `\\frac{${vec}}{\\left|\\left|${vec}\\right|\\right|}`
 const renderMath = (includeX, normQY, closeCoeff) => {
   const xTerm = includeX ? "X\\left(P\\right)" : "";
   const qyMod = normQY ? c => renderNorm(renderVec(c)) : renderVec;
-  return TeXZilla.toMathML(`${xTerm}-${closeCoeff}${qyMod("q")}\\cdot ${qyMod("Y\\left(P\\right)")}`);
+  return TeXZilla.toMathML(`\\arg\\min_{P}\\left[${xTerm}-${closeCoeff}${qyMod("q")}\\cdot ${qyMod("Y\\left(P\\right)")}\\right]`);
+}
+
+const renderQVec = (q, id) => {
+  document.getElementById(id).innerHTML = TeXZilla.toMathMLString(`\\vec{q}_{\\text{RGB}} = \\left(${q.join(", ")}\\right)`);
 }
 
 const changePageColors = color => {
@@ -173,7 +179,8 @@ const onUpdate = (event) => {
 
     // Update the color display
     changePageColors(targetColor);
-    // TODO render q vectors somewhere
+    renderQVec(targetRGB.map(c => c.toFixed()), "q-vec-rgb");
+    renderQVec(targetJAB.map(c => c.toFixed(2)), "q-vec-jab");
 
     // Determine metrics from configuration
     const xSelector = includeX ? ({ xRGB, xJAB }) => [ xRGB, xJAB ] : () => [ 0, 0 ];
@@ -219,15 +226,9 @@ const onUpdate = (event) => {
   }
 
   // Lookup by name
-  if (pokemonName.length === 0) {
-    const searchList = document.getElementById("search-list");
-    searchList.innerHTML = '';
-  } else if (lastPkmnSearch !== pokemonName || newParams) {
-    // Update last search
-    lastPkmnSearch = pokemonName;
-
-    const searchList = document.getElementById("search-list");
-    searchList.innerHTML = '';
+  const searchList = document.getElementById("search-list");
+  searchList.innerHTML = '';
+  if (pokemonName.length > 0 && (lastPkmnSearch !== pokemonName || newParams)) {
     pokemonLookup
       .search(pokemonName, { limit: 10 })
       // If scoring is impossible, totalScorer will just be identity
@@ -238,6 +239,7 @@ const onUpdate = (event) => {
         searchList.appendChild(li);
       });
   }
+  lastPkmnSearch = pokemonName;
 };
 
 const onRandomColor = () => {