Skip to content

Commit

Permalink
chore: Reduce PR complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
EvHaus committed Dec 23, 2024
1 parent 0d959f4 commit 8c583bd
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 7,445 deletions.
Binary file modified examples/recharts-basic.pdf
Binary file not shown.
Binary file modified examples/recharts-composed.pdf
Binary file not shown.
Binary file modified examples/recharts-gradient.pdf
Binary file not shown.
163 changes: 37 additions & 126 deletions examples/recharts-gradient.tsx
Original file line number Diff line number Diff line change
@@ -1,137 +1,48 @@
import { fileURLToPath } from 'node:url';
import ReactPDF, { Page, Document } from '@react-pdf/renderer';
import { CartesianGrid, Label, Line, LineChart, XAxis, YAxis } from 'recharts';
import { CartesianGrid, Line, LineChart, XAxis, YAxis } from 'recharts';
import ReactPDFChart from '../src/index.jsx';

const data = [
{ x: 2024, '1': 10, '2': 11 },
{ x: 2026, '1': 12, '2': 13 },
{ x: 2030, '1': 14, '2': 15 },
{ x: 2024, y: 10 },
{ x: 2026, y: 12 },
{ x: 2030, y: 14 },
];

const colors = {
grid: '#E9E8EB',
lineColors: [
{
lineStroke: 'red',
pointStroke: '#FDB5AC',
pointFill: 'url(#point0Fill)',
pointFillC1: '#EFB9C7',
pointFillC2: '#F2DEE3',
},
{
lineStroke: '#7AA1FA',
pointStroke: '#B8CEFF',
pointFill: 'url(#point1Fill)',
pointFillC1: '#AEAAD5',
pointFillC2: '#D4D1F3',
},
{
lineStroke: '#8BC5CB',
pointStroke: '#ABD6C0',
pointFill: 'url(#point2Fill)',
pointFillC1: '#CBDFC8',
pointFillC2: '#F7F7F7',
},
],
};

const CustomizedDot = ({
cx,
cy,
fill,
stroke,
strokeWidth = 1,
radius = 6,
}: {
cx: number;
cy: number;
fill: string;
stroke: string;
strokeWidth?: number;
radius?: number;
}) => {
return (
<circle
cx={cx}
cy={cy}
fill={fill}
r={radius}
stroke={stroke}
strokeWidth={strokeWidth}
/>
);
};

const Linechart = () => {
return (
<Document>
<Page size='A4' style={{ padding: 20 }}>
<ReactPDFChart>
<LineChart data={data} height={200} width={523}>
<defs>
{['1', '2'].map((id, idx) => (
<linearGradient
id={`grad${id}`}
key={id}
x1={0.5}
x2={0.5}
y1={0}
y2={1}
// gradientTransform="rotate(90deg)"
>
<stop
offset='0'
stopColor={colors.lineColors[idx].pointFillC1}
stopOpacity={1}
/>
<stop
offset='1'
stopColor={colors.lineColors[idx].pointFillC2}
stopOpacity={1}
/>
</linearGradient>
))}
</defs>

<CartesianGrid stroke={colors.grid} vertical={false} />
<XAxis dataKey='x' stroke={colors.grid} />
<YAxis orientation='left' stroke={colors.grid} tickCount={10}>
<Label
angle={-90}
fill='#9C97A2'
position={'insideLeft'}
style={{ textAnchor: 'middle' }}
value={'Test label'}
/>
</YAxis>

{['1', '2'].map((id, idx) => (
<Line
dataKey={id}
dot={({ cx, cy }) => (
<CustomizedDot
cx={cx}
cy={cy}
fill={`url(#grad${id})`}
stroke={colors.lineColors[idx].pointStroke}
strokeWidth={1}
/>
)}
isAnimationActive={false}
key={id}
stroke={colors.lineColors[idx].lineStroke}
strokeWidth={1}
type='monotone'
/** Test case for https://github.com/EvHaus/react-pdf-charts/issues/523 */
const MyDocument = () => (
<Document>
<Page size='A4' style={{ padding: 20 }}>
<ReactPDFChart>
<LineChart data={data} height={200} width={523}>
<defs>
<linearGradient id='gradient' x1={0.5} x2={0.5} y1={0} y2={1}>
<stop offset={0} stopColor='blue' stopOpacity={1} />
<stop offset={1} stopColor='red' stopOpacity={1} />
</linearGradient>
</defs>
<CartesianGrid />
<XAxis />
<YAxis />
<Line
dataKey='y'
dot={({ cx, cy }) => (
<circle
cx={cx}
cy={cy}
fill='url(#gradient)'
key='custom-dot'
r={12}
/>
))}
</LineChart>
</ReactPDFChart>
</Page>
</Document>
);
};
)}
strokeWidth={5}
/>
</LineChart>
</ReactPDFChart>
</Page>
</Document>
);

const __dirname = fileURLToPath(new URL('.', import.meta.url));

ReactPDF.render(<Linechart />, `${__dirname}/recharts-gradient.pdf`);
ReactPDF.render(<MyDocument />, `${__dirname}/recharts-gradient.pdf`);
Binary file modified examples/victory-basic.pdf
Binary file not shown.
10 changes: 6 additions & 4 deletions lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ pre-commit:
commands:
biome-format:
glob: "*.{js,jsx,ts,tsx}"
run: npx bun run biome format --write {staged_files}
run: bun run biome format --write {staged_files}
stage_fixed: true
biome-lint:
glob: "*.{js,jsx,ts,tsx}"
run: npx bun run biome check --write {staged_files}
run: bun run biome check --write {staged_files}
stage_fixed: true
prettier-package-json:
glob: "package.json"
run: npx bun run prettier-package-json --use-tabs --write {staged_files}
run: bun run prettier-package-json --use-tabs --write {staged_files}
stage_fixed: true
typescript:
glob: "*.{ts,tsx}"
run: npx bun run tsc --project ./tsconfig.json --noEmit
run: bun run tsc --project ./tsconfig.json --noEmit


Loading

0 comments on commit 8c583bd

Please sign in to comment.