Unovis Data Visualization Framework

repository·main·Indexed 25 days ago

https://github.com/f5/unovis

A modular, tree-shakable data visualization framework version 1.6.7. Unovis provides a core TypeScript engine (@unovis/ts) with dedicated integration packages for React, Angular, Svelte, Vue, and Solid, as well as support for vanilla TypeScript and JavaScript.

Tokens
82.3K
Snippets
172
Records
613
Agent score
80%

What's inside unovis

  1. Understand Unovis Containers

    main

    Most Unovis components require a Container to render. There are two primary types:

    • XY Container: Designed to manage multiple XY Components (such as Line, GroupedBar, or Scatter) along with optional Axis, Tooltip, and Crosshair components.
    • Single Container: Used for components that work with a single element, such as Graph, Sankey, or TopoJSONMap. It also supports Tooltip.

    Note: Some components like LeafletMap, LeafletFlowMap, and legends are stand-alone and do not require a container.

  2. Implement a new Unovis component core

    main

    To add a new component to the Unovis TypeScript core, create a new directory in packages/ts/src/components/<kebab-name>/ containing the following files:

    • config.ts: Define a ConfigInterface (using JSDoc for each property, ending with Default: ‘...’) and a Config class with defaults.
      • Extend XYComponentConfig* for XY components.
      • Extend ComponentConfig* for Core components.
      • Stand-alone components do not extend a superclass.
    • index.ts: Define the component class. It should extend XYComponentCore or ComponentCore (or stand alone). It must declare static selectors, static cssVariables, config, events, and a _render(customDuration?) (or render) method using D3 enter/update/exit selections.
    • style.ts: Define emotion css selectors and a cssVarDefaults map. CSS variables must follow the pattern --vis-<component>-<selector>-<property>. Every color variable requires a --vis-dark-... counterpart. Export variables = getCssVarNames(cssVarDefaults) and call injectGlobalCssVariables(...).
    • types.ts: (Optional) Component-specific types.
    • modules/: (Optional) Extract long render logic into helper functions.

    Style Guide: Use 2-space indentation, single quotes, no semicolons, and explicit return types.

  3. Quick Start: Create a Basic Line Chart in React

    main

    You can create a basic line chart by using VisXYContainer to wrap your data and axis components. Use VisLine to define the line, providing accessor functions for the x and y coordinates via useCallback to ensure performance and stability.

    import React, { useCallback } from 'react'
    import { VisXYContainer, VisLine, VisAxis } from '@unovis/react'
    
    export type DataRecord = { x: number; y: number }
    export const data: DataRecord[] = [
      { x: 0, y: 0 },
      { x: 1, y: 2 },
      { x: 2, y: 1 },
    ]
    
    export function BasicLineChart (): JSX.Element {
      return (
        <VisXYContainer data={data} height={600}>
          <VisLine<DataRecord>
            x={useCallback(d => d.x, [])}
            y={useCallback(d => d.y, [])}
          ></VisLine>
          <VisAxis type="x"></VisAxis>
          <VisAxis type="y"></VisAxis>
        </VisXYContainer>
      )
    }
  4. Customize Unovis components with CSS Variables

    main

    Unovis components use CSS variables to control SVG attributes like fill, stroke, and opacity. You can override these variables in your CSS to customize component appearance.

    Naming Convention: Variables follow the pattern --vis-[label]-[attribute]. For example, --vis-area-cursor targets the cursor property of the Area component.

    Usage: Apply custom styles to the container element of your Unovis component. For example, to customize a Sankey component, add a custom class to its container and define the variables in your CSS.

  5. Format PR titles and bodies for Unovis

    main

    Follow these templates for your Pull Request metadata:

    PR Title

    • New components: New Component: <Name> (<milestone>) (e.g., New Component: Boxplot (1.7)).
    • Other changes: Use a concise, specific summary.

    PR Body

    Use the checklist template below. For new components, tick the applicable boxes. For non-component PRs, provide a short summary of what changed and why, and list the surfaces touched (core, dev, docs, or wrappers).

    Adding a new `<Name>` <XY/Core/standalone> component
    
    - [x] Dev examples
    - [x] Wrappers
    - [x] Gallery example
    - [x] Docs
    
    <!-- Light + dark screenshots and/or a short screen recording of the component -->

    Important: Always attach both light and dark mode screenshots (and a short recording for interactive components).

  6. Follow the Unovis custom commit format

    main

    Unovis uses a custom commit message format that is enforced via a commit-msg hook. Do not use Conventional Commits (e.g., feat:, fix:); these will be rejected.

    Format:

    Type | Scope | Subscope | Subscope2: Sentence-case subject

    Rules:

    • Type (Required): Must be one of the allowed types (see Picking the type and scope).
    • Subject (Required): Must be in sentence case (e.g., Add new feature), must not be empty, and must not have a trailing period. Use backticks for code or prop names (e.g., `brushHeightExtend`).
    • Scope/Subscope (Optional): Separated by | (space-pipe-space). Subscopes should be PascalCase.
    Type | Scope | Subscope | Subscope2: Sentence-case subject
  7. Prepare a branch and commits for a Unovis Pull Request

    main

    When contributing to Unovis, follow these branching and commit conventions:

    Branching

    • Always branch off main. Never commit directly to main.
    • Use descriptive names like feat/boxplot or fix/crosshair-threshold.
    • Note: First-time contributors will be prompted by the F5 CLA bot to sign the CLA. There is no DCO or Signed-off-by requirement.

    Commit Grouping

    For new components, split your work into these four logical commits to match maintainer standards:

    1. Component | <Name>: New component: Includes packages/ts core (config, index, style, types, modules), export wiring, and registry entry.
    2. Dev | Examples: <Name> examples: Includes packages/dev pages.
    3. Misc: Framework integrations: Includes regenerated wrappers for React, Angular, Svelte, Vue, and Solid.
    4. Website: <Name> docs and gallery example: Includes .mdx docs, packages/shared/examples gallery entries, and previews.

    For smaller changes, a single well-scoped commit is acceptable, but try to keep core, dev, website, and wrapper concerns separate if they coexist.

  8. Configure TypeScript for Unovis

    main

    To use Unovis with TypeScript, you may need to adjust your tsconfig.json settings:

    1. Enable allowSyntheticDefaultImports in the compilerOptions section.
    2. If you have an explicit types array in tsconfig.json, add "topojson-client" to the list to ensure TopoJSON types are found.