Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion docs/src/content/components/Bars.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ layers: [svg, canvas]
related: [Bar]
---

> See also: [BarChart](/docs/components/BarChart) for simplified examples
:::tip
See also: [BarChart](/docs/components/BarChart) for simplified examples
:::

## Usage

Expand Down
26 changes: 19 additions & 7 deletions docs/src/examples/components/AnnotationPoint/line-to-point.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,39 @@
details: 'iPhone (1st Gen)'
},
{
x: new Date('July 7, 2008'),
x: new Date('July 11, 2008'),
y: 175.16,
label: 'B',
details: 'iPad (1st Gen)'
details: 'iPhone 3G'
},
{
x: new Date('January 27, 2010'),
y: 207.88,
x: new Date('April 3, 2010'),
y: 232.39,
label: 'C',
details: 'iPad (1st Gen)'
},
{
x: new Date('June 24, 2010'),
y: 254.28,
label: 'D',
details: 'iPhone 4'
},
{
x: new Date('September 1, 2010'),
y: 258.77,
label: 'E',
details: 'Apple TV (2nd Gen)'
},
{
x: new Date('March 11, 2011'),
y: 352.47,
label: 'D',
details: 'iPad (1st Gen)'
label: 'F',
details: 'iPad (2nd Gen)'
},
{
x: new Date('March 7, 2012'),
y: 545.18,
label: 'E',
label: 'G',
details: 'Apple TV (3rd Gen)'
}
];
Expand Down
10 changes: 8 additions & 2 deletions docs/src/examples/components/AnnotationRange/hide-tooltip.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<script lang="ts">
import { AnnotationRange, LineChart } from 'layerchart';
import { AnnotationRange, LineChart, defaultChartPadding } from 'layerchart';
import { getAppleStock } from '$lib/data.remote';

const data = await getAppleStock();

export { data };
</script>

<LineChart {data} x="date" y="value" height={300} padding={{ left: 25, bottom: 5 }}>
<LineChart
{data}
x="date"
y="value"
height={300}
padding={defaultChartPadding({ left: 25, bottom: 15 })}
>
{#snippet aboveMarks({ context })}
<AnnotationRange
x={[new Date('2010-01-01'), null]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<script lang="ts">
import { AnnotationRange, LineChart } from 'layerchart';
import { AnnotationRange, LineChart, defaultChartPadding } from 'layerchart';
import { getAppleStock } from '$lib/data.remote';

const data = await getAppleStock();

export { data };
</script>

<LineChart {data} x="date" y="value" height={300} padding={{ left: 25, bottom: 5 }}>
<LineChart
{data}
x="date"
y="value"
height={300}
padding={defaultChartPadding({ left: 25, bottom: 15 })}
>
{#snippet belowMarks({ context })}
<AnnotationRange y={[0, 400]} class="fill-success/10" />
<AnnotationRange y={[400, 600]} class="fill-warning/10" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<script lang="ts">
import { AnnotationRange, LineChart } from 'layerchart';
import { AnnotationRange, LineChart, defaultChartPadding } from 'layerchart';
import { getAppleStock } from '$lib/data.remote';

const data = await getAppleStock();

export { data };
</script>

<LineChart {data} x="date" y="value" height={300} padding={{ left: 25, bottom: 5 }}>
<LineChart
{data}
x="date"
y="value"
height={300}
padding={defaultChartPadding({ left: 25, bottom: 15 })}
>
{#snippet belowMarks({ context })}
<AnnotationRange
y={[500, null]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<script lang="ts">
import { AnnotationRange, LineChart } from 'layerchart';
import { AnnotationRange, LineChart, defaultChartPadding } from 'layerchart';
import { getAppleStock } from '$lib/data.remote';

const data = await getAppleStock();

export { data };
</script>

<LineChart {data} x="date" y="value" height={300} padding={{ left: 25, bottom: 5 }}>
<LineChart
{data}
x="date"
y="value"
height={300}
padding={defaultChartPadding({ left: 25, bottom: 15 })}
>
{#snippet belowMarks({ context })}
<AnnotationRange
y={[300, 500]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<script lang="ts">
import { AnnotationRange, LineChart } from 'layerchart';
import { AnnotationRange, LineChart, defaultChartPadding } from 'layerchart';
import { getAppleStock } from '$lib/data.remote';

const data = await getAppleStock();

export { data };
</script>

<LineChart {data} x="date" y="value" height={300} padding={{ left: 25, bottom: 5 }}>
<LineChart
{data}
x="date"
y="value"
height={300}
padding={defaultChartPadding({ left: 25, bottom: 15 })}
>
{#snippet belowMarks({ context })}
<AnnotationRange
y={[null, 500]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { AnnotationRange, LineChart, type Placement } from 'layerchart';
import { AnnotationRange, LineChart, defaultChartPadding, type Placement } from 'layerchart';
import AnnotationRangeControls from '$lib/components/controls/AnnotationRangePointLineControls.svelte';

import { getAppleStock } from '$lib/data.remote';
Expand All @@ -26,7 +26,13 @@

<AnnotationRangeControls bind:placement bind:xOffset bind:yOffset />

<LineChart {data} x="date" y="value" height={300} padding={{ left: 25, bottom: 5 }}>
<LineChart
{data}
x="date"
y="value"
height={300}
padding={defaultChartPadding({ left: 25, bottom: 15 })}
>
{#snippet aboveMarks({ context })}
<AnnotationRange
x={[new Date('2010-01-01'), new Date('2010-12-31')]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<script lang="ts">
import { AnnotationRange, LineChart } from 'layerchart';
import { AnnotationRange, LineChart, defaultChartPadding } from 'layerchart';
import { getAppleStock } from '$lib/data.remote';

const data = await getAppleStock();

export { data };
</script>

<LineChart {data} x="date" y="value" height={300} padding={{ left: 25, bottom: 5 }}>
<LineChart
{data}
x="date"
y="value"
height={300}
padding={defaultChartPadding({ left: 25, bottom: 15 })}
>
{#snippet belowMarks({ context })}
<AnnotationRange
x={[new Date('2011-01-01'), new Date('2011-06-30')]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<script lang="ts">
import { AnnotationRange, LineChart } from 'layerchart';
import { AnnotationRange, LineChart, defaultChartPadding } from 'layerchart';
import { getAppleStock } from '$lib/data.remote';

const data = await getAppleStock();

export { data };
</script>

<LineChart {data} x="date" y="value" height={300} padding={{ left: 25, bottom: 5 }}>
<LineChart
{data}
x="date"
y="value"
height={300}
padding={defaultChartPadding({ left: 25, bottom: 15 })}
>
{#snippet belowMarks({ context })}
<AnnotationRange
x={[new Date('2010-01-01'), null]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<script lang="ts">
import { AnnotationRange, LineChart } from 'layerchart';
import { AnnotationRange, LineChart, defaultChartPadding } from 'layerchart';
import { getAppleStock } from '$lib/data.remote';

const data = await getAppleStock();

export { data };
</script>

<LineChart {data} x="date" y="value" height={300} padding={{ left: 25, bottom: 5 }}>
<LineChart
{data}
x="date"
y="value"
height={300}
padding={defaultChartPadding({ left: 25, bottom: 15 })}
>
{#snippet belowMarks({ context })}
<AnnotationRange
x={[new Date('2010-01-01'), new Date('2010-12-31')]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<script lang="ts">
import { AnnotationRange, LineChart } from 'layerchart';
import { AnnotationRange, LineChart, defaultChartPadding } from 'layerchart';
import { getAppleStock } from '$lib/data.remote';

const data = await getAppleStock();

export { data };
</script>

<LineChart {data} x="date" y="value" height={300} padding={{ left: 25, bottom: 5 }}>
<LineChart
{data}
x="date"
y="value"
height={300}
padding={defaultChartPadding({ left: 25, bottom: 15 })}
>
{#snippet belowMarks({ context })}
<AnnotationRange
x={[null, new Date('2010-12-31')]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
y={['apples', 'bananas', 'oranges']}
yDomain={[0, null]}
yNice
padding={{ top: 20, left: 20, bottom: 20, right: 48 }}
padding={{ top: 20, left: 20, bottom: 20, right: 15 }}
tooltip={{ mode: 'quadtree-x' }}
height={300}
>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/components/Area/multiple-series.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
cDomain={Object.keys(fruitColors)}
cRange={Object.values(fruitColors)}
tooltip={{ mode: 'quadtree' }}
padding={{ ...defaultChartPadding, top: 10, bottom: 10, left: 20, right: 60 }}
padding={defaultChartPadding({ top: 10, bottom: 15, left: 20, right: 60 })}
height={300}
>
{#snippet children({ context })}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/components/Area/stack.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
cDomain={Object.keys(fruitColors)}
cRange={Object.values(fruitColors)}
tooltip={{ mode: 'quadtree-x' }}
padding={{ ...defaultChartPadding, left: 25, bottom: 20 }}
padding={defaultChartPadding({ left: 25, bottom: 20, right: 15 })}
height={300}
>
{#snippet children({ context })}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/components/AreaChart/custom.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
export { data };
</script>

<AreaChart {data} x="date" y="value" padding={defaultChartPadding({ right: 10 })} height={300}>
<AreaChart {data} x="date" y="value" padding={defaultChartPadding({ right: 15 })} height={300}>
{#snippet children({ context })}
<Layer>
<Axis placement="left" grid rule />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
}
]}
props={{ tooltip: { context: { mode: 'quadtree' } } }}
padding={defaultChartPadding({ right: 10 })}
padding={defaultChartPadding({ right: 15 })}
height={300}
>
{#snippet marks({ series, context })}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
]}
legend
seriesLayout="stack"
padding={defaultChartPadding({ bottom: 45, right: 10 })}
padding={defaultChartPadding({ legend: true, right: 10 })}
height={300}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
]}
seriesLayout="stack"
legend
padding={defaultChartPadding({ bottom: 45, right: 10 })}
padding={defaultChartPadding({ legend: true, right: 10 })}
height={300}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import {
Area,
AreaChart,
defaultChartPadding,
Highlight,
LinearGradient,
Tooltip
Tooltip,
defaultChartPadding
} from 'layerchart';
import { createDateSeries } from '$lib/utils/data.js';
import { format } from '@layerstack/utils';
Expand All @@ -19,7 +19,7 @@
};
</script>

<AreaChart {data} x="date" y="value" padding={defaultChartPadding({ right: 10 })} height={300}>
<AreaChart {data} x="date" y="value" padding={defaultChartPadding({ right: 15 })} height={300}>
{#snippet marks({ context })}
{@const thresholdValue = 0}
{@const thresholdOffset =
Expand Down
8 changes: 6 additions & 2 deletions docs/src/examples/components/Axis/rotate-labels.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<script lang="ts">
import { Axis, Chart, Layer } from 'layerchart';
import { Axis, Chart, Layer, defaultChartPadding } from 'layerchart';
import { timeDay } from 'd3-time';
import { startOfInterval } from '@layerstack/utils';

const today = startOfInterval('day', new Date());
</script>

<Chart xDomain={[timeDay.offset(today, -10), today]} padding={24} height={48}>
<Chart
xDomain={[timeDay.offset(today, -10), today]}
padding={defaultChartPadding({ bottom: 60, top: 24, left: 24, right: 24 })}
height={52}
>
<Layer>
<Axis
placement="bottom"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { Axis, Chart, Layer } from 'layerchart';
import { Axis, Chart, Layer, defaultChartPadding } from 'layerchart';
import {
timeDay,
timeHour,
Expand Down Expand Up @@ -112,7 +112,10 @@
<div>
<div class="text-sm mb-1">{example.label}</div>
<div class="h-[100px] p-4 border rounded-sm">
<Chart xDomain={example.domain} padding={{ top: 20, bottom: 20, left: 20, right: 20 }}>
<Chart
xDomain={example.domain}
padding={defaultChartPadding({ top: 20, bottom: 20, left: 20, right: 25 })}
>
<Layer>
<Axis placement="bottom" rule grid {tickSpacing} format={example.format} />
</Layer>
Expand Down
Loading
Loading