Source

52 chart lines · 1 file · 1.4 kBBenchmark harness excluded · shared/mount.ts

U.S. metropolitan wage inequality195 records · CSV · 15.4 kB
@charts-poc/demo-data/citywages

Selection: Complete published snapshot

Metro
string
POP_1980
number
LPOP_1980
number
R90_10_1980
number
POP_2015
number
LPOP_2015
number
R90_10_2015
number
nyt_display
string
state_display
string | null
highlight
number | null

The New York Times@observablehq/sample-datasets@1.0.1 · revision 732c0148de74 · citywages.csv · ISC distribution; upstream source credited · SHA-256 9b50329064c1Pinned snapshot

cases/17-dumbbell/tanstack.ts52 lines · entry
cases/17-dumbbell/tanstack.ts
import { citywages } from '@charts-poc/demo-data/citywages'
import { defineChart, dot, link } from '@tanstack/charts'
import { scaleBand, scaleLinear } from 'd3-scale'
import { tanstackMount } from '../../shared/mount'
import type { ConformanceInput } from '../../types'

const definition = (input: ConformanceInput) => {
  const rows = citywages.slice(input.revision * 4, input.revision * 4 + 8)
  return defineChart({
    marks: [
      link(rows, {
        x1: 'R90_10_1980',
        y1: 'nyt_display',
        x2: 'R90_10_2015',
        y2: 'nyt_display',
        stroke: '#94a3b8',
        strokeWidth: 2,
      }),
      dot(rows, {
        x: 'R90_10_1980',
        y: 'nyt_display',
        fill: '#2563eb',
        r: 4,
      }),
      dot(rows, {
        x: 'R90_10_2015',
        y: 'nyt_display',
        fill: '#f97316',
        r: 4,
      }),
    ],
    x: {
      scale: scaleLinear,
      grid: true,
      axis: { label: '90th/10th percentile wage ratio' },
    },
    y: {
      scale: () => scaleBand<string>().padding(0.22),
    },
  })
}

export const mount = tanstackMount(
  definition,
  'Metropolitan wage inequality in 1980 and 2015',
  {
    format: ({ datum }) =>
      `${datum.nyt_display} · 1980 ${datum.R90_10_1980.toLocaleString(
        'en-US',
      )} · 2015 ${datum.R90_10_2015.toLocaleString('en-US')}`,
  },
)