Source

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

San Francisco daily temperatures732 records · CSV · 15.1 kB
@charts-poc/demo-data/sf-temperatures

Selection: Complete published snapshot

date
Date
high
number
low
number

National Climatic Data Centerobservablehq/plot@356f579b1d94 · revision 356f579b1d94 · test/data/sf-temperatures.csv · Observable Plot repository MIT; upstream source credited · SHA-256 1e90d4f9b209Pinned snapshot

cases/03-temperature-range-band/tanstack.ts51 lines · entry
cases/03-temperature-range-band/tanstack.ts
import { areaY, defineChart, lineY } from '@tanstack/charts'
import { sfTemperatures } from '@charts-poc/demo-data/sf-temperatures'
import { scaleLinear, scaleUtc } from 'd3-scale'
import type { ConformanceInput, ConformanceMount } from '../../types'
import { tanstackMount } from '../../shared/mount'

const definition = (input: ConformanceInput) => {
  return defineChart({
    marks: [
      areaY(sfTemperatures, {
        x: 'date',
        y1: 'low',
        y2: 'high',
        fill: '#60a5fa',
        fillOpacity: 0.24,
      }),
      lineY(sfTemperatures, {
        x: 'date',
        y: 'low',
        stroke: '#2563eb',
        strokeWidth: 1.75,
      }),
      lineY(sfTemperatures, {
        x: 'date',
        y: 'high',
        stroke: '#dc2626',
        strokeWidth: 1.75,
      }),
    ],
    x: { scale: scaleUtc, axis: { label: 'Week' } },
    y: { scale: scaleLinear, grid: true, axis: { label: 'Temperature (°F)' } },
  })
}

export const mount: ConformanceMount = tanstackMount(
  definition,
  'San Francisco daily low-to-high temperature range',
  {
    format: ({ datum }) =>
      `${datum.date.toLocaleDateString('en-US', {
        month: 'short',
        day: 'numeric',
        year: 'numeric',
        timeZone: 'UTC',
      })} · ${datum.low.toLocaleString('en-US', {
        maximumFractionDigits: 1,
      })}${datum.high.toLocaleString('en-US', {
        maximumFractionDigits: 1,
      })} °F`,
  },
)