@molecule/app-chart-wrapper-vue
Feature · chart-wrapper · App (browser) · v1.1.2 · Apache-2.0
Vue ChartCard and ChartLegend wrappers around @molecule/app-charts
npm install @molecule/app-chart-wrapper-vueHow it works
@molecule/app-chart-wrapper-vue is a ready-made chart-wrapper feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
import { defineComponent, h, onMounted, onBeforeUnmount, ref } from 'vue'
import { ChartCard, ChartLegend } from '@molecule/app-chart-wrapper-vue'
import { createBarChart } from '@molecule/app-charts'
const RevenueChart = defineComponent({
setup() {
const el = ref<HTMLCanvasElement | null>(null)
let chart: { destroy(): void } | undefined
onMounted(() => {
if (!el.value) return
chart = createBarChart(el.value, {
labels: ['Jan', 'Feb', 'Mar'],
datasets: [{ label: 'Revenue', data: [4200, 5800, 5100] }],
})
})
onBeforeUnmount(() => chart?.destroy())
return () => h('canvas', { ref: el, height: 240 })
},
})
const Chart = defineComponent({
setup() {
return () =>
h(
ChartCard,
{ title: 'Monthly Revenue', description: 'Last 12 months' },
{
default: () => [h(RevenueChart)],
footer: () => [
h(ChartLegend, {
items: [
{ id: 'revenue', label: 'Revenue', color: '#4f46e5' },
{ id: 'expenses', label: 'Expenses', color: '#e11d48' },
],
}),
],
},
)
},
})Works with: @molecule/app-ui, @molecule/app-ui-vue, @molecule/app-vue
Reference
Vue ChartCard + ChartLegend wrappers around @molecule/app-charts.
Exports:
<ChartCard>— uniform chrome (title / description / actions / summary / body / footer) around a chart rendering.minChartHeight(default 240) stops responsive charts collapsing;dataMolIdsetsdata-mol-id.<ChartLegend>— swatch + label (+ value) legend. Items become toggle buttons whenonToggleis provided.ChartLegendItemtype.
These wrappers provide ONLY the surrounding chrome. The chart itself is
whatever you render as the default slot — typically a canvas driven by
createLineChart/createBarChart from @molecule/app-charts (via a real
bonded ChartProvider) or your own chart component. There is no <BarChart>
component in @molecule/app-charts.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
import { defineComponent, h, onMounted, onBeforeUnmount, ref } from 'vue'
import { ChartCard, ChartLegend } from '@molecule/app-chart-wrapper-vue'
import { createBarChart } from '@molecule/app-charts'
const RevenueChart = defineComponent({
setup() {
const el = ref<HTMLCanvasElement | null>(null)
let chart: { destroy(): void } | undefined
onMounted(() => {
if (!el.value) return
chart = createBarChart(el.value, {
labels: ['Jan', 'Feb', 'Mar'],
datasets: [{ label: 'Revenue', data: [4200, 5800, 5100] }],
})
})
onBeforeUnmount(() => chart?.destroy())
return () => h('canvas', { ref: el, height: 240 })
},
})
const Chart = defineComponent({
setup() {
return () =>
h(
ChartCard,
{ title: 'Monthly Revenue', description: 'Last 12 months' },
{
default: () => [h(RevenueChart)],
footer: () => [
h(ChartLegend, {
items: [
{ id: 'revenue', label: 'Revenue', color: '#4f46e5' },
{ id: 'expenses', label: 'Expenses', color: '#e11d48' },
],
}),
],
},
)
},
})
Type
feature
Installation
npm install @molecule/app-chart-wrapper-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue
API
Interfaces
ChartCardProps
Props accepted by the ChartCard component.
interface ChartCardProps {
/**
* Card heading (a node, also accepted as the same-named slot). Required by
* the component: one of the prop and the slot must carry it.
*/
title?: VNodeChild
/** Optional supporting description (a node, or its same-named slot). */
description?: VNodeChild
/** Optional right-aligned actions (range selector, export menu, filter), a node or its slot. */
actions?: VNodeChild
/** Optional KPI summary row shown between header and chart, a node or its slot. */
summary?: VNodeChild
/** Chart content — the DEFAULT slot. */
children?: VNodeChild
/** Optional footer below the chart (legend, source attribution), a node or its slot. */
footer?: VNodeChild
/** Set a minimum chart height so responsive charts don't collapse. Defaults to `240`. */
minChartHeight?: number
/** Extra classes on the Card. */
className?: string
/** `data-mol-id` for AI-agent selectors. */
dataMolId?: string
}
ChartLegendItem
Describes a single series entry rendered in the chart legend.
interface ChartLegendItem {
/** Series id — the value `onToggle` receives. */
id: string
/** Series label (a node). */
label: VNodeChild
/** Swatch color (any valid CSS color or ClassMap token string). */
color: string
/** Optional value / count display next to the label (a node). */
value?: VNodeChild
/** Whether the series is hidden (greyed out). */
hidden?: boolean
}
ChartLegendProps
Props accepted by the ChartLegend component.
interface ChartLegendProps {
/** The legend's series. */
items: ChartLegendItem[]
/** Called when an item is toggled. */
onToggle?: (id: string) => void
/** Layout direction. Defaults to `'horizontal'`. */
layout?: 'horizontal' | 'vertical'
/** Extra classes. */
className?: string
}
Constants
ChartCard
Uniform chrome around a chart rendering — header + actions + optional summary strip + chart body + optional footer.
The chart library itself comes from the @molecule/app-charts bond; this
package only provides the surrounding container.
const ChartCard: DefineComponent<
ExtractPropTypes<{
title: null
description: null
actions: null
summary: null
footer: null
minChartHeight: { type: PropType<ChartCardProps['minChartHeight']>; default: number }
className: StringConstructor
dataMolId: StringConstructor
}>,
() => VNode,
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
{},
string,
PublicProps,
Readonly<
ExtractPropTypes<{
title: null
description: null
actions: null
summary: null
footer: null
minChartHeight: { type: PropType<ChartCardProps['minChartHeight']>; default: number }
className: StringConstructor
dataMolId: StringConstructor
}>
> &
Readonly<{}>,
{ minChartHeight: number | undefined },
{},
{},
{},
string,
ComponentProvideOptions,
true,
{},
any
>
props— Component props (seeChartCardProps).
Returns: The chart card component.
ChartLegend
Chart legend — swatch + label (+ optional value) per series. When
onToggle is provided, items become buttons that toggle series visibility.
const ChartLegend: DefineComponent<
ExtractPropTypes<{
items: { type: PropType<ChartLegendItem[]>; required: true }
onToggle: PropType<ChartLegendProps['onToggle']>
layout: { type: PropType<'horizontal' | 'vertical'>; default: string }
className: StringConstructor
}>,
() => VNode,
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
{},
string,
PublicProps,
Readonly<
ExtractPropTypes<{
items: { type: PropType<ChartLegendItem[]>; required: true }
onToggle: PropType<ChartLegendProps['onToggle']>
layout: { type: PropType<'horizontal' | 'vertical'>; default: string }
className: StringConstructor
}>
> &
Readonly<{}>,
{ layout: 'horizontal' | 'vertical' },
{},
{},
{},
string,
ComponentProvideOptions,
true,
{},
any
>
props— Component props (seeChartLegendProps).
Returns: The chart legend component.
Injection Notes
Requirements
Peer dependencies:
@molecule/app-ui^1.0.1@molecule/app-ui-vue^1.1.0@molecule/app-vue^3.13.0 || ^4.0.0vue^3.4.0
Runtime Dependencies
@molecule/app-ui@molecule/app-ui-vue@molecule/app-vuevue
@molecule/app-charts' built-in provider renders a non-functional placeholder
notice (and logs a one-time console warning), not a real chart. Bond the
Chart.js provider once at startup — import { provider } from '@molecule/app-charts-chartjs'; setProvider(provider) — so createChart /
createBarChart draw real charts (or render your own chart component as the
default slot). Legend items labels/values are consumer-provided nodes; pass
translated strings via t(). Node-valued props (title, description,
actions, summary, footer) arrive as a prop AND a same-named slot;
components accept either.