Source

52 chart lines · 2 files · 1.6 kBBenchmark harness excluded · shared/mount.ts

English letter frequencies26 records · CSV · 275 B
@charts-poc/demo-data/alphabet

Selection: Complete published snapshot

letter
string
frequency
number

Cryptographical Mathematics by Robert Edward Lewand@observablehq/sample-datasets@1.0.1 · revision 732c0148de74 · alphabet.csv · ISC distribution; upstream source credited · SHA-256 d62ce74dad83Pinned snapshot

cases/95-rounded-donut/tanstack.ts41 lines · entry
cases/95-rounded-donut/tanstack.ts
import { defineChart } from '@tanstack/charts'
import { polar, radialArc } from '@tanstack/charts/polar'
import { alphabet } from '@charts-poc/demo-data/alphabet'
import { pie } from 'd3-shape'
import { selectRoundedDonutData } from './selection'
import { tanstackMount } from '../../shared/mount'
import type { AlphabetRow } from '@charts-poc/demo-data/alphabet'
import type { ConformanceInput } from '../../types'

const paddingAngle = (Math.PI / 180) * 3
const pieLayout = pie<AlphabetRow>()
  .sort(null)
  .value(({ frequency }) => frequency)
  .padAngle(paddingAngle)
const colors = ['#0284c7', '#4f46e5', '#9333ea', '#db2777', '#ea580c']

const definition = (input: ConformanceInput) => {
  const arcs = pieLayout([...selectRoundedDonutData(alphabet, input.revision)])

  return defineChart({
    marks: [
      polar({
        radiusRatio: 0.8,
        marks: [
          radialArc(arcs, {
            startAngle: 'startAngle',
            endAngle: (slice) => slice.endAngle - slice.padAngle,
            padAngle: () => 0,
            innerRadius: ({ radius }) => radius * 0.58,
            cornerRadius: 8,
            color: ({ data }) => data.letter,
          }),
        ],
      }),
    ],
    color: { range: colors },
    margin: 0,
  })
}

export const mount = tanstackMount(definition, 'Rounded letter frequency donut')
cases/95-rounded-donut/selection.ts11 lines · support
cases/95-rounded-donut/selection.ts
import type { AlphabetRow } from '@charts-poc/demo-data/alphabet'

const sliceSize = 5

export function selectRoundedDonutData(
  rows: readonly AlphabetRow[],
  revision = 0,
) {
  const start = Math.abs(revision % 2) * sliceSize
  return rows.slice(start, start + sliceSize)
}