Skip to content
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

Add gradient fill to line charts #190

Merged
merged 1 commit into from
Aug 20, 2024
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
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@visx/axis": "^3.10.1",
"@visx/curve": "^3.3.0",
"@visx/event": "^3.3.0",
"@visx/gradient": "^3.3.0",
"@visx/grid": "^3.5.0",
"@visx/group": "^3.3.0",
"@visx/hierarchy": "^3.3.0",
Expand Down
34 changes: 25 additions & 9 deletions src/avs/charts/OperatorsTabLineChart.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AreaClosed, Circle, LinePath } from '@visx/shape';
import { AxisBottom, AxisRight } from '@visx/axis';
import { Circle, LinePath } from '@visx/shape';
import { getGrowthPercentage, reduceState } from '../../shared/helpers';
import { scaleLinear, scaleUtc } from '@visx/scale';
import { Tab, Tabs } from '@nextui-org/react';
Expand All @@ -10,6 +10,7 @@ import { curveMonotoneX } from '@visx/curve';
import { formatNumber } from '../../shared/formatters';
import { GridRows } from '@visx/grid';
import { Group } from '@visx/group';
import { LinearGradient } from '@visx/gradient';
import { localPoint } from '@visx/event';
import { tabs } from '../../shared/slots';
import { useMutativeReducer } from 'use-mutative';
Expand Down Expand Up @@ -163,6 +164,13 @@ export default function OperatorsTabLineChart({ points, height, width }) {
ref={containerRef}
width={width}
>
<LinearGradient
from="hsl(var(--app-chart-9))"
fromOpacity={0.5}
id="area-gradient"
to="hsl(var(--app-chart-9))"
toOpacity={0}
/>
<Group left={margin.left} top={margin.top}>
<GridRows
className="opacity-25 [&_line]:stroke-foreground-2"
Expand All @@ -171,6 +179,22 @@ export default function OperatorsTabLineChart({ points, height, width }) {
scale={scaleValue}
width={state.maxX - margin.right}
/>
<AreaClosed
curve={curveMonotoneX}
data={state.filteredPoints}
fill="url(#area-gradient)"
x={d => scaleDate(getDate(d)) ?? 0}
y={d => scaleValue(getValue(d)) ?? 0}
yScale={scaleValue}
/>
<LinePath
className="stroke-chart-9 stroke-2"
curve={curveMonotoneX}
data={state.filteredPoints}
strokeLinecap="butt"
x={d => scaleDate(getDate(d)) ?? 0}
y={d => scaleValue(getValue(d)) ?? 0}
/>
<AxisRight
axisLineClassName="stroke-foreground-2"
left={state.maxX - margin.right}
Expand Down Expand Up @@ -199,14 +223,6 @@ export default function OperatorsTabLineChart({ points, height, width }) {
}}
top={state.maxY}
/>
<LinePath
className="stroke-chart-9 stroke-2"
curve={curveMonotoneX}
data={state.filteredPoints}
x={d => scaleDate(getDate(d)) ?? 0}
y={d => scaleValue(getValue(d)) ?? 0}
/>

{tooltipOpen && (
<Circle
className="cursor-pointer fill-chart-9 stroke-2 dark:stroke-white"
Expand Down
34 changes: 25 additions & 9 deletions src/avs/charts/TVLTabLineChart.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AreaClosed, Circle, LinePath } from '@visx/shape';
import { AxisBottom, AxisRight } from '@visx/axis';
import { Circle, LinePath } from '@visx/shape';
import { formatETH, formatNumber, formatUSD } from '../../shared/formatters';
import { getGrowthPercentage, reduceState } from '../../shared/helpers';
import { scaleLinear, scaleUtc } from '@visx/scale';
Expand All @@ -10,6 +10,7 @@ import { bisector } from '@visx/vendor/d3-array';
import { curveMonotoneX } from '@visx/curve';
import { GridRows } from '@visx/grid';
import { Group } from '@visx/group';
import { LinearGradient } from '@visx/gradient';
import { localPoint } from '@visx/event';
import { tabs } from '../../shared/slots';
import { useMutativeReducer } from 'use-mutative';
Expand Down Expand Up @@ -186,6 +187,13 @@ export default function TVLTabLineChart({ points, height, width }) {
ref={containerRef}
width={width}
>
<LinearGradient
from="hsl(var(--app-chart-9))"
fromOpacity={0.5}
id="area-gradient"
to="hsl(var(--app-chart-9))"
toOpacity={0}
/>
<Group left={margin.left} top={margin.top}>
<GridRows
className="opacity-25 [&_line]:stroke-foreground-2"
Expand All @@ -194,6 +202,22 @@ export default function TVLTabLineChart({ points, height, width }) {
scale={scaleValue}
width={state.maxX - margin.right}
/>
<AreaClosed
curve={curveMonotoneX}
data={state.filteredPoints}
fill="url(#area-gradient)"
x={d => scaleDate(getDate(d)) ?? 0}
y={d => scaleValue(getValue(d)) ?? 0}
yScale={scaleValue}
/>
<LinePath
className="stroke-chart-9 stroke-2"
curve={curveMonotoneX}
data={state.filteredPoints}
strokeLinecap="butt"
x={d => scaleDate(getDate(d)) ?? 0}
y={d => scaleValue(getValue(d)) ?? 0}
/>
<AxisRight
axisLineClassName="stroke-foreground-2"
left={state.maxX - margin.right}
Expand Down Expand Up @@ -222,14 +246,6 @@ export default function TVLTabLineChart({ points, height, width }) {
}}
top={state.maxY}
/>
<LinePath
className="stroke-chart-9 stroke-2"
curve={curveMonotoneX}
data={state.filteredPoints}
x={d => scaleDate(getDate(d)) ?? 0}
y={d => scaleValue(getValue(d)) ?? 0}
/>

{tooltipOpen && (
<Circle
className="cursor-pointer fill-chart-9 stroke-2 dark:stroke-white"
Expand Down
33 changes: 25 additions & 8 deletions src/operators/charts/OperatorRestakersLineChart.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AreaClosed, Circle, LinePath } from '@visx/shape';
import { AxisBottom, AxisRight } from '@visx/axis';
import { Circle, LinePath } from '@visx/shape';
import {
getGrowthPercentage,
handleServiceError,
Expand All @@ -15,6 +15,7 @@ import ErrorMessage from '../../shared/ErrorMessage';
import { formatNumber } from '../../shared/formatters';
import { GridRows } from '@visx/grid';
import { Group } from '@visx/group';
import { LinearGradient } from '@visx/gradient';
import { localPoint } from '@visx/event';
import { ParentSize } from '@visx/responsive';
import { tabs } from '../../shared/slots';
Expand Down Expand Up @@ -243,6 +244,13 @@ function LineChart({ points, height, width }) {
ref={containerRef}
width={width}
>
<LinearGradient
from="hsl(var(--app-chart-9))"
fromOpacity={0.5}
id="area-gradient"
to="hsl(var(--app-chart-9))"
toOpacity={0}
/>
<Group left={margin.left} top={margin.top}>
<GridRows
className="opacity-25 [&_line]:stroke-foreground-2"
Expand All @@ -251,6 +259,22 @@ function LineChart({ points, height, width }) {
scale={scaleValue}
width={state.maxX - margin.right}
/>
<AreaClosed
curve={curveMonotoneX}
data={state.filteredPoints}
fill="url(#area-gradient)"
x={d => scaleDate(getDate(d)) ?? 0}
y={d => scaleValue(getValue(d)) ?? 0}
yScale={scaleValue}
/>
<LinePath
className="stroke-chart-9 stroke-2"
curve={curveMonotoneX}
data={state.filteredPoints}
strokeLinecap="butt"
x={d => scaleDate(getDate(d)) ?? 0}
y={d => scaleValue(getValue(d)) ?? 0}
/>
<AxisRight
axisLineClassName="stroke-foreground-2"
left={state.maxX - margin.right}
Expand Down Expand Up @@ -279,13 +303,6 @@ function LineChart({ points, height, width }) {
}}
top={state.maxY}
/>
<LinePath
className="stroke-chart-9 stroke-2"
curve={curveMonotoneX}
data={state.filteredPoints}
x={d => scaleDate(getDate(d)) ?? 0}
y={d => scaleValue(getValue(d)) ?? 0}
/>
{tooltipOpen && (
<Circle
className="cursor-pointer fill-chart-9 stroke-2 dark:stroke-foreground"
Expand Down
34 changes: 25 additions & 9 deletions src/operators/charts/OperatorTVLLineChart.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AreaClosed, Circle, LinePath } from '@visx/shape';
import { AxisBottom, AxisRight } from '@visx/axis';
import { Circle, LinePath } from '@visx/shape';
import { formatETH, formatNumber, formatUSD } from '../../shared/formatters';
import {
getGrowthPercentage,
Expand All @@ -15,6 +15,7 @@ import { curveMonotoneX } from '@visx/curve';
import ErrorMessage from '../../shared/ErrorMessage';
import { GridRows } from '@visx/grid';
import { Group } from '@visx/group';
import { LinearGradient } from '@visx/gradient';
import { localPoint } from '@visx/event';
import { ParentSize } from '@visx/responsive';
import { tabs } from '../../shared/slots';
Expand Down Expand Up @@ -268,6 +269,13 @@ function LineChart({ points, height, width }) {
ref={containerRef}
width={width}
>
<LinearGradient
from="hsl(var(--app-chart-9))"
fromOpacity={0.5}
id="area-gradient"
to="hsl(var(--app-chart-9))"
toOpacity={0}
/>
<Group left={margin.left} top={margin.top}>
<GridRows
className="opacity-25 [&_line]:stroke-foreground-2"
Expand All @@ -276,6 +284,22 @@ function LineChart({ points, height, width }) {
scale={scaleValue}
width={state.maxX - margin.right}
/>
<AreaClosed
curve={curveMonotoneX}
data={state.filteredPoints}
fill="url(#area-gradient)"
x={d => scaleDate(getDate(d)) ?? 0}
y={d => scaleValue(getValue(d)) ?? 0}
yScale={scaleValue}
/>
<LinePath
className="stroke-chart-9 stroke-2"
curve={curveMonotoneX}
data={state.filteredPoints}
strokeLinecap="butt"
x={d => scaleDate(getDate(d)) ?? 0}
y={d => scaleValue(getValue(d)) ?? 0}
/>
<AxisRight
axisLineClassName="stroke-foreground-2"
left={state.maxX - margin.right}
Expand Down Expand Up @@ -304,14 +328,6 @@ function LineChart({ points, height, width }) {
}}
top={state.maxY}
/>
<LinePath
className="stroke-chart-9 stroke-2"
curve={curveMonotoneX}
data={state.filteredPoints}
x={d => scaleDate(getDate(d)) ?? 0}
y={d => scaleValue(getValue(d)) ?? 0}
/>

{tooltipOpen && (
<Circle
className="cursor-pointer fill-chart-9 stroke-2 dark:stroke-foreground"
Expand Down