Source
50 chart lines · 1 file · 1.3 kBBenchmark harness excluded · shared/mount.ts
San Francisco daily temperatures732 records · CSV · 15.1 kB
@charts-poc/demo-data/sf-temperaturesSelection: 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/19-moving-average-line/tanstack.ts50 lines · entry
cases/19-moving-average-line/tanstack.ts
import { defineChart, lineY, ruleY, window } from '@tanstack/charts'
import { scaleLinear, scaleUtc } from 'd3-scale'
import { sfTemperatures } from '@charts-poc/demo-data/sf-temperatures'
import { tanstackMount } from '../../shared/mount'
import type { ConformanceInput, ConformanceMount } from '../../types'
const windowSize = 14
const definition = (_input: ConformanceInput) => {
const rows = window(sfTemperatures, {
size: windowSize,
partial: false,
outputs: {
high: { value: 'high', reduce: 'mean' },
low: { value: 'low', reduce: 'mean' },
},
})
return defineChart({
marks: [
lineY(rows, {
x: 'date',
y: 'low',
stroke: '#4e79a7',
strokeWidth: 2.25,
}),
lineY(rows, {
x: 'date',
y: 'high',
stroke: '#e15759',
strokeWidth: 2.25,
}),
ruleY([32], {
stroke: '#64748b',
strokeDasharray: '4 4',
}),
],
x: { scale: scaleUtc, axis: { label: 'Date' } },
y: {
scale: scaleLinear,
grid: true,
axis: { label: 'Fourteen-day average temperature (°F)' },
},
})
}
export const mount: ConformanceMount = tanstackMount(
definition,
'Fourteen-day average high and low temperature in San Francisco',
)