Skip to content

Pass data type through mark components #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
146e305
docs: add cell example, figure out solution for passing thru types
gka Jun 6, 2025
bb808d1
improve typing of BarX
gka Jun 6, 2025
baf71cd
improve typing of BarY
gka Jun 6, 2025
1fbf3d8
ts: improve typing of Geo mark
gka Jun 8, 2025
d5b4e18
ts: improve dotx and doty
gka Jun 9, 2025
e6d013f
ts: improve frame
gka Jun 9, 2025
8498487
ts: improve line
gka Jun 9, 2025
89e47b2
ts: line marks
gka Jun 9, 2025
1a5789f
ts: bollinger marks
gka Jun 9, 2025
cabc2d8
ts: brush marks
gka Jun 9, 2025
8ff916c
ts: cell marks
gka Jun 9, 2025
2c0614b
ts: custom mark, screenshots
gka Jun 9, 2025
97b7462
fix
gka Jun 9, 2025
19658b4
fix brush mark
gka Jun 9, 2025
bfad61c
..
gka Jun 9, 2025
3f7bf76
ts: rect mark props
gka Jun 9, 2025
9077f34
fix axis marks
gka Jun 9, 2025
4f60da8
add rect examples
gka Jun 9, 2025
635db6d
increase title margin on axisY
gka Jun 9, 2025
6ee6ea7
ensure that interval ticks stay within domain
gka Jun 9, 2025
165b38b
..
gka Jun 9, 2025
8527c72
tests
gka Jun 10, 2025
8188532
ts: improve area prop type
gka Jun 10, 2025
b263fe6
..
gka Jun 10, 2025
8fcd536
add streamgraph example
gka Jun 10, 2025
5668cbc
docs
gka Jun 10, 2025
6135445
ts: improve arrow prop type
gka Jun 10, 2025
de86fae
remove unused css
gka Jun 11, 2025
114cbab
ts: improve link mark props
gka Jun 11, 2025
2e02df0
ts: improve pointer mark props
gka Jun 11, 2025
225ffff
docs: add link examples
gka Jun 11, 2025
76dc86b
chore: break types into separate files
gka Jun 11, 2025
7f90ed2
fix imports
gka Jun 11, 2025
cd7fc42
ts: improve rule mark props
gka Jun 11, 2025
a952693
fix aapl type
gka Jun 11, 2025
031fa05
docs: add rule examples
gka Jun 11, 2025
5a6edbb
ts: improve sphere mark props
gka Jun 11, 2025
edc97ea
ts: improve spike and vector mark props
gka Jun 11, 2025
17f45dd
ts: improve tick mark props
gka Jun 11, 2025
361043a
docs: add exmaples
gka Jun 11, 2025
df21c51
docs: add spike map example
gka Jun 11, 2025
c17157c
bump dependencies
gka Jun 11, 2025
bb39db8
add ssr
gka Jun 11, 2025
0a1fbb0
add screenshot
gka Jun 11, 2025
75edbb7
more examples
gka Jun 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ts: improve area prop type
resolves #97
  • Loading branch information
gka committed Jun 11, 2025
commit 8188532da458c933e8d71cfcb1961328222282a3
27 changes: 12 additions & 15 deletions src/lib/marks/Area.svelte
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<!-- @component
Creates an area chart with filled regions between two x-y value pairs
-->
<script module lang="ts">
export type AreaMarkProps = {
data: DataRecord[];
x1?: ChannelAccessor;
x2?: ChannelAccessor;
y1?: ChannelAccessor;
y2?: ChannelAccessor;
z?: ChannelAccessor;
<script lang="ts" generics="Datum extends DataRecord">
interface AreaMarkProps extends BaseMarkProps<Datum>, LinkableMarkProps<Datum> {
data: Datum[];
x1?: ChannelAccessor<Datum>;
x2?: ChannelAccessor<Datum>;
y1?: ChannelAccessor<Datum>;
y2?: ChannelAccessor<Datum>;
z?: ChannelAccessor<Datum>;
curve?: CurveName | CurveFactory;
tension?: number;
sort?: ConstantAccessor<RawValue> | { channel: 'stroke' | 'fill' };
stack?: Partial<StackOptions>;
canvas?: boolean;
} & BaseMarkProps &
LinkableMarkProps;
</script>
}

<script lang="ts">
import Mark from '../Mark.svelte';
import GroupMultiple from './helpers/GroupMultiple.svelte';
import { getContext } from 'svelte';
Expand Down Expand Up @@ -49,15 +46,15 @@

const DEFAULTS = {
fill: 'currentColor',
curve: 'linear',
curve: 'linear' as CurveName,
tension: 0,
...getContext<PlotDefaults>('svelteplot/_defaults').area
};

const {
data,
data = [{} as Datum],
/** the curve */
curve = 'linear',
curve = 'linear' as CurveName,
tension = 0,
class: className = '',
canvas = false,
Expand Down
27 changes: 15 additions & 12 deletions src/lib/marks/AreaX.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,30 @@
Creates a horizontal area chart with x value and baseline. Areas are implicitly
stacked horizontally if just the x channel is defined.
-->
<script lang="ts">
import Area, { type AreaMarkProps } from './Area.svelte';
<script lang="ts" generics="Datum extends DataRow">
interface AreaXMarkProps extends Omit<ComponentProps<typeof Area>, 'y1' | 'y2'> {
x?: ChannelAccessor<Datum>;
y?: ChannelAccessor<Datum>;
}
import Area from './Area.svelte';
import { renameChannels } from '$lib/transforms/rename.js';
import { stackX } from '$lib/transforms/stack.js';
import { recordizeX } from '$lib/transforms/recordize.js';
import type { ChannelAccessor, PlotDefaults } from '../types.js';
import { getContext } from 'svelte';
import type { ChannelAccessor, DataRow, PlotDefaults } from '../types.js';
import { getContext, type ComponentProps } from 'svelte';

type AreaXProps = Omit<AreaMarkProps, 'y1' | 'y2'> & {
x?: ChannelAccessor;
y?: ChannelAccessor;
};

let markProps: AreaMarkProps = $props();
let markProps: AreaXMarkProps = $props();

const DEFAULTS = getContext<PlotDefaults>('svelteplot/_defaults').areaX;

const { data, stack, ...options }: AreaMarkProps = $derived({ ...DEFAULTS, ...markProps });
const { data, stack, ...options }: AreaXMarkProps = $derived({
...(markProps.x == undefined ? { x1: 0, x2: 0 } : {}),
...DEFAULTS,
...markProps
});

const args = $derived(
renameChannels<AreaXProps>(
renameChannels<AreaXMarkProps>(
stackX(recordizeX({ data, ...options, y1: null, y2: null }), stack),
{ y: 'y1' }
)
Expand Down
30 changes: 15 additions & 15 deletions src/lib/marks/AreaY.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
Creates a vertical area chart with y value and baseline. Areas are implicitly
stacked vertically if just the y channel is defined.
-->
<script lang="ts">
import Area, { type AreaMarkProps } from './Area.svelte';
<script lang="ts" generics="Datum extends DataRow">
interface AreaYMarkProps extends Omit<ComponentProps<typeof Area>, 'x1' | 'x2'> {
x?: ChannelAccessor<Datum>;
y?: ChannelAccessor<Datum>;
}
import Area from './Area.svelte';
import { renameChannels } from '$lib/transforms/rename.js';
import { stackY } from '$lib/transforms/stack.js';
import { recordizeY } from '$lib/transforms/recordize.js';
import type { ChannelAccessor, PlotDefaults } from '../types.js';
import { getContext } from 'svelte';
import type { ChannelAccessor, DataRow, PlotDefaults } from '../types.js';
import { getContext, type Component, type ComponentProps } from 'svelte';

/**
* AreaY mark foo
*/
type AreaYProps = Omit<AreaMarkProps, 'x1' | 'x2'> & {
x?: ChannelAccessor;
y?: ChannelAccessor;
};

let markProps: AreaMarkProps = $props();
let markProps: AreaYMarkProps = $props();

const DEFAULTS = getContext<PlotDefaults>('svelteplot/_defaults').areaY;

const { data, stack, ...options }: AreaMarkProps = $derived({ ...DEFAULTS, ...markProps });
const { data, stack, ...options }: AreaYMarkProps = $derived({
...(markProps.y == undefined ? { y1: 0, y2: 0 } : {}),
...DEFAULTS,
...markProps
});

const args = $derived(
renameChannels<AreaYProps>(
renameChannels<AreaYMarkProps>(
stackY(recordizeY({ data, ...options, x1: null, x2: null }), stack),
{ x: 'x1' }
)
Expand Down
14 changes: 9 additions & 5 deletions src/routes/examples/[group]/[page]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@
<div class="svp-code-block">
<HighlightSvelte
lang="svelte"
code={pagesSrc[plotKey].substring(
pagesSrc[plotKey].indexOf(
code={pagesSrc[plotKey]
.substring(
pages[plotKey].fullCode
? '<script lang="ts">'
: '<Plot'
? pagesSrc[plotKey].indexOf(
'<script lang="ts">'
)
: pagesSrc[plotKey].lastIndexOf(
'</scr' + 'ipt>'
) + 9
)
)} />
.trim()} />
</div>
</div>

Expand Down
5 changes: 5 additions & 0 deletions src/routes/examples/area/_index.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script module>
export let title = 'Area';
</script>

<h1>Area examples</h1>
23 changes: 23 additions & 0 deletions src/routes/examples/area/area-x.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script module>
export const title = 'AreaX';
</script>

<script lang="ts">
import { Plot, AreaX } from 'svelteplot';
import { page } from '$app/state';
import type { ExamplesData } from '../types';
import { setContext } from 'svelte';
let { aapl } = $derived(page.data.data) as ExamplesData;
</script>

<div>
<Plot><AreaX data={aapl} y="Date" x="Close" /></Plot>
<Plot><AreaX data={aapl} y="Date" x1="Close" /></Plot>
<Plot><AreaX data={aapl} y="Date" x2="Close" /></Plot>
</div>

<style>
div {
columns: 3;
}
</style>
19 changes: 19 additions & 0 deletions src/routes/examples/area/area-y.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script module>
export const title = 'AreaY';
</script>

<script lang="ts">
import { Plot, AreaY } from 'svelteplot';
import { page } from '$app/state';
import type { ExamplesData } from '../types';
import { setContext } from 'svelte';
let { aapl } = $derived(page.data.data) as ExamplesData;

setContext('svelteplot/defaults', {
height: 200
});
</script>

<Plot><AreaY data={aapl} x="Date" y="Close" /></Plot>
<Plot><AreaY data={aapl} x="Date" y1="Close" /></Plot>
<Plot><AreaY data={aapl} x="Date" y2="Close" /></Plot>
14 changes: 14 additions & 0 deletions src/routes/examples/area/area.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script module>
export const title = 'Simple area';
</script>

<script lang="ts">
import { Plot, Area } from 'svelteplot';
import { page } from '$app/state';
import type { ExamplesData } from '../types';
let { aapl } = $derived(page.data.data) as ExamplesData;
</script>

<Plot y={{ grid: true }}>
<Area data={aapl} x1="Date" y1={0} y2="Close" />
</Plot>
Binary file added static/examples/area/area-x.dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/examples/area/area-x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/examples/area/area-y.dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/examples/area/area-y.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/examples/area/area.dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/examples/area/area.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy