Menu

Change language

GitHub repo

Theme River

theme-riverui

Theme-river (streamgraph) wrapper around Apache ECharts. Stacked areas centred on a baseline along a time axis — good for topic-volume drift over time.

Installation

$npx uipkge-ng@latest add theme-river
Manifest:https://uipkge.dev/r/angular/theme-river.jsonInstalls to:src/app/components/ui/charts/theme-river/

Examples

Loading interactive previews…

Props

NameType / ValuesDefaultRequired
data

`[time, value, category]` event tuples.

[string | number, number, string][][]optional
heightnumber | string320optional
optionRecord<string, unknown>—optional
ariaLabel

Accessible name announced for the chart image. Defaults to "Chart".

string—optional
classstring—optional

npm dependencies

Used by

Files installed (3)

  • src/app/components/ui/charts/theme-river/theme-river.component.ts5.1 kB
    import {
      AfterViewInit,
      Component,
      ElementRef,
      Input,
      OnChanges,
      OnDestroy,
      SimpleChanges,
      ViewChild,
      ChangeDetectionStrategy,
    } from '@angular/core'
    import type * as echarts from 'echarts/core'
    import { cn } from '@/lib/utils'
    import {
      getChartAxisColor,
      getChartColors,
      getChartTextColor,
      getChartTooltipBg,
      getChartTooltipBorder,
      getChartTooltipText,
      mergeOptionBlock,
    } from '../use-chart-theme'
    
    /**
     * Angular port of the UIPKGE ThemeRiver — streamgraph centred on a baseline. Standalone, theme-aware. Same inputs as the Vue `ThemeRiver` (`data`, `height`, `option`).
     */
    @Component({
      changeDetection: ChangeDetectionStrategy.Eager,
      selector: 'ui-theme-river, [ui-theme-river]',
      standalone: true,
      host: {
        '[attr.data-slot]': '"theme-river"',
        '[attr.data-uipkge]': '""',
        '[class]': 'hostClass',
        '[attr.role]': '"img"',
        '[attr.aria-label]': 'ariaLabel || "Chart"',
        '[style.height]': 'heightStyle',
      },
      template: `<div #chartEl class="size-full"></div>`,
    })
    export class UiThemeRiverComponent implements AfterViewInit, OnChanges, OnDestroy {
      /** `[time, value, category]` event tuples. */
      @Input() data: [string | number, number, string][] = []
      @Input() height: number | string = 320
      @Input() option?: Record<string, unknown>
      /** Accessible name announced for the chart image. Defaults to "Chart". */
      @Input() ariaLabel?: string
      @Input('class') className?: string
    
      @ViewChild('chartEl', { static: false }) chartEl?: ElementRef<HTMLDivElement>
    
      private chart: echarts.ECharts | null = null
      private unsubscribeTheme: (() => void) | null = null
    
      get hostClass(): string {
        // Bare `w-full` frame like React's ChartFrame with focusable={false}: role + label, no tab stop.
        return cn('block w-full', this.className)
      }
    
      get heightStyle(): string {
        return /^\d+$/.test(String(this.height)) ? `${this.height}px` : String(this.height)
      }
    
      /** Build the merged ECharts option (pure — no DOM needed, unit-testable). */
      getOption(): Record<string, unknown> {
        const colors = getChartColors()
        const series = [
          {
            type: 'themeRiver',
            data: this.data,
            label: { show: false },
            emphasis: { itemStyle: { shadowBlur: 12, shadowColor: 'rgba(0,0,0,0.2)' } },
          },
        ]
        const userOption: Record<string, any> = this.option ?? {}
        const {
          series: userSeries,
          tooltip: userTooltip,
          legend: userLegend,
          singleAxis: userAxis,
          ...userRest
        } = userOption
        const mergedSeries = Array.isArray(userSeries) ? series.map((s, i) => ({ ...s, ...(userSeries[i] ?? {}) })) : series
        return {
          color: colors,
          tooltip: mergeOptionBlock(
            {
              trigger: 'axis',
              axisPointer: { type: 'line', lineStyle: { color: getChartAxisColor(), opacity: 0.8 } },
              backgroundColor: getChartTooltipBg(),
              borderColor: getChartTooltipBorder(),
              textStyle: { color: getChartTooltipText(), fontSize: 12 },
            },
            userTooltip,
          ),
          legend:
            userLegend?.show === false
              ? undefined
              : mergeOptionBlock(
                  {
                    bottom: 0,
                    icon: 'circle',
                    itemWidth: 8,
                    itemHeight: 8,
                    data: [...new Set(this.data.map((d) => d[2]))],
                    textStyle: { fontSize: 11, color: getChartTextColor() },
                  },
                  userLegend,
                ),
          singleAxis: mergeOptionBlock(
            {
              top: 12,
              bottom: 40,
              type: 'time',
              axisTick: { show: false },
              axisLabel: { color: getChartTextColor(), fontSize: 11 },
              axisLine: { lineStyle: { color: getChartAxisColor() } },
            },
            userAxis,
          ),
          series: mergedSeries,
          ...userRest,
        }
      }
    
      async ngAfterViewInit(): Promise<void> {
        if (typeof window === 'undefined' || !this.chartEl?.nativeElement) return
        const [{ use }, { CanvasRenderer }, { ThemeRiverChart: EChartsThemeRiverChart }, comps] = await Promise.all([
          import('echarts/core'),
          import('echarts/renderers'),
          import('echarts/charts'),
          import('echarts/components'),
        ])
        use([
          CanvasRenderer,
          EChartsThemeRiverChart,
          comps.SingleAxisComponent,
          comps.TooltipComponent,
          comps.LegendComponent,
        ])
        const { init } = await import('echarts/core')
        this.chart = init(this.chartEl.nativeElement)
        this.chart.setOption(this.getOption())
        const { onChartThemeChange } = await import('../use-chart-theme')
        this.unsubscribeTheme = onChartThemeChange(() => this.chart?.setOption(this.getOption()))
        if (typeof ResizeObserver !== 'undefined') {
          new ResizeObserver(() => this.chart?.resize()).observe(this.chartEl.nativeElement)
        }
      }
    
      ngOnChanges(changes: SimpleChanges): void {
        if (this.chart && (changes['data'] || changes['option'])) {
          this.chart.setOption(this.getOption())
        }
      }
    
      ngOnDestroy(): void {
        this.unsubscribeTheme?.()
        this.unsubscribeTheme = null
        try {
          this.chart?.dispose()
        } catch {
          /* already disposed */
        }
        this.chart = null
      }
    }
    
  • src/app/components/ui/charts/theme-river/index.ts0.1 kB
  • src/app/components/ui/charts/use-chart-theme.ts7.4 kB

Raw manifest:https://uipkge.dev/r/angular/theme-river.json