Skip to content

Commit

Permalink
Merge pull request #300 from K4ST0R/feat-chart
Browse files Browse the repository at this point in the history
feat: ajout des charts
  • Loading branch information
garronej authored Sep 8, 2024
2 parents 0ab5f2a + 963cdf6 commit 0db478a
Show file tree
Hide file tree
Showing 28 changed files with 1,608 additions and 162 deletions.
3 changes: 2 additions & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module.exports = {
"stories": [
"../stories/*.stories.mdx",
"../stories/*.stories.@(ts|tsx)",
"../stories/blocks/*.stories.@(ts|tsx)"
"../stories/blocks/*.stories.@(ts|tsx)",
"../stories/charts/*.stories.@(ts|tsx)"
],
"addons": [
"@storybook/addon-links",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
],
"homepage": "https://github.com/codegouvfr/react-dsfr",
"dependencies": {
"@gouvfr/dsfr-chart": "^1.0.0",
"tsafe": "^1.7.2",
"yargs-parser": "^21.1.1"
},
Expand Down
43 changes: 43 additions & 0 deletions src/Chart/BarChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use client";
import React from "react";
import { symToStr } from "tsafe/symToStr";
import "@gouvfr/dsfr-chart/BarChart/bar-chart.common";
import "@gouvfr/dsfr-chart/BarChart/bar-chart.css";
import {
chartWrapper,
IntrinsicGraphType,
BaseChartProps,
stringifyObjectValue,
MultiChartProps,
ChartLineProps,
IntrinsicGraphLineType
} from "./chartWrapper";

declare global {
namespace JSX {
interface IntrinsicElements {
// https://github.com/GouvernementFR/dsfr-chart/blob/v1.0.0/src/components/BarChart.vue#L79
"bar-chart": {
horizontal?: string;
stacked?: string;
} & IntrinsicGraphType &
IntrinsicGraphLineType;
}
}
}

export type BarChartBaseProps = {
horizontal?: boolean;
stacked?: boolean;
} & MultiChartProps &
ChartLineProps;

export type BarChartProps = BarChartBaseProps & BaseChartProps;

/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/charts-barchart> */
export const BarChart = chartWrapper((props: BarChartBaseProps) => {
return <bar-chart {...stringifyObjectValue(props)} />;
}, "bar-chart");
BarChart.displayName = symToStr({ BarChart });

export default BarChart;
44 changes: 44 additions & 0 deletions src/Chart/BarLineChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"use client";
import React from "react";
import { symToStr } from "tsafe/symToStr";
import "@gouvfr/dsfr-chart/BarLineChart/barline-chart.common";
import "@gouvfr/dsfr-chart/BarLineChart/barline-chart.css";
import {
chartWrapper,
IntrinsicGraphType,
BaseChartProps,
stringifyObjectValue,
ChartProps,
ChartLineProps,
IntrinsicGraphLineType
} from "./chartWrapper";

declare global {
namespace JSX {
interface IntrinsicElements {
// https://github.com/GouvernementFR/dsfr-chart/blob/v1.0.0/src/components/BarLineChart.vue#L75
"bar-line-chart": {
ybar: string;
} & IntrinsicGraphType &
IntrinsicGraphLineType;
}
}
}

export type BarLineChartBaseProps = {
ybar: number[];
name?: [string, string];
horizontal?: boolean;
stacked?: boolean;
} & Omit<ChartProps, "name"> &
ChartLineProps;

export type BarLineChartProps = BarLineChartBaseProps & BaseChartProps;

/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/charts-barlinechart> */
export const BarLineChart = chartWrapper((props: BarLineChartBaseProps) => {
return <bar-line-chart {...stringifyObjectValue(props)} />;
}, "bar-line-chart");
BarLineChart.displayName = symToStr({ BarLineChart });

export default BarLineChart;
38 changes: 38 additions & 0 deletions src/Chart/GaugeChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use client";
import React from "react";
import { symToStr } from "tsafe/symToStr";
import "@gouvfr/dsfr-chart/GaugeChart/gauge-chart.common";
import "@gouvfr/dsfr-chart/GaugeChart/gauge-chart.css";
import { chartWrapper, BaseChartProps, stringifyObjectValue, ChartColor } from "./chartWrapper";

declare global {
namespace JSX {
interface IntrinsicElements {
// https://github.com/GouvernementFR/dsfr-chart/blob/v1.0.0/src/components/GaugeChart.vue#L55
"gauge-chart": {
value: string;
init: string;
target: string;
color: string;
};
}
}
}

export type GaugeChartBaseProps = {
value: number;
init: number;
target: number;
color?: ChartColor;
};

export type GaugeChartProps = GaugeChartBaseProps & BaseChartProps;

/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/charts-gaugechart> */
export const GaugeChart = chartWrapper(
(props: GaugeChartBaseProps) => <gauge-chart {...stringifyObjectValue(props)} />,
"gauge-chart"
);
GaugeChart.displayName = symToStr({ GaugeChart });

export default GaugeChart;
36 changes: 36 additions & 0 deletions src/Chart/LineChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"use client";
import React from "react";
import { symToStr } from "tsafe/symToStr";
import "@gouvfr/dsfr-chart/LineChart/line-chart.common";
import "@gouvfr/dsfr-chart/LineChart/line-chart.css";
import {
chartWrapper,
ChartProps,
IntrinsicGraphType,
BaseChartProps,
stringifyObjectValue,
ChartLineProps,
IntrinsicGraphLineType
} from "./chartWrapper";

declare global {
namespace JSX {
interface IntrinsicElements {
// https://github.com/GouvernementFR/dsfr-chart/blob/v1.0.0/src/components/LineChart.vue#L70
"line-chart": IntrinsicGraphType & IntrinsicGraphLineType;
}
}
}

export type LineChartBaseProps = ChartProps & ChartLineProps;

export type LineChartProps = LineChartBaseProps & BaseChartProps;

/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/charts-linechart> */
export const LineChart = chartWrapper(
(props: LineChartBaseProps) => <line-chart {...stringifyObjectValue(props)} />,
"line-chart"
);
LineChart.displayName = symToStr({ LineChart });

export default LineChart;
36 changes: 36 additions & 0 deletions src/Chart/MultiLineChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"use client";
import React from "react";
import { symToStr } from "tsafe/symToStr";
import "@gouvfr/dsfr-chart/MultiLineChart/multiline-chart.common";
import "@gouvfr/dsfr-chart/MultiLineChart/multiline-chart.css";
import {
chartWrapper,
IntrinsicGraphType,
BaseChartProps,
stringifyObjectValue,
MultiChartProps,
ChartLineProps,
IntrinsicGraphLineType
} from "./chartWrapper";

declare global {
namespace JSX {
interface IntrinsicElements {
// https://github.com/GouvernementFR/dsfr-chart/blob/v1.0.0/src/components/MultiLineChart.vue#L74
"multiline-chart": IntrinsicGraphType & IntrinsicGraphLineType;
}
}
}

export type MultiLineChartBaseProps = MultiChartProps & ChartLineProps;

export type MultiLineChartProps = MultiLineChartBaseProps & BaseChartProps;

/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/charts-multilinechart> */
export const MultiLineChart = chartWrapper(
(props: MultiLineChartBaseProps) => <multiline-chart {...stringifyObjectValue(props)} />,
"multiline-chart"
);
MultiLineChart.displayName = symToStr({ MultiLineChart });

export default MultiLineChart;
38 changes: 38 additions & 0 deletions src/Chart/PieChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use client";
import React from "react";
import { symToStr } from "tsafe/symToStr";
import "@gouvfr/dsfr-chart/PieChart/pie-chart.common";
import "@gouvfr/dsfr-chart/PieChart/pie-chart.css";
import {
chartWrapper,
ChartProps,
IntrinsicGraphType,
BaseChartProps,
stringifyObjectValue
} from "./chartWrapper";

declare global {
namespace JSX {
interface IntrinsicElements {
// https://github.com/GouvernementFR/dsfr-chart/blob/v1.0.0/src/components/PieChart.vue#L59
"pie-chart": {
fill?: string;
} & IntrinsicGraphType;
}
}
}

export type PieChartBaseProps = {
fill?: boolean;
} & ChartProps;

export type PieChartProps = PieChartBaseProps & BaseChartProps;

/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/charts-piechart> */
export const PieChart = chartWrapper(
(props: PieChartBaseProps) => <pie-chart {...stringifyObjectValue(props)} />,
"pie-chart"
);
PieChart.displayName = symToStr({ PieChart });

export default PieChart;
34 changes: 34 additions & 0 deletions src/Chart/RadarChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use client";
import React from "react";
import { symToStr } from "tsafe/symToStr";
import "@gouvfr/dsfr-chart/RadarChart/radar-chart.common";
import "@gouvfr/dsfr-chart/RadarChart/radar-chart.css";
import {
chartWrapper,
IntrinsicGraphType,
BaseChartProps,
stringifyObjectValue,
MultiChartProps
} from "./chartWrapper";

declare global {
namespace JSX {
interface IntrinsicElements {
// https://github.com/GouvernementFR/dsfr-chart/blob/v1.0.0/src/components/RadarChart.vue#L57
"radar-chart": IntrinsicGraphType;
}
}
}

export type RadarChartBaseProps = MultiChartProps;

export type RadarChartProps = RadarChartBaseProps & BaseChartProps;

/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/charts-radarchart> */
export const RadarChart = chartWrapper(
(props: RadarChartBaseProps) => <radar-chart {...stringifyObjectValue(props)} />,
"radar-chart"
);
RadarChart.displayName = symToStr({ RadarChart });

export default RadarChart;
43 changes: 43 additions & 0 deletions src/Chart/ScatterChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use client";
import React from "react";
import { symToStr } from "tsafe/symToStr";
import "@gouvfr/dsfr-chart/ScatterChart/scatter-chart.common";
import "@gouvfr/dsfr-chart/ScatterChart/scatter-chart.css";
import {
chartWrapper,
BaseChartProps,
MultiChartProps,
IntrinsicGraphType,
stringifyObjectValue,
ChartLineProps,
IntrinsicGraphLineType
} from "./chartWrapper";

declare global {
namespace JSX {
interface IntrinsicElements {
// https://github.com/GouvernementFR/dsfr-chart/blob/v1.0.0/src/components/ScatterChart.vue#L75
"scatter-chart": {
showLine?: string;
} & IntrinsicGraphType &
IntrinsicGraphLineType;
}
}
}

type ScatterChartBaseProps = {
x: number[][];
showLine?: boolean;
} & Omit<MultiChartProps, "x"> &
ChartLineProps;

export type ScatterChartProps = ScatterChartBaseProps & BaseChartProps;

/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/charts-radarchart> */
export const ScatterChart = chartWrapper(
(props: ScatterChartBaseProps) => <scatter-chart {...stringifyObjectValue(props)} />,
"scatter-chart"
);
ScatterChart.displayName = symToStr({ ScatterChart });

export default ScatterChart;
Loading

0 comments on commit 0db478a

Please sign in to comment.