Skip to content

Commit aa5cb90

Browse files
committed
v7.3.1
1 parent b26be80 commit aa5cb90

File tree

103 files changed

+13281
-21414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+13281
-21414
lines changed

docs/demos/car-analysis/article.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<nav><ul><li><a href="/">TinyBase</a></li><li><a href="/demos/">Demos</a></li><li><a href="/demos/car-analysis/">Car Analysis</a></li></ul></nav><section class="s1" id="/demos/car-analysis/" data-id="CA"><h1>Car Analysis</h1><iframe srcdoc="&lt;html&gt;&lt;head&gt;&lt;script type=&quot;importmap&quot;&gt;{
22
&quot;imports&quot;: {
3-
&quot;tinybase&quot;: &quot;https://esm.sh/[email protected].0&quot;,
4-
&quot;tinybase/ui-react&quot;: &quot;https://esm.sh/[email protected].0/ui-react&quot;,
5-
&quot;tinybase/ui-react-dom&quot;: &quot;https://esm.sh/[email protected].0/ui-react-dom&quot;,
6-
&quot;tinybase/ui-react-inspector&quot;: &quot;https://esm.sh/[email protected].0/ui-react-inspector&quot;,
3+
&quot;tinybase&quot;: &quot;https://esm.sh/[email protected].1&quot;,
4+
&quot;tinybase/ui-react&quot;: &quot;https://esm.sh/[email protected].1/ui-react&quot;,
5+
&quot;tinybase/ui-react-dom&quot;: &quot;https://esm.sh/[email protected].1/ui-react-dom&quot;,
6+
&quot;tinybase/ui-react-inspector&quot;: &quot;https://esm.sh/[email protected].1/ui-react-inspector&quot;,
77
&quot;react&quot;: &quot;https://esm.sh/react@^19.0.0&quot;,
88
&quot;react/jsx-runtime&quot;: &quot;https://esm.sh/react@^19.0.0/jsx-runtime&quot;,
99
&quot;react-dom/client&quot;: &quot;https://esm.sh/react-dom@^19.0.0/client&quot;
@@ -12,10 +12,10 @@
1212
`),s=o.shift().split(&quot; &quot;);t.transaction(()=&gt;o.forEach((n,c)=&gt;{const a=n.split(&quot; &quot;);a.length==s.length&amp;&amp;a.forEach((r,u)=&gt;{r!=&quot;&quot;&amp;&amp;(z.test(r)&amp;&amp;(r=parseFloat(r)),t.setCell(&quot;cars&quot;,c,s[u],r))})}))},W=()=&gt;{const[t,o]=S(!1),[s,n]=C(&quot;cars&quot;,&quot;dimensions&quot;),[c,a]=C(&quot;cars&quot;,&quot;measures&quot;),[r,u]=C(&quot;cars&quot;,&quot;aggregate&quot;);return f(v,{children:[f(&quot;aside&quot;,{children:[e(&quot;b&quot;,{children:&quot;Dimensions&quot;}),e(E,{options:F,selected:s,onOptionsChange:n}),e(&quot;hr&quot;,{}),e(&quot;b&quot;,{children:&quot;Measures&quot;}),e(E,{options:Y,selected:c,onOptionsChange:a}),e(&quot;hr&quot;,{}),e(&quot;b&quot;,{children:&quot;Aggregate&quot;}),e(E,{options:Object.keys(T),selected:[r],onOptionsChange:u,multiple:!1}),e(&quot;hr&quot;,{}),e(&quot;input&quot;,{id:&quot;showTable&quot;,type:&quot;checkbox&quot;,checked:t,onChange:A(({target:l})=&gt;o(l.checked),[])}),e(&quot;label&quot;,{for:&quot;showTable&quot;,children:&quot;Show table&quot;}),e(&quot;br&quot;,{}),e(&quot;small&quot;,{children:e(&quot;a&quot;,{href:&quot;https://github.com/vega/vega-datasets/blob/next/data/cars.json&quot;,children:&quot;Source&quot;})})]}),t?e(X,{columns:[...s,...c]}):e(K,{dimensions:s,measures:c})]})},X=({columns:t})=&gt;e(Q,{queryId:&quot;cars&quot;,sortOnClick:!0,paginator:!0,limit:10,idColumn:!1,customCells:y(()=&gt;Object.fromEntries(t.map(o=&gt;[o,{component:J}])),[...t])}),J=({rowId:t,cellId:o})=&gt;{const s=H(&quot;cars&quot;,t,o);return e(&quot;span&quot;,{className:o,children:Number.isFinite(s)?$(s):s})},K=({dimensions:t,measures:o})=&gt;{const s=D(null),[{width:n=0,height:c=0},a]=S({});O(()=&gt;{const p=new ResizeObserver(([{contentRect:i}])=&gt;a(i));return p.observe(s.current),()=&gt;p.disconnect()},[s]);const[r,u,l]=Z(t,o),[m,h,x,M,w]=ee(n,c,r,l);return n==0||c==0?e(&quot;main&quot;,{ref:s}):e(&quot;main&quot;,{ref:s,children:f(&quot;svg&quot;,{xmlns:&quot;http://www.w3.org/2000/svg&quot;,viewBox:`0 0 ${n} ${c}`,children:[e(&quot;path&quot;,{d:`M${m(0)} ${h(0)}H${m(w)}`}),e(v,{children:x.map((p,i)=&gt;{const d=m(i)-R/2,g=h(0)+b;return p&amp;&amp;e(&quot;text&quot;,{transform:`translate(${d} ${g}) rotate(90)`,children:p},i)})}),e(v,{children:M.map(p=&gt;{const i=m(0)-b,d=h(p)+R/2;return e(&quot;text&quot;,{transform:`translate(${i} ${d})`,&quot;text-anchor&quot;:&quot;end&quot;,children:p},p)})}),u.map((p,i)=&gt;f(&quot;g&quot;,{className:o[i],children:[e(&quot;path&quot;,{d:p.map((d,g)=&gt;`${g==0?&quot;M&quot;:&quot;L&quot;}${m(g)} ${h(d)}`).join(&quot;&quot;)}),p.map((d,g)=&gt;f(v,{children:[e(&quot;circle&quot;,{cx:m(g),cy:h(d),r:b}),f(&quot;text&quot;,{x:m(g),y:h(d)-R,children:[r[g],&quot; &quot;,o[i],&quot;: &quot;,$(d)]})]}))]},i))]})})},Z=(t,o)=&gt;{const s=j(&quot;cars&quot;),n=_(&quot;cars&quot;,o[0]??void 0);return y(()=&gt;{const c=[1],a=[],r=o.map(()=&gt;[]);return n.forEach(u=&gt;{const l=s[u];a.push(t.map(m=&gt;l[m]).join(&quot;, &quot;)),o.forEach((m,h)=&gt;{c.push(l[m]),r[h].push(l[m])})}),[a,r,Math.max(...c)]},[s,n,o,t])},ee=(t,o,s,n)=&gt;y(()=&gt;{const c=o/4,a=t/15,r=t-a-b,u=o-c-b,l=s.length-1,m=s.map((i,d)=&gt;d%Math.ceil(R*l/r)==0?i:null),h=Math.pow(10,Math.floor(Math.log10(n))),x=Math.ceil(n/h)*h,M=Math.ceil(n/h),w=M&lt;=2?5:M&lt;=5?2:1,p=Array(w*M+1).fill().map((i,d)=&gt;d*h/w);return[i=&gt;a+i*r/l,i=&gt;b+u-i*u/x,m,p,l,x]},[t,o,s,n]),E=({options:t,selected:o,onOptionsChange:s,multiple:n=!0})=&gt;{const c=A(({target:a})=&gt;s(n?[...a.selectedOptions].map(r=&gt;r.value):a.value),[s]);return e(&quot;select&quot;,{multiple:n,size:t.length,onChange:c,children:t.map(a=&gt;e(&quot;option&quot;,{value:a,selected:o.includes(a),className:a,children:a}))})};&lt;/script&gt;&lt;/html&gt;"></iframe><p>In this demo, we build an app that showcases the query capabilities of TinyBase v2.0, grouping and sorting dimensional data for lightweight analytical usage.</p><p>We&#x27;ve also updated it to use parameterized queries to take advantage of TinyBase v7.2.</p><p>The data from this demo is derived from <code>cars.json</code> in the <a href="https://github.com/vega/vega-datasets">Vega datasets</a> - thank you <a href="https://idl.cs.washington.edu/">UW Interactive Data Lab</a>!</p><h3 id="an-overview-of-the-data">An Overview Of The Data</h3><p>Before looking at code, let&#x27;s familiarize ourselves with the data used in this application.</p><p>The raw data is loaded from a TSV file into one single <a href="/api/store/type-aliases/store/table/"><code>Table</code></a> object: <code>cars</code>, and comprises almost 400 records of cars made in the 1970s and 1980s.</p><p>For each, the data includes the manufacturer, the car name, year, and region. These <a href="/api/store/type-aliases/store/cell/"><code>Cell</code></a> values are &#x27;dimensions&#x27; with which the data can be grouped.</p><p>Each record also includes a number of quantitative fields, including the car&#x27;s miles-per-gallon (MPG), the number of cylinders, their displacement, its horsepower, weight, and acceleration. These <a href="/api/store/type-aliases/store/cell/"><code>Cell</code></a> values are &#x27;measures&#x27; which can be aggregated together - in this basic app, to find their average, maximum, or minimum.</p><p>The app is oriented around one single query. As the user picks different dimensions or measures in the app&#x27;s sidebar, that query is re-run and the results (either in graphical or tabular form) reactively update immediately.</p><h3 id="boilerplate">Boilerplate</h3><p>First, we create the import aliases for TinyBase and React modules we&#x27;ll need:</p><pre><code><span class="tag"><span class="tag"><span class="punctuation">&lt;</span>script</span> <span class="attr-name">type</span><span class="attr-value"><span class="punctuation">=</span><span class="punctuation">"</span>importmap<span class="punctuation">"</span></span><span class="punctuation">></span></span><span class="script"><span class="language-javascript">
1313
<span class="punctuation">{</span>
1414
<span class="string-property">"imports"</span><span class="operator">:</span> <span class="punctuation">{</span>
15-
<span class="string-property">"tinybase"</span><span class="operator">:</span> <span class="string">"https://esm.sh/[email protected].0"</span><span class="punctuation">,</span>
16-
<span class="string-property">"tinybase/ui-react"</span><span class="operator">:</span> <span class="string">"https://esm.sh/[email protected].0/ui-react"</span><span class="punctuation">,</span>
17-
<span class="string-property">"tinybase/ui-react-dom"</span><span class="operator">:</span> <span class="string">"https://esm.sh/[email protected].0/ui-react-dom"</span><span class="punctuation">,</span>
18-
<span class="string-property">"tinybase/ui-react-inspector"</span><span class="operator">:</span> <span class="string">"https://esm.sh/[email protected].0/ui-react-inspector"</span><span class="punctuation">,</span>
15+
<span class="string-property">"tinybase"</span><span class="operator">:</span> <span class="string">"https://esm.sh/[email protected].1"</span><span class="punctuation">,</span>
16+
<span class="string-property">"tinybase/ui-react"</span><span class="operator">:</span> <span class="string">"https://esm.sh/[email protected].1/ui-react"</span><span class="punctuation">,</span>
17+
<span class="string-property">"tinybase/ui-react-dom"</span><span class="operator">:</span> <span class="string">"https://esm.sh/[email protected].1/ui-react-dom"</span><span class="punctuation">,</span>
18+
<span class="string-property">"tinybase/ui-react-inspector"</span><span class="operator">:</span> <span class="string">"https://esm.sh/[email protected].1/ui-react-inspector"</span><span class="punctuation">,</span>
1919
<span class="string-property">"react"</span><span class="operator">:</span> <span class="string">"https://esm.sh/react@^19.0.0"</span><span class="punctuation">,</span>
2020
<span class="string-property">"react/jsx-runtime"</span><span class="operator">:</span> <span class="string">"https://esm.sh/react@^19.0.0/jsx-runtime"</span><span class="punctuation">,</span>
2121
<span class="string-property">"react-dom/client"</span><span class="operator">:</span> <span class="string">"https://esm.sh/react-dom@^19.0.0/client"</span>

0 commit comments

Comments
 (0)