Skip to content

[Labels] Apply series property accessors #633

@silktrader

Description

@silktrader

Hello and thanks for providing such a crafty library.
I set up layerchart by way of shadcn-svelte and followed the instructions at: https://next.layerchart.com, but I am having an issue customising labels.

Version: "layerchart": "^2.0.0-next.27"

A simple dataset:

	const data = [
		{ macro: 'Proteins', current: 100, target: 200 },
		{ macro: 'Carbs', current: 230, target: 200 }
	];

I would like to display labels only for the "current" keys. And this was my failed attempt:

<BarChart
			{data}
			y="macro"
			axis={false}
			c="macro"
			cDomain={["Proteins", "Carbs"]}
			cRange={["var(--color-macro-proteins)", "var(--color-macro-carbs)"]}
			orientation="horizontal"
						series={[
							{
								key: 'target',
								props: { fillOpacity: 0.2 }
							},
							{
								key: 'current',
								props: { insets: { y: 8 } }
							}
						]}
			renderContext="svg"
		>
			{#snippet labels({ visibleSeries, getLabelsProps })}
				{@const currentSeries = visibleSeries.filter(s => s.key === 'current')}
				{#each currentSeries as s, i}
						<Labels {...getLabelsProps(s, i)} placement="inside" fill="white" class="text-base" />
				{/each}
			{/snippet}

		</BarChart>

The code above yields:

Image

The goal is to elide the 200 in the first bar. Is this my issue or one with the library?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions