|
| 1 | +<script lang="ts"> |
| 2 | + import Chart from '../components/Chart.svelte'; |
| 3 | + import Layer from '../components/layers/Layer.svelte'; |
| 4 | + import Rect from '../components/Rect.svelte'; |
| 5 | + import Circle from '../components/Circle.svelte'; |
| 6 | + import Ellipse from '../components/Ellipse.svelte'; |
| 7 | + import Line from '../components/Line.svelte'; |
| 8 | + import Group from '../components/Group.svelte'; |
| 9 | + import Text from '../components/Text.svelte'; |
| 10 | + import Path from '../components/Path.svelte'; |
| 11 | +
|
| 12 | + type Primitive = 'rect' | 'circle' | 'ellipse' | 'line' | 'group' | 'text' | 'path'; |
| 13 | + type Mode = 'layerchart' | 'native'; |
| 14 | +
|
| 15 | + type Props = { |
| 16 | + primitive: Primitive; |
| 17 | + mode: Mode; |
| 18 | + count?: number; |
| 19 | + }; |
| 20 | +
|
| 21 | + let { primitive, mode, count = 100 }: Props = $props(); |
| 22 | +</script> |
| 23 | + |
| 24 | +{#if mode === 'layerchart'} |
| 25 | + <Chart width={500} height={300}> |
| 26 | + <Layer type="svg"> |
| 27 | + {#each Array(count) as _, i (i)} |
| 28 | + {#if primitive === 'rect'} |
| 29 | + <Rect x={10} y={10} width={50} height={30} fill="steelblue" /> |
| 30 | + {:else if primitive === 'circle'} |
| 31 | + <Circle cx={30} cy={30} r={15} fill="steelblue" /> |
| 32 | + {:else if primitive === 'ellipse'} |
| 33 | + <Ellipse cx={30} cy={30} rx={20} ry={10} fill="steelblue" /> |
| 34 | + {:else if primitive === 'line'} |
| 35 | + <Line x1={0} y1={0} x2={50} y2={50} stroke="steelblue" strokeWidth={2} /> |
| 36 | + {:else if primitive === 'group'} |
| 37 | + <Group x={10} y={10} /> |
| 38 | + {:else if primitive === 'text'} |
| 39 | + <Text x={10} y={20} value="Hello" fill="steelblue" /> |
| 40 | + {:else if primitive === 'path'} |
| 41 | + <Path pathData="M0,0 L50,50 L100,0 Z" fill="none" stroke="steelblue" strokeWidth={2} /> |
| 42 | + {/if} |
| 43 | + {/each} |
| 44 | + </Layer> |
| 45 | + </Chart> |
| 46 | +{:else} |
| 47 | + <svg width={500} height={300}> |
| 48 | + {#each Array(count) as _, i (i)} |
| 49 | + {#if primitive === 'rect'} |
| 50 | + <rect x={10} y={10} width={50} height={30} fill="steelblue" /> |
| 51 | + {:else if primitive === 'circle'} |
| 52 | + <circle cx={30} cy={30} r={15} fill="steelblue" /> |
| 53 | + {:else if primitive === 'ellipse'} |
| 54 | + <ellipse cx={30} cy={30} rx={20} ry={10} fill="steelblue" /> |
| 55 | + {:else if primitive === 'line'} |
| 56 | + <line x1={0} y1={0} x2={50} y2={50} stroke="steelblue" stroke-width={2} /> |
| 57 | + {:else if primitive === 'group'} |
| 58 | + <g transform="translate(10,10)"></g> |
| 59 | + {:else if primitive === 'text'} |
| 60 | + <text x={10} y={20} fill="steelblue">Hello</text> |
| 61 | + {:else if primitive === 'path'} |
| 62 | + <path d="M0,0 L50,50 L100,0 Z" fill="none" stroke="steelblue" stroke-width={2} /> |
| 63 | + {/if} |
| 64 | + {/each} |
| 65 | + </svg> |
| 66 | +{/if} |
0 commit comments