UNPKG

lightview

Version:

A reactive UI library with features of Bau, Juris, and HTMX plus safe LLM UI generation

550 lines (507 loc) 28.6 kB
<!-- SEO-friendly SPA Shim --> <script src="/lightview-router.js"></script> <script> if (globalThis.LightviewRouter) { LightviewRouter.base('/index.html'); } </script> <script type="module" src="../../components/data-display/chart.js"></script> <!-- Load the page-specific stylesheet --> <link rel="stylesheet" href="./index.css"> <!-- Gallery Structure --> <div class="gallery-page"> <div class="gallery-layout"> <!-- Sidebar Overlay --> <div id="sidebar-overlay" class="sidebar-overlay"></div> <!-- Sidebar --> <div id="gallery-sidebar" class="gallery-sidebar" style="visibility: hidden" src="./component-nav.html"></div> <!-- Main Content --> <div id="gallery-main" class="gallery-main"> <!-- Header Container --> <div style="position: sticky; top: 0; z-index: 30; background: var(--gallery-surface); border-bottom: 1px solid var(--gallery-border); backdrop-filter: blur(8px);"> <!-- Breadcrumbs Row --> <div style="padding: 0.75rem 1.5rem 0;"> <script> (() => { const { Breadcrumbs } = Lightview.tags; const breadcrumbs = Breadcrumbs({ id: 'page-breadcrumbs', items: [ { label: 'Components', href: '/docs/components' }, { label: 'Chart Column' } ] }); document.currentScript.replaceWith(breadcrumbs.domEl); })(); </script> </div> <!-- Title Row --> <div class="gallery-header" style="border-bottom: none; height: auto; padding-top: 0.5rem; padding-bottom: 0.75rem;"> <button id="toggle-btn" class="toggle-btn" aria-label="Toggle Sidebar"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="toggle-icon" style="stroke: currentColor; stroke-width: 2;"> <path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7" /> <path stroke-linecap="round" stroke-linejoin="round" d="M11 19l-7-7 7-7" /> </svg> </button> <h1 class="gallery-title">Chart Column</h1> </div> </div> <!-- Content --> <div class="gallery-content"> <div class="section-content" style="max-width: 1000px;"> <p class="text-lg" style="opacity: 0.7; margin-bottom: 1.5rem;"> Column charts display data as vertical bars. The column height represents the data value. </p> <!-- Basic Usage --> <div class="card bg-base-200" style="margin-bottom: 2rem;"> <div class="card-body"> <h2 class="card-title">Basic Usage</h2> <p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;"> To visualize data with a column chart, use <code>type: 'column'</code>. </p> <!-- Tabs --> <script> globalThis.switchBasicColumnTab = (tabId) => { const tabs = ['tagged', 'vdom', 'object']; tabs.forEach(t => { const tabEl = document.getElementById(`basic-column-tab-btn-${t}`); const contentEl = document.getElementById(`basic-column-syntax-${t}`); if (t === tabId) { tabEl.classList.add('syntax-tab-active'); contentEl.style.display = 'block'; } else { tabEl.classList.remove('syntax-tab-active'); contentEl.style.display = 'none'; } }); }; </script> <div role="tablist" class="syntax-tabs" style="margin-bottom: 1rem;"> <button id="basic-column-tab-btn-tagged" role="tab" class="syntax-tab syntax-tab-active" onclick="switchBasicColumnTab('tagged')">Tagged</button> <button id="basic-column-tab-btn-vdom" role="tab" class="syntax-tab" onclick="switchBasicColumnTab('vdom')">vDOM</button> <button id="basic-column-tab-btn-object" role="tab" class="syntax-tab" onclick="switchBasicColumnTab('object')">Object DOM</button> </div> <!-- Tagged Syntax --> <div id="basic-column-syntax-tagged"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 250, autoRun: true }); </script><code contenteditable="true">await import('/components/data-display/chart.js'); const { tags, $ } = Lightview; const { Chart, span } = tags; const chart = Chart({ type: 'column', labels: true, style: 'width: 100%; max-width: 600px; height: 250px; margin: 0 auto;' }, Chart.Body({}, Chart.Row({}, Chart.Label({}, 'Jan'), Chart.Data({ value: 0.4 }, span({ class: 'data' }, '40%'))), Chart.Row({}, Chart.Label({}, 'Feb'), Chart.Data({ value: 0.6 }, span({ class: 'data' }, '60%'))), Chart.Row({}, Chart.Label({}, 'Mar'), Chart.Data({ value: 0.8 }, span({ class: 'data' }, '80%'))), Chart.Row({}, Chart.Label({}, 'Apr'), Chart.Data({ value: 0.5 }, span({ class: 'data' }, '50%'))) ) ); $('#example').content(chart);</code></pre> </div> <!-- vDOM Syntax --> <div id="basic-column-syntax-vdom" style="display: none;"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 250 }); </script><code contenteditable="true">await import('/components/data-display/chart.js'); const { tags, $ } = Lightview; const { Chart, span } = tags; const months = [ { label: 'Jan', value: 0.4, text: '40%' }, { label: 'Feb', value: 0.6, text: '60%' }, { label: 'Mar', value: 0.8, text: '80%' }, { label: 'Apr', value: 0.5, text: '50%' } ]; const chart = { tag: Chart, attributes: { type: 'column', labels: true, style: 'width: 100%; max-width: 600px; height: 250px; margin: 0 auto;' }, children: [ { tag: Chart.Body, children: months.map(m => ({ tag: Chart.Row, children: [ { tag: Chart.Label, children: [m.label] }, { tag: Chart.Data, attributes: { value: m.value }, children: [{ tag: span, attributes: { class: 'data' }, children: [m.text] }] } ] })) } ] }; $('#example').content(chart);</code></pre> </div> <!-- Object DOM Syntax --> <div id="basic-column-syntax-object" style="display: none;"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 250 }); </script><code contenteditable="true">await import('/components/data-display/chart.js'); const { $ } = Lightview; const chart = { Chart: { type: 'column', labels: true, style: 'width: 100%; max-width: 600px; height: 250px; margin: 0 auto;', children: [ { 'Chart.Body': { children: [ { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Jan'] } }, { 'Chart.Data': { value: 0.4, children: [{ span: { class: 'data', children: ['40%'] } }] } }] } }, { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Feb'] } }, { 'Chart.Data': { value: 0.6, children: [{ span: { class: 'data', children: ['60%'] } }] } }] } }, { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Mar'] } }, { 'Chart.Data': { value: 0.8, children: [{ span: { class: 'data', children: ['80%'] } }] } }] } }, { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Apr'] } }, { 'Chart.Data': { value: 0.5, children: [{ span: { class: 'data', children: ['50%'] } }] } }] } } ] } } ] } }; $('#example').content(chart);</code></pre> </div> </div> </div> <!-- Multiple Datasets --> <div class="card bg-base-200" style="margin-bottom: 2rem;"> <div class="card-body"> <h2 class="card-title">Multiple Datasets</h2> <p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;"> Add multiple <code>Chart.Data</code> elements per row and set <code>multiple: true</code>. </p> <!-- Tabs --> <script> globalThis.switchMultipleColumnTab = (tabId) => { const tabs = ['tagged', 'vdom', 'object']; tabs.forEach(t => { const tabEl = document.getElementById(`multiple-column-tab-btn-${t}`); const contentEl = document.getElementById(`multiple-column-syntax-${t}`); if (t === tabId) { tabEl.classList.add('syntax-tab-active'); contentEl.style.display = 'block'; } else { tabEl.classList.remove('syntax-tab-active'); contentEl.style.display = 'none'; } }); }; </script> <div role="tablist" class="syntax-tabs" style="margin-bottom: 1rem;"> <button id="multiple-column-tab-btn-tagged" role="tab" class="syntax-tab syntax-tab-active" onclick="switchMultipleColumnTab('tagged')">Tagged</button> <button id="multiple-column-tab-btn-vdom" role="tab" class="syntax-tab" onclick="switchMultipleColumnTab('vdom')">vDOM</button> <button id="multiple-column-tab-btn-object" role="tab" class="syntax-tab" onclick="switchMultipleColumnTab('object')">Object DOM</button> </div> <!-- Tagged Syntax --> <div id="multiple-column-syntax-tagged"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 280, autoRun: true }); </script><code contenteditable="true">await import('/components/data-display/chart.js'); const { tags, $ } = Lightview; const { Chart } = tags; const chart = Chart({ type: 'column', multiple: true, labels: true, primaryAxis: true, primaryAxis: true, style: 'width: 100%; max-width: 600px; height: 280px; margin: 0 auto;' }, Chart.Body({}, Chart.Row({}, Chart.Label({}, 'Q1'), Chart.Data({ value: 0.4, color: '#4CAF50' }), Chart.Data({ value: 0.6, color: '#2196F3' }), Chart.Data({ value: 0.3, color: '#FF9800' }) ), Chart.Row({}, Chart.Label({}, 'Q2'), Chart.Data({ value: 0.5, color: '#4CAF50' }), Chart.Data({ value: 0.7, color: '#2196F3' }), Chart.Data({ value: 0.5, color: '#FF9800' }) ), Chart.Row({}, Chart.Label({}, 'Q3'), Chart.Data({ value: 0.7, color: '#4CAF50' }), Chart.Data({ value: 0.5, color: '#2196F3' }), Chart.Data({ value: 0.8, color: '#FF9800' }) ), Chart.Row({}, Chart.Label({}, 'Q4'), Chart.Data({ value: 0.9, color: '#4CAF50' }), Chart.Data({ value: 0.8, color: '#2196F3' }), Chart.Data({ value: 0.6, color: '#FF9800' }) ) ) ); $('#example').content(chart);</code></pre> </div> <!-- vDOM Syntax --> <div id="multiple-column-syntax-vdom" style="display: none;"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 280 }); </script><code contenteditable="true">await import('/components/data-display/chart.js'); const { tags, $ } = Lightview; const { Chart } = tags; const quarters = [ { label: 'Q1', values: [0.4, 0.6, 0.3] }, { label: 'Q2', values: [0.5, 0.7, 0.5] }, { label: 'Q3', values: [0.7, 0.5, 0.8] }, { label: 'Q4', values: [0.9, 0.8, 0.6] } ]; const colors = ['#4CAF50', '#2196F3', '#FF9800']; const chart = { tag: Chart, attributes: { type: 'column', multiple: true, primaryAxis: true, style: 'width: 100%; max-width: 600px; height: 280px; margin: 0 auto;' }, children: [ { tag: Chart.Body, children: quarters.map(q => ({ tag: Chart.Row, children: [ { tag: Chart.Label, children: [q.label] }, ...q.values.map((value, i) => ({ tag: Chart.Data, attributes: { value, color: colors[i] } })) ] })) } ] }; $('#example').content(chart);</code></pre> </div> <!-- Object DOM Syntax --> <div id="multiple-column-syntax-object" style="display: none;"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 280 }); </script><code contenteditable="true">await import('/components/data-display/chart.js'); const { $ } = Lightview; const chart = { Chart: { type: 'column', multiple: true, labels: true, primaryAxis: true, style: 'width: 100%; max-width: 600px; height: 280px; margin: 0 auto;', children: [ { 'Chart.Body': { children: [ { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Q1'] } }, { 'Chart.Data': { value: 0.4, color: '#4CAF50' } }, { 'Chart.Data': { value: 0.6, color: '#2196F3' } }, { 'Chart.Data': { value: 0.3, color: '#FF9800' } }] } }, { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Q2'] } }, { 'Chart.Data': { value: 0.5, color: '#4CAF50' } }, { 'Chart.Data': { value: 0.7, color: '#2196F3' } }, { 'Chart.Data': { value: 0.5, color: '#FF9800' } }] } }, { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Q3'] } }, { 'Chart.Data': { value: 0.7, color: '#4CAF50' } }, { 'Chart.Data': { value: 0.5, color: '#2196F3' } }, { 'Chart.Data': { value: 0.8, color: '#FF9800' } }] } }, { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Q4'] } }, { 'Chart.Data': { value: 0.9, color: '#4CAF50' } }, { 'Chart.Data': { value: 0.8, color: '#2196F3' } }, { 'Chart.Data': { value: 0.6, color: '#FF9800' } }] } } ] } } ] } }; $('#example').content(chart);</code></pre> </div> </div> </div> <!-- Axes --> <div class="card bg-base-200" style="margin-bottom: 2rem;"> <div class="card-body"> <h2 class="card-title">Axes</h2> <p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;"> Control axis visibility with <code>primaryAxis</code> and <code>secondaryAxis</code>. </p> <!-- Tabs --> <script> globalThis.switchAxesColumnTab = (tabId) => { const tabs = ['tagged', 'vdom', 'object']; tabs.forEach(t => { const tabEl = document.getElementById(`axes-column-tab-btn-${t}`); const contentEl = document.getElementById(`axes-column-syntax-${t}`); if (t === tabId) { tabEl.classList.add('syntax-tab-active'); contentEl.style.display = 'block'; } else { tabEl.classList.remove('syntax-tab-active'); contentEl.style.display = 'none'; } }); }; </script> <div role="tablist" class="syntax-tabs" style="margin-bottom: 1rem;"> <button id="axes-column-tab-btn-tagged" role="tab" class="syntax-tab syntax-tab-active" onclick="switchAxesColumnTab('tagged')">Tagged</button> <button id="axes-column-tab-btn-vdom" role="tab" class="syntax-tab" onclick="switchAxesColumnTab('vdom')">vDOM</button> <button id="axes-column-tab-btn-object" role="tab" class="syntax-tab" onclick="switchAxesColumnTab('object')">Object DOM</button> </div> <!-- Tagged Syntax --> <div id="axes-column-syntax-tagged"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 280, autoRun: true }); </script><code contenteditable="true">await import('/components/data-display/chart.js'); const { tags, $ } = Lightview; const { Chart, span } = tags; const chart = Chart({ type: 'column', labels: true, primaryAxis: true, secondaryAxesCount: 5, style: 'width: 100%; max-width: 600px; height: 280px; margin: 0 auto;' }, Chart.Body({}, Chart.Row({}, Chart.Label({}, 'A'), Chart.Data({ value: 0.2 }, span({ class: 'data' }, '20%'))), Chart.Row({}, Chart.Label({}, 'B'), Chart.Data({ value: 0.4 }, span({ class: 'data' }, '40%'))), Chart.Row({}, Chart.Label({}, 'C'), Chart.Data({ value: 0.6 }, span({ class: 'data' }, '60%'))), Chart.Row({}, Chart.Label({}, 'D'), Chart.Data({ value: 0.8 }, span({ class: 'data' }, '80%'))), Chart.Row({}, Chart.Label({}, 'E'), Chart.Data({ value: 1.0 }, span({ class: 'data' }, '100%'))) ) ); $('#example').content(chart);</code></pre> </div> <!-- vDOM Syntax --> <div id="axes-column-syntax-vdom" style="display: none;"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 280 }); </script><code contenteditable="true">await import('/components/data-display/chart.js'); const { tags, $ } = Lightview; const { Chart, span } = tags; const data = [ { label: 'A', value: 0.2, text: '20%' }, { label: 'B', value: 0.4, text: '40%' }, { label: 'C', value: 0.6, text: '60%' }, { label: 'D', value: 0.8, text: '80%' }, { label: 'E', value: 1.0, text: '100%' } ]; const chart = { tag: Chart, attributes: { type: 'column', labels: true, primaryAxis: true, secondaryAxesCount: 5, style: 'width: 100%; max-width: 600px; height: 280px; margin: 0 auto;' }, children: [ { tag: Chart.Body, children: data.map(d => ({ tag: Chart.Row, children: [ { tag: Chart.Label, children: [d.label] }, { tag: Chart.Data, attributes: { value: d.value }, children: [{ tag: span, attributes: { class: 'data' }, children: [d.text] }] } ] })) } ] }; $('#example').content(chart);</code></pre> </div> <!-- Object DOM Syntax --> <div id="axes-column-syntax-object" style="display: none;"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 280 }); </script><code contenteditable="true">await import('/components/data-display/chart.js'); const { $ } = Lightview; const chart = { Chart: { type: 'column', labels: true, primaryAxis: true, secondaryAxesCount: 5, style: 'width: 100%; max-width: 600px; height: 280px; margin: 0 auto;', children: [ { 'Chart.Body': { children: [ { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['A'] } }, { 'Chart.Data': { value: 0.2, children: [{ span: { class: 'data', children: ['20%'] } }] } }] } }, { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['B'] } }, { 'Chart.Data': { value: 0.4, children: [{ span: { class: 'data', children: ['40%'] } }] } }] } }, { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['C'] } }, { 'Chart.Data': { value: 0.6, children: [{ span: { class: 'data', children: ['60%'] } }] } }] } }, { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['D'] } }, { 'Chart.Data': { value: 0.8, children: [{ span: { class: 'data', children: ['80%'] } }] } }] } }, { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['E'] } }, { 'Chart.Data': { value: 1.0, children: [{ span: { class: 'data', children: ['100%'] } }] } }] } } ] } } ] } }; $('#example').content(chart);</code></pre> </div> </div> </div> </div> </div> </div> </div> </div>