Horizontal Line Graph
<loomi-horizontal-line-graph> — a single proportion bar split into colored segments,
with an optional legend. Good for showing how a whole breaks down into parts — market
share, demographic split, budget allocation.
npm install @loomidev/horizontal-line-graph litimport "@loomidev/horizontal-line-graph";Basic Usage
Section titled “Basic Usage”<loomi-horizontal-line-graph id="g"></loomi-horizontal-line-graph>
<script type="module"> document.getElementById("g").data = [ { label: "Direct", value: 45, color: "primary" }, { label: "Search", value: 30, color: "success" }, { label: "Social", value: 25, color: "warning" }, ];</script>Custom Segment Colors
Section titled “Custom Segment Colors”color on each segment accepts any loomi color name or a raw CSS color.
<loomi-horizontal-line-graph id="ages"></loomi-horizontal-line-graph>
<script type="module"> document.getElementById("ages").data = [ { label: "Under 40", value: 24, color: "warning" }, { label: "40–60", value: 43, color: "#a855f7" }, { label: "Above 60", value: 33, color: "gray" }, ];</script>Hiding the Legend or Values
Section titled “Hiding the Legend or Values”<loomi-horizontal-line-graph id="g2" show-legend="false"></loomi-horizontal-line-graph><loomi-horizontal-line-graph id="g3" show-values="false"></loomi-horizontal-line-graph>Practical Example: Side-by-Side Cards
Section titled “Practical Example: Side-by-Side Cards”<div style="display:grid;grid-template-columns:repeat(2,1fr);gap:1.5rem"> <loomi-card title="Mobile Money Penetration"> <loomi-horizontal-line-graph id="mm"></loomi-horizontal-line-graph> </loomi-card> <loomi-card title="Farmer Age Ratio"> <loomi-horizontal-line-graph id="age"></loomi-horizontal-line-graph> </loomi-card></div>
<script type="module"> document.getElementById("mm").data = [ { label: "MTN", value: 55, color: "yellow" }, { label: "Vodafone", value: 30, color: "error" }, { label: "AirtelTigo", value: 15, color: "primary" }, ]; document.getElementById("age").data = [ { label: "Above 60", value: 33, color: "warning" }, { label: "40–60", value: 43, color: "success" }, { label: "Under 40", value: 24, color: "gray" }, ];</script>Accessibility
Section titled “Accessibility”- Legend repeats segment labels for sighted users.
For the library-wide baseline, see Foundations — Accessibility.
Responsive behavior
Section titled “Responsive behavior”For the shared container and viewport rules, see Foundations — Responsive behavior.
Dark mode
Section titled “Dark mode”For theme activation, token overrides, and contrast guidance, see Foundations — Dark mode.
Attributes
Section titled “Attributes”| Attribute | Default | Description |
|---|---|---|
data | [] | Segments — { label, value, color? }[] (loomi color name or any CSS color). |
show-legend | true | Show the legend. (boolean) |
show-values | true | Show each segment’s percentage. (boolean) |
Full Example
Section titled “Full Example”<loomi-horizontal-line-graph id="full-graph"></loomi-horizontal-line-graph>
<script type="module"> document.getElementById("full-graph").data = [ { label: "Women Farmers", value: 55.8, color: "error" }, { label: "Men Farmers", value: 44.2, color: "primary" }, ];</script>Framework integration
Section titled “Framework integration”<loomi-horizontal-line-graph> is a standard custom element, so the browser can use it in plain HTML, Blade, React, Vue, Angular, Svelte, Astro, and most other frameworks. The important beginner rule is: install the package, import it once before the tag is rendered, then write the Loomi tag in your template.
Where to run commands
Section titled “Where to run commands”Run install commands from the app where you want to use this component. That means the folder that contains that app’s package.json. Do not run these install commands from packages/horizontal-line-graph unless you are editing LoomiUI itself.
cd /path/to/your-appnpm install @loomidev/horizontal-line-graph litIf you are contributing to LoomiUI itself, first move to the top-level components folder. That is where the main package.json for all packages lives, and pnpm --filter ... commands should be run from there:
cd /path/to/your-copy-of-loomiui/componentspnpm --filter @loomidev/horizontal-line-graph buildpnpm --filter @loomidev/horizontal-line-graph typecheckChoose your framework
Section titled “Choose your framework”Use the CDN version for prototypes, documentation pages, or a quick reproduction. The import map tells the browser where to find Lit, which Loomi components use internally.
<script type="importmap"> { "imports": { "lit": "https://esm.sh/lit@3.3.3", "lit/": "https://esm.sh/lit@3.3.3/" } }</script><script type="module" src="https://esm.sh/@loomidev/horizontal-line-graph"></script>
<loomi-horizontal-line-graph id="traffic-sources"></loomi-horizontal-line-graph>In Vite, Webpack, Parcel, Rollup, or a framework build pipeline, install the package and import it once in your main app JavaScript file. After that, you can use the Loomi tag anywhere in your app.
import "@loomidev/horizontal-line-graph";This component accepts data as a JavaScript property. Use an HTML attribute only for simple strings; use a property when you pass arrays, objects, or functions.
const el = document.querySelector("loomi-horizontal-line-graph");el.data = [{ label: "Direct", value: 45, color: "primary" }, { label: "Search", value: 30, color: "success" }];Run the install command from your Laravel project root, then import the component in resources/js/app.js. If your project uses Laravel Vite, npm run dev and npm run build should also be run from the Laravel project root.
cd /path/to/your-laravel-appnpm install @loomidev/horizontal-line-graph litnpm run devimport "@loomidev/horizontal-line-graph";<loomi-horizontal-line-graph id="traffic-sources"></loomi-horizontal-line-graph>React can render Loomi tags directly. If you are on React 18, or if you need to pass arrays, objects, or functions, use a ref and assign those values after the component mounts.
import { useEffect, useRef } from "react";import "@loomidev/horizontal-line-graph";
export function LoomiExample() { const el = useRef(null);
useEffect(() => { el.current.data = [{ label: "Direct", value: 45, color: "primary" }, { label: "Search", value: 30, color: "success" }]; }, []);
return <loomi-horizontal-line-graph ref={el}></loomi-horizontal-line-graph>;}If TypeScript does not recognize the Loomi tag in JSX, add it to your app’s JSX type declarations.
Import the package in the component that uses it, or once in your main Vue file. Vue templates can use Loomi tags directly. For arrays, objects, or functions, pass the value as a JavaScript property instead of as plain text.
<script setup>import { onMounted, ref } from "vue";import "@loomidev/horizontal-line-graph";
const el = ref(null);
onMounted(() => { el.value.data = [{ label: "Direct", value: 45, color: "primary" }, { label: "Search", value: 30, color: "success" }];});</script>
<template> <loomi-horizontal-line-graph ref="el"></loomi-horizontal-line-graph></template>If Vue warns that the tag is an unknown component, configure compilerOptions.isCustomElement for tags that start with loomi- in your Vite or Vue config.
Import the package once and tell Angular to allow custom HTML tags with CUSTOM_ELEMENTS_SCHEMA. For NgModule apps, add the schema to the module instead of the standalone component.
import { AfterViewInit, CUSTOM_ELEMENTS_SCHEMA, Component, ElementRef, ViewChild } from "@angular/core";import "@loomidev/horizontal-line-graph";
@Component({ selector: "app-root", standalone: true, schemas: [CUSTOM_ELEMENTS_SCHEMA], template: ` <loomi-horizontal-line-graph #el></loomi-horizontal-line-graph> `,})export class AppComponent implements AfterViewInit { @ViewChild("el") el!: ElementRef<any>;
ngAfterViewInit() { this.el.nativeElement.data = [{ label: "Direct", value: 45, color: "primary" }, { label: "Search", value: 30, color: "success" }]; }}Svelte can import the package inside a component script. Astro can import it in the frontmatter of the page or layout where the tag appears.
<script> import { onMount } from "svelte"; import "@loomidev/horizontal-line-graph";
let el;
onMount(() => { el.data = [{ label: "Direct", value: 45, color: "primary" }, { label: "Search", value: 30, color: "success" }]; });</script>
<loomi-horizontal-line-graph bind:this={el}></loomi-horizontal-line-graph>---import "@loomidev/horizontal-line-graph";---
<loomi-horizontal-line-graph id="traffic-sources"></loomi-horizontal-line-graph>Server-side rendering notes
Section titled “Server-side rendering notes”Frameworks such as Next.js, Nuxt, SvelteKit, and Astro sometimes render HTML on the server before browser-only code runs. If your framework complains, move the Loomi import to client-side code. In Next.js, that usually means a component with "use client"; in Nuxt, it often means a .client.ts plugin.
Dependencies
Section titled “Dependencies”@loomidev/core