lightview
Version:
A reactive UI library with features of Bau, Juris, and HTMX plus safe LLM UI generation
605 lines (562 loc) • 30.1 kB
HTML
<!-- 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 Bar' }
]
});
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 Bar</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;">
Bar charts display data as horizontal bars. The bar length 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 bar chart, use <code>type: 'bar'</code>.
</p>
<!-- Tabs -->
<script>
globalThis.switchBasicBarTab = (tabId) => {
const tabs = ['tagged', 'vdom', 'object'];
tabs.forEach(t => {
const tabEl = document.getElementById(`basic-bar-tab-btn-${t}`);
const contentEl = document.getElementById(`basic-bar-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-bar-tab-btn-tagged" role="tab" class="syntax-tab syntax-tab-active"
onclick="switchBasicBarTab('tagged')">Tagged</button>
<button id="basic-bar-tab-btn-vdom" role="tab" class="syntax-tab"
onclick="switchBasicBarTab('vdom')">vDOM</button>
<button id="basic-bar-tab-btn-object" role="tab" class="syntax-tab"
onclick="switchBasicBarTab('object')">Object DOM</button>
</div>
<!-- Tagged Syntax -->
<div id="basic-bar-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: 200,
autoRun: true
});
</script><code contenteditable="true">await import('/components/data-display/chart.js');
const { tags, $ } = Lightview;
const { Chart, span } = tags;
const chart = Chart({
type: 'bar',
labels: true,
style: 'width: 100%; max-width: 600px; margin: 0 auto;'
},
Chart.Body({},
Chart.Row({},
Chart.Label({}, 'Item 1'),
Chart.Data({ value: 0.4 }, span({ class: 'data' }, '40%'))
),
Chart.Row({},
Chart.Label({}, 'Item 2'),
Chart.Data({ value: 0.6 }, span({ class: 'data' }, '60%'))
),
Chart.Row({},
Chart.Label({}, 'Item 3'),
Chart.Data({ value: 0.8 }, span({ class: 'data' }, '80%'))
)
)
);
$('#example').content(chart);</code></pre>
</div>
<!-- vDOM Syntax -->
<div id="basic-bar-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: 200
});
</script><code contenteditable="true">await import('/components/data-display/chart.js');
const { tags, $ } = Lightview;
const { Chart, span } = tags;
const items = [
{ label: 'Item 1', value: 0.4, text: '40%' },
{ label: 'Item 2', value: 0.6, text: '60%' },
{ label: 'Item 3', value: 0.8, text: '80%' }
];
const chart = {
tag: Chart,
attributes: { type: 'bar', labels: true, style: 'width: 100%; max-width: 600px; margin: 0 auto;' },
children: [
{
tag: Chart.Body,
children: items.map(item => ({
tag: Chart.Row,
children: [
{ tag: Chart.Label, children: [item.label] },
{
tag: Chart.Data,
attributes: { value: item.value },
children: [{ tag: span, attributes: { class: 'data' }, children: [item.text] }]
}
]
}))
}
]
};
$('#example').content(chart);</code></pre>
</div>
<!-- Object DOM Syntax -->
<div id="basic-bar-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: 200
});
</script><code contenteditable="true">await import('/components/data-display/chart.js');
const { $ } = Lightview;
const chart = {
Chart: {
type: 'bar',
labels: true,
style: 'width: 100%; max-width: 600px; margin: 0 auto;',
children: [
{
'Chart.Body': {
children: [
{
'Chart.Row': {
children: [
{ 'Chart.Label': { children: ['Item 1'] } },
{ 'Chart.Data': { value: 0.4, children: [{ span: { class: 'data', children: ['40%'] } }] } }
]
}
},
{
'Chart.Row': {
children: [
{ 'Chart.Label': { children: ['Item 2'] } },
{ 'Chart.Data': { value: 0.6, children: [{ span: { class: 'data', children: ['60%'] } }] } }
]
}
},
{
'Chart.Row': {
children: [
{ 'Chart.Label': { children: ['Item 3'] } },
{ 'Chart.Data': { value: 0.8, children: [{ span: { class: 'data', children: ['80%'] } }] } }
]
}
}
]
}
}
]
}
};
$('#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.switchMultipleBarTab = (tabId) => {
const tabs = ['tagged', 'vdom', 'object'];
tabs.forEach(t => {
const tabEl = document.getElementById(`multiple-bar-tab-btn-${t}`);
const contentEl = document.getElementById(`multiple-bar-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-bar-tab-btn-tagged" role="tab" class="syntax-tab syntax-tab-active"
onclick="switchMultipleBarTab('tagged')">Tagged</button>
<button id="multiple-bar-tab-btn-vdom" role="tab" class="syntax-tab"
onclick="switchMultipleBarTab('vdom')">vDOM</button>
<button id="multiple-bar-tab-btn-object" role="tab" class="syntax-tab"
onclick="switchMultipleBarTab('object')">Object DOM</button>
</div>
<!-- Tagged Syntax -->
<div id="multiple-bar-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: 220,
autoRun: true
});
</script><code contenteditable="true">await import('/components/data-display/chart.js');
const { tags, $ } = Lightview;
const { Chart, span } = tags;
const chart = Chart({
type: 'bar',
multiple: true,
labels: true,
primaryAxis: true,
primaryAxis: true,
style: 'width: 100%; max-width: 600px; margin: 0 auto;'
},
Chart.Body({},
Chart.Row({},
Chart.Label({}, 'Q1'),
Chart.Data({ value: 0.3, color: '#4CAF50' }, span({ class: 'data' }, 'East')),
Chart.Data({ value: 0.5, color: '#2196F3' }, span({ class: 'data' }, 'West')),
Chart.Data({ value: 0.4, color: '#FF9800' }, span({ class: 'data' }, 'North'))
),
Chart.Row({},
Chart.Label({}, 'Q2'),
Chart.Data({ value: 0.5, color: '#4CAF50' }, span({ class: 'data' }, 'East')),
Chart.Data({ value: 0.6, color: '#2196F3' }, span({ class: 'data' }, 'West')),
Chart.Data({ value: 0.7, color: '#FF9800' }, span({ class: 'data' }, 'North'))
),
Chart.Row({},
Chart.Label({}, 'Q3'),
Chart.Data({ value: 0.7, color: '#4CAF50' }, span({ class: 'data' }, 'East')),
Chart.Data({ value: 0.8, color: '#2196F3' }, span({ class: 'data' }, 'West')),
Chart.Data({ value: 0.5, color: '#FF9800' }, span({ class: 'data' }, 'North'))
)
)
);
$('#example').content(chart);</code></pre>
</div>
<!-- vDOM Syntax -->
<div id="multiple-bar-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: 220
});
</script><code contenteditable="true">await import('/components/data-display/chart.js');
const { tags, $ } = Lightview;
const { Chart, span } = tags;
const quarters = [
{ label: 'Q1', values: [0.3, 0.5, 0.4] },
{ label: 'Q2', values: [0.5, 0.6, 0.7] },
{ label: 'Q3', values: [0.7, 0.8, 0.5] }
];
const regions = ['East', 'West', 'North'];
const colors = ['#4CAF50', '#2196F3', '#FF9800'];
const chart = {
tag: Chart,
attributes: {
type: 'bar',
multiple: true,
labels: true,
primaryAxis: true,
primaryAxis: true,
style: 'width: 100%; max-width: 600px; 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] },
children: [{ tag: span, attributes: { class: 'data' }, children: [regions[i]] }]
}))
]
}))
}
]
};
$('#example').content(chart);</code></pre>
</div>
<!-- Object DOM Syntax -->
<div id="multiple-bar-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: 220
});
</script><code contenteditable="true">await import('/components/data-display/chart.js');
const { $ } = Lightview;
const chart = {
Chart: {
type: 'bar',
multiple: true,
labels: true,
primaryAxis: true,
primaryAxis: true,
style: 'width: 100%; max-width: 600px; margin: 0 auto;',
children: [
{
'Chart.Body': {
children: [
{
'Chart.Row': {
children: [
{ 'Chart.Label': { children: ['Q1'] } },
{ 'Chart.Data': { value: 0.3, color: '#4CAF50', children: [{ span: { class: 'data', children: ['East'] } }] } },
{ 'Chart.Data': { value: 0.5, color: '#2196F3', children: [{ span: { class: 'data', children: ['West'] } }] } },
{ 'Chart.Data': { value: 0.4, color: '#FF9800', children: [{ span: { class: 'data', children: ['North'] } }] } }
]
}
},
{
'Chart.Row': {
children: [
{ 'Chart.Label': { children: ['Q2'] } },
{ 'Chart.Data': { value: 0.5, color: '#4CAF50', children: [{ span: { class: 'data', children: ['East'] } }] } },
{ 'Chart.Data': { value: 0.6, color: '#2196F3', children: [{ span: { class: 'data', children: ['West'] } }] } },
{ 'Chart.Data': { value: 0.7, color: '#FF9800', children: [{ span: { class: 'data', children: ['North'] } }] } }
]
}
},
{
'Chart.Row': {
children: [
{ 'Chart.Label': { children: ['Q3'] } },
{ 'Chart.Data': { value: 0.7, color: '#4CAF50', children: [{ span: { class: 'data', children: ['East'] } }] } },
{ 'Chart.Data': { value: 0.8, color: '#2196F3', children: [{ span: { class: 'data', children: ['West'] } }] } },
{ 'Chart.Data': { value: 0.5, color: '#FF9800', children: [{ span: { class: 'data', children: ['North'] } }] } }
]
}
}
]
}
}
]
}
};
$('#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.switchAxesBarTab = (tabId) => {
const tabs = ['tagged', 'vdom', 'object'];
tabs.forEach(t => {
const tabEl = document.getElementById(`axes-bar-tab-btn-${t}`);
const contentEl = document.getElementById(`axes-bar-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-bar-tab-btn-tagged" role="tab" class="syntax-tab syntax-tab-active"
onclick="switchAxesBarTab('tagged')">Tagged</button>
<button id="axes-bar-tab-btn-vdom" role="tab" class="syntax-tab"
onclick="switchAxesBarTab('vdom')">vDOM</button>
<button id="axes-bar-tab-btn-object" role="tab" class="syntax-tab"
onclick="switchAxesBarTab('object')">Object DOM</button>
</div>
<!-- Tagged Syntax -->
<div id="axes-bar-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: 220,
autoRun: true
});
</script><code contenteditable="true">await import('/components/data-display/chart.js');
const { tags, $ } = Lightview;
const { Chart, span } = tags;
const chart = Chart({
type: 'bar',
labels: true,
primaryAxis: true,
secondaryAxesCount: 4,
style: 'width: 100%; max-width: 600px; margin: 0 auto;'
},
Chart.Body({},
Chart.Row({}, Chart.Label({}, 'Jan'), Chart.Data({ value: 0.25 }, span({ class: 'data' }, '25%'))),
Chart.Row({}, Chart.Label({}, 'Feb'), Chart.Data({ value: 0.5 }, span({ class: 'data' }, '50%'))),
Chart.Row({}, Chart.Label({}, 'Mar'), Chart.Data({ value: 0.75 }, span({ class: 'data' }, '75%'))),
Chart.Row({}, Chart.Label({}, 'Apr'), Chart.Data({ value: 1.0 }, span({ class: 'data' }, '100%')))
)
);
$('#example').content(chart);</code></pre>
</div>
<!-- vDOM Syntax -->
<div id="axes-bar-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: 220
});
</script><code contenteditable="true">await import('/components/data-display/chart.js');
const { tags, $ } = Lightview;
const { Chart, span } = tags;
const months = [
{ label: 'Jan', value: 0.25, text: '25%' },
{ label: 'Feb', value: 0.5, text: '50%' },
{ label: 'Mar', value: 0.75, text: '75%' },
{ label: 'Apr', value: 1.0, text: '100%' }
];
const chart = {
tag: Chart,
attributes: {
type: 'bar',
labels: true,
primaryAxis: true,
secondaryAxis: 'show-4-secondary-axes',
style: 'width: 100%; max-width: 600px; 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="axes-bar-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: 220
});
</script><code contenteditable="true">await import('/components/data-display/chart.js');
const { $ } = Lightview;
const chart = {
Chart: {
type: 'bar',
labels: true,
primaryAxis: true,
secondaryAxis: 'show-4-secondary-axes',
style: 'width: 100%; max-width: 600px; margin: 0 auto;',
children: [
{
'Chart.Body': {
children: [
{ 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Jan'] } }, { 'Chart.Data': { value: 0.25, children: [{ span: { class: 'data', children: ['25%'] } }] } }] } },
{ 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Feb'] } }, { 'Chart.Data': { value: 0.5, children: [{ span: { class: 'data', children: ['50%'] } }] } }] } },
{ 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Mar'] } }, { 'Chart.Data': { value: 0.75, children: [{ span: { class: 'data', children: ['75%'] } }] } }] } },
{ 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Apr'] } }, { 'Chart.Data': { value: 1.0, children: [{ span: { class: 'data', children: ['100%'] } }] } }] } }
]
}
}
]
}
};
$('#example').content(chart);</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>