Skip to content

Commit f32a1c6

Browse files
authored
some chart stylings to match the old version (#351)
## Summary Couple of changes to get my feet wet with LayerChart and bring the chart styles closer to what they were using ECharts. ## Checklist - [ ] Added Unit Tests - [ ] Covered by existing CI - [ ] Integration tested - [ ] Documentation update <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced chart interactivity with improved tooltip behavior and legend styling for a smoother, more engaging visualization experience. - Added customizable options for axis configurations and highlighted points, allowing for a more refined display of data trends. - **Chores** - Updated a core charting dependency to its latest version, contributing to improved performance and stability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 84ee4fa commit f32a1c6

File tree

4 files changed

+47
-9
lines changed

4 files changed

+47
-9
lines changed

frontend/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"clsx": "^2.1.1",
6767
"d3": "^7.9.0",
6868
"dotenv": "^16.4.7",
69-
"layerchart": "^0.93.9",
69+
"layerchart": "^0.95.0",
7070
"lodash": "^4.17.21",
7171
"tailwind-merge": "^2.6.0",
7272
"tailwind-variants": "^0.3.1"

frontend/src/lib/components/charts/FeaturesLineChart.svelte

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,20 @@
5151
};
5252
})}
5353
padding={{ left: 24, bottom: 48 }}
54-
legend={{ placement: 'bottom-left', classes: { root: 'right-0 overflow-auto scrollbar-none' } }}
54+
legend={{
55+
placement: 'bottom-left',
56+
classes: {
57+
root: 'right-0 overflow-auto scrollbar-none',
58+
swatch: 'h-2 w-2 rounded-full',
59+
label: 'text-sm',
60+
item: () => 'flex items-center gap-2'
61+
}
62+
}}
5563
renderContext="canvas"
5664
{...lineChartProps}
5765
{...restProps}
5866
brush={{ onbrushend }}
67+
tooltip={{ hideDelay: 150 }}
5968
>
6069
<svelte:fragment slot="aboveMarks" let:xScale let:yScale>
6170
{#if markPoint}
@@ -72,7 +81,14 @@
7281
{/if}
7382
</svelte:fragment>
7483

75-
<svelte:fragment slot="tooltip" let:x let:y let:height let:visibleSeries>
84+
<svelte:fragment
85+
slot="tooltip"
86+
let:x
87+
let:y
88+
let:height
89+
let:visibleSeries
90+
let:setHighlightSeriesKey
91+
>
7692
<Tooltip.Root {...tooltipProps.root} x="data" y={height + 24} pointerEvents let:data>
7793
<Tooltip.Header {...tooltipProps.header}>
7894
{formatDate(x(data))}
@@ -87,6 +103,8 @@
87103
<button
88104
class="col-span-full grid grid-cols-[1fr,auto] gap-6 hover:bg-neutral-400 py-2 px-3 rounded"
89105
onclick={() => onitemclick?.({ series: s, data: seriesTooltipData, value })}
106+
onmouseenter={() => setHighlightSeriesKey(s.key)}
107+
onmouseleave={() => setHighlightSeriesKey(null)}
90108
>
91109
<Tooltip.Item
92110
label={s.label ?? (s.key !== 'default' ? s.key : 'value')}

frontend/src/lib/components/charts/common.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ export const colors = [
2323
'#CB5587'
2424
];
2525

26+
export const xAxisProps = {
27+
placement: 'bottom' as const,
28+
classes: {
29+
tickLabel: 'fill-neutral-700 text-xs'
30+
}
31+
};
32+
33+
export const yAxisProps = {
34+
placement: 'left' as const,
35+
classes: {
36+
tickLabel: 'fill-neutral-700 text-xs'
37+
}
38+
};
39+
2640
export const tooltipProps = {
2741
root: {
2842
variant: 'none',
@@ -44,7 +58,11 @@ export const tooltipProps = {
4458
} satisfies NonNullable<ComponentProps<typeof LineChart>['props']>['tooltip'];
4559

4660
export const highlightProps = {
47-
motion: false
61+
motion: false,
62+
points: {
63+
r: 8,
64+
strokeWidth: 4
65+
}
4866
} satisfies NonNullable<ComponentProps<typeof LineChart>['props']>['highlight'];
4967

5068
export const barChartProps = {
@@ -60,7 +78,9 @@ export const lineChartProps = {
6078
},
6179
props: {
6280
tooltip: tooltipProps,
63-
highlight: highlightProps
81+
highlight: highlightProps,
82+
xAxis: xAxisProps,
83+
yAxis: yAxisProps
6484
}
6585
} satisfies NonNullable<ComponentProps<typeof LineChart>>;
6686

0 commit comments

Comments
 (0)