Menu

Change language

GitHub repo

Slope Chart

slope-chartui

React mirror of @uipkge/slope-chart — see the Vue registry item for the canonical description.

Installation

$npx shadcn@latest add https://uipkge.dev/r/lit/slope-chart.json
Manifest:https://uipkge.dev/r/lit/slope-chart.jsonInstalls to:src/uip/components/charts/

Examples

Loading interactive previews…

Props

NameType / ValuesDefaultRequired
dataSlopeDatum[][]optional
pointsstring[][]optional
optionany—optional

Schema

Type aliases from this item's source — use them to shape the data you pass in.

SlopeDatum
interface SlopeDatum {
  /** One line per entry. Two values = slope chart, more = bump chart. */
  label: string
  values: number[]
}
HTMLElementTagNameMap
interface HTMLElementTagNameMap {
    'uip-slope-chart': UipSlopeChart
  }
}
ChartTheme
interface ChartTheme {
  colors: string[]
  textColor: string
  axisColor: string
  splitLineColor: string
  tooltipBg: string
  tooltipBorder: string
  tooltipText: string
  bgColor: string
  accentColor: string
  dangerColor: string
  /** `--card`: cell borders and inside-label text, so they read as gaps /
   *  contrast on light and dark surfaces (never '#fff'). */
  surfaceColor: string
  /** `--foreground`: primary numbers drawn on the canvas (gauge value). */
  foregroundColor: string
  /** Gauge stoplight from the status tokens, same rule as <uip-usage-bar>:
   *  < 70% success, 70-89% warning, >= 90% destructive. */
  semanticGaugeThresholds: [number, string][]
}

npm dependencies

Includes

Used by

Files installed (4)

  • src/uip/components/charts/slope-chart.ts3.2 kB
    import { ChartElement } from './lib/chart-element'
    import { mergeOptionBlock } from './lib/chart-theme'
    
    export interface SlopeDatum {
      /** One line per entry. Two values = slope chart, more = bump chart. */
      label: string
      values: number[]
    }
    
    /**
     * <uip-slope-chart> — the registry SlopeChart (React `SlopeChart`) as a web
     * component. Builds the same ECharts option as React for the same props.
     *
     * Properties (React props): `data` (SlopeDatum[]; JSON attribute or
     * property), `points` (point labels, e.g. ['2024', '2025']; property or JSON
     * attribute), `height` (default 320), `option` (ECharts escape hatch,
     * merged like React), `aria-label` (React `ariaLabel`). React's `className`
     * → host classes.
     */
    export class UipSlopeChart extends ChartElement {
      static properties = {
        data: { type: Array },
        points: { type: Array },
        option: { type: Object },
      }
    
      data: SlopeDatum[] = []
      points: string[] = []
      option?: any
      protected readonly chartSlot = 'slope-chart'
    
      constructor() {
        super()
        this.height = 320
      }
    
      protected buildOption() {
        const theme = this.chartTheme
        const data = this.data ?? []
        const series = data.map((d, i) => ({
          name: d.label,
          type: 'line',
          symbol: 'circle',
          symbolSize: 7,
          lineStyle: { width: 2, color: theme.colors[i % theme.colors.length] },
          itemStyle: { color: theme.colors[i % theme.colors.length] },
          label: {
            show: true,
            position: i % 2 ? 'right' : 'left',
            color: theme.textColor,
            fontSize: 10,
            formatter: '{a}',
          },
          endLabel: { show: true, color: theme.textColor, fontSize: 10, formatter: '{a}' },
          data: d.values,
        }))
        const userOption: any = this.option ?? {}
        const {
          series: userSeries,
          xAxis: userXAxis,
          yAxis: userYAxis,
          grid: userGrid,
          tooltip: userTooltip,
          legend: userLegend,
          ...userRest
        } = userOption
        const mergedSeries = Array.isArray(userSeries) ? series.map((s, i) => ({ ...s, ...(userSeries[i] ?? {}) })) : series
        return {
          color: theme.colors,
          grid: mergeOptionBlock({ left: 16, right: 64, top: 24, bottom: 24, containLabel: false }, userGrid),
          tooltip: mergeOptionBlock(
            {
              trigger: 'axis',
              backgroundColor: theme.tooltipBg,
              borderColor: theme.tooltipBorder,
              textStyle: { color: theme.tooltipText, fontSize: 12 },
            },
            userTooltip,
          ),
          legend: userLegend?.show === false ? undefined : mergeOptionBlock({ show: false }, userLegend),
          xAxis: mergeOptionBlock(
            {
              type: 'category',
              boundaryGap: false,
              data: this.points ?? [],
              axisLine: { lineStyle: { color: theme.axisColor } },
              axisLabel: { color: theme.textColor, fontSize: 11, fontWeight: 600 },
              axisTick: { show: false },
            },
            userXAxis,
          ),
          yAxis: mergeOptionBlock({ type: 'value', show: false, splitLine: { show: false } }, userYAxis),
          series: mergedSeries,
          ...userRest,
        }
      }
    }
    
    customElements.get('uip-slope-chart') || customElements.define('uip-slope-chart', UipSlopeChart)
    
    declare global {
      interface HTMLElementTagNameMap {
        'uip-slope-chart': UipSlopeChart
      }
    }
    
  • src/uip/components/charts/lib/chart-element.ts4.9 kB
  • src/uip/components/charts/lib/chart-theme.ts7.1 kB
  • src/uip/components/charts/lib/echarts.ts1.9 kB

Raw manifest:https://uipkge.dev/r/lit/slope-chart.json