|
1 | 1 | <script lang="ts"> |
2 | | - import { scaleLinear, scaleRadial, scaleUtc } from 'd3-scale'; |
| 2 | + import { scaleBand, scaleUtc } from 'd3-scale'; |
3 | 3 | import { flatGroup } from 'd3-array'; |
4 | 4 | import { curveLinearClosed, curveCatmullRomClosed, curveCatmullRom } from 'd3-shape'; |
5 | | - import { PeriodType, cls } from 'svelte-ux'; |
| 5 | + import { Field, PeriodType, ToggleGroup, ToggleOption, cls } from 'svelte-ux'; |
6 | 6 |
|
7 | 7 | import Chart, { Svg } from '$lib/components/Chart.svelte'; |
8 | 8 | import Area from '$lib/components/Area.svelte'; |
|
11 | 11 | import Spline from '$lib/components/Spline.svelte'; |
12 | 12 |
|
13 | 13 | import Preview from '$lib/docs/Preview.svelte'; |
| 14 | + import Points from '$lib/components/Points.svelte'; |
14 | 15 |
|
15 | 16 | export let data; |
16 | 17 |
|
17 | | - /** |
18 | | - * TODO: |
19 | | - * - [ ] Tooltip (manual with path, radial bisect?). Work with Highlight |
20 | | - */ |
| 18 | + const pitchData = [ |
| 19 | + { name: 'fastball', value: 10 }, |
| 20 | + { name: 'change', value: 0 }, |
| 21 | + { name: 'slider', value: 4 }, |
| 22 | + { name: 'cutter', value: 8 }, |
| 23 | + { name: 'curve', value: 5 }, |
| 24 | + ]; |
| 25 | + let curve = curveLinearClosed; |
21 | 26 | </script> |
22 | 27 |
|
23 | 28 | <h1>Examples</h1> |
24 | 29 |
|
| 30 | +<div class="grid grid-cols-[1fr,auto] gap-2 items-end"> |
| 31 | + <h2>Radar</h2> |
| 32 | + <Field label="curve: " labelPlacement="left" class="mb-1" dense> |
| 33 | + <ToggleGroup bind:value={curve} size="sm"> |
| 34 | + <ToggleOption value={curveLinearClosed}>Linear</ToggleOption> |
| 35 | + <ToggleOption value={curveCatmullRomClosed}>CatmullRom</ToggleOption> |
| 36 | + </ToggleGroup> |
| 37 | + </Field> |
| 38 | +</div> |
| 39 | + |
| 40 | +<Preview data={pitchData}> |
| 41 | + <div class="h-[300px] p-4 border rounded"> |
| 42 | + <Chart |
| 43 | + data={pitchData} |
| 44 | + x="name" |
| 45 | + xScale={scaleBand()} |
| 46 | + xDomain={pitchData.map((d) => d.name)} |
| 47 | + xRange={[0, 2 * Math.PI]} |
| 48 | + y="value" |
| 49 | + yRange={({ height }) => [0, height / 2]} |
| 50 | + yPadding={[0, 10]} |
| 51 | + padding={{ top: 32, bottom: 8 }} |
| 52 | + > |
| 53 | + <Svg> |
| 54 | + <Group center> |
| 55 | + <Axis |
| 56 | + placement="radius" |
| 57 | + grid={{ class: 'stroke-surface-content/20 fill-surface-200/50' }} |
| 58 | + ticks={[0, 5, 10]} |
| 59 | + format={(d) => ''} |
| 60 | + /> |
| 61 | + <Axis placement="angle" grid={{ class: 'stroke-surface-content/20' }} /> |
| 62 | + <Spline radial {curve} class="stroke-primary fill-primary/20" /> |
| 63 | + <Points radial class="fill-primary stroke-surface-200" /> |
| 64 | + </Group> |
| 65 | + </Svg> |
| 66 | + </Chart> |
| 67 | + </div> |
| 68 | +</Preview> |
| 69 | + |
25 | 70 | <h2>Line with Areas</h2> |
26 | 71 |
|
27 | 72 | <Preview data={data.sfoTemperatures}> |
|
32 | 77 | xScale={scaleUtc()} |
33 | 78 | xRange={[0, 2 * Math.PI]} |
34 | 79 | y={['minmin', 'maxmax']} |
35 | | - yScale={scaleRadial()} |
36 | 80 | yRange={({ height }) => [height / 5, height / 2]} |
37 | 81 | let:yScale |
38 | 82 | > |
|
0 commit comments