Skip to content

Feat/adding custom label and dimensions names #4

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 23 additions & 2 deletions src/components/graph/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const AreaChart: React.FC<AreaChartProps> = ({
data,
metrics,
dimensions,
labelNames,
dimensionsNames,
className = "w-full h-80",
colors = QualitativeColorPallete,
margin = DefaultMargins,
Expand Down Expand Up @@ -44,10 +46,29 @@ const AreaChart: React.FC<AreaChartProps> = ({
<Area type="monotone" key={index} dataKey={metric} stroke={colors[index % colors.length]} fillOpacity={1} fill={`url(#color${index})`} />
))}

{dimensionsNames.map((dimension, index) => (
<Tooltip
key={index}
contentStyle={{ backgroundColor: "#fff", border: "1px solid #ccc" }}
formatter={(value, name, entry) => {
const customDimensionName = dimensionsNames && dimensionsNames[index]
? dimensionsNames[index]
: name;
const typedEntry = entry as any;
const customLabelName = labelNames && labelNames[index]
? labelNames[index]
: typedEntry[dimensionsNames[0]];

return [customDimensionName, customLabelName, value];
}}
labelFormatter={() => null}
separator=""
position={{ x: 0, y: 0 }}
/>
))}
</RAreaChart>
</ResponsiveContainer>
</div>
);
};

export default AreaChart;
export default AreaChart;
22 changes: 22 additions & 0 deletions src/components/graph/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const BarChart: React.FC<BarChartProps> = ({
data,
metrics,
dimensions,
labelNames,
dimensionsNames,
className = "w-full h-80",
colors = QualitativeColorPallete,
margin = DefaultMargins,
Expand Down Expand Up @@ -35,6 +37,26 @@ const BarChart: React.FC<BarChartProps> = ({
<Bar dataKey={metric} key={index} fill={colors[index % colors.length]} />
))}

{dimensionsNames.map((dimension, index) => (
<Tooltip
key={index}
contentStyle={{ backgroundColor: "#fff", border: "1px solid #ccc" }}
formatter={(value, name, entry) => {
const customDimensionName = dimensionsNames && dimensionsNames[index]
? dimensionsNames[index]
: name;
const typedEntry = entry as any;
const customLabelName = labelNames && labelNames[index]
? labelNames[index]
: typedEntry[dimensionsNames[0]];
return [customDimensionName, customLabelName, value];
}}
labelFormatter={() => null}
separator=""
position={{ x: 0, y: 0 }}
/>
))}

</RBarChart>
</ResponsiveContainer>
</div>
Expand Down
21 changes: 21 additions & 0 deletions src/components/graph/BubbleChart/BubbleChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const BubbleChart: React.FC<BubbleChartProps> = ({
data,
xKey: xDimension,
yKey: yDimension,
labelNames,
dimensionsNames,
dataKey = "",
className = "w-full h-80",
colors = QualitativeColorPallete,
Expand Down Expand Up @@ -56,7 +58,26 @@ const BubbleChart: React.FC<BubbleChartProps> = ({
<Tooltip content={<FrolicTooltip />} />
<Legend iconType="circle" />
<Scatter name={dataKey} dataKey={dataKey} fill={colors[0 % colors.length]} />
{dimensionsNames.map((dimensionName, index) => (
<Tooltip
key={index}
contentStyle={{ backgroundColor: "#fff", border: "1px solid #ccc" }}
formatter={(value, name, entry) => {
const customDimensionName = dimensionsNames && dimensionsNames[index]
? dimensionsNames[index]
: name;
const typedEntry = entry as any;
const customLabelName = labelNames && labelNames[index]
? labelNames[index]
: typedEntry[dataKey]; // Assuming the dataKey is used as the label

return [customDimensionName, customLabelName, value];
}}
labelFormatter={() => null}
separator=""
position={{ x: 0, y: 0 }}
/>
))}
</RScatterChart>
</ResponsiveContainer>
</div>
Expand Down
23 changes: 23 additions & 0 deletions src/components/graph/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const LineChart: React.FC<LineChartProps> = ({
data,
metrics,
dimensions,
labelNames,
dimensionsNames,
className = "w-full h-80",
colors = QualitativeColorPallete,
margin = DefaultMargins,
Expand All @@ -32,6 +34,27 @@ const LineChart: React.FC<LineChartProps> = ({
</>
))}

{dimensionsNames.map((dimensionName, index) => (
<Tooltip
key={index}
contentStyle={{ backgroundColor: "#fff", border: "1px solid #ccc" }}
formatter={(value, name, entry) => {
const customDimensionName = dimensionsNames && dimensionsNames[index]
? dimensionsNames[index]
: name;
const typedEntry = entry as any;
const customLabelName = labelNames && labelNames[index]
? labelNames[index]
: typedEntry[dimensions[0]]; // Assuming the first dimension is used as the label

return [customDimensionName, customLabelName, value];
}}
labelFormatter={() => null}
separator=""
position={{ x: 0, y: 0 }}
/>
))}

</RLineChart>
</ResponsiveContainer>
</div>
Expand Down
21 changes: 21 additions & 0 deletions src/components/graph/ScatterChart/ScatterChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const ScatterChart: React.FC<ScatterChartProps> = ({
data,
xKey: xDimension,
yKey: yDimension,
labelNames,
dimensionsNames,
dataKey = "",
className = "w-full h-80",
colors = QualitativeColorPallete,
Expand All @@ -28,7 +30,26 @@ const ScatterChart: React.FC<ScatterChartProps> = ({
<Legend iconType="circle" />

<Scatter name={dataKey} fill={colors[0 % colors.length]} />
{dimensionsNames.map((dimensionName, index) => (
<Tooltip
key={index}
contentStyle={{ backgroundColor: "#fff", border: "1px solid #ccc" }}
formatter={(value, name, entry) => {
const customDimensionName = dimensionsNames && dimensionsNames[index]
? dimensionsNames[index]
: name;
const typedEntry = entry as any;
const customLabelName = labelNames && labelNames[index]
? labelNames[index]
: typedEntry[dataKey];

return [customDimensionName, customLabelName, value];
}}
labelFormatter={() => null}
separator=""
position={{ x: 0, y: 0 }}
/>
))}
</RScatterChart>
</ResponsiveContainer>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/utils/AxisFormatter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const FrolicTooltip: React.FC<CustomTooltipProps> = ({ active, payload, l
</>
}

{payload.map((entry, index) => (
{payload.map((entry , index) => (
<div className='flex flex-row gap-1 items-center'>
<div className='w-1 h-4 rounded-sm' style={{ background: entry.color }}>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/components/utils/ChartInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export interface ChartInterface {
data: any[];
dimensions: string[];
metrics: string[];
labelNames: string[];
dimensionsNames: string[];
className?: string;
colors?: string[];
margin?: Margin;
Expand All @@ -11,6 +13,8 @@ export interface ScatterChartInterface {
data: any[];
xKey: string;
yKey: string;
labelNames: string[];
dimensionsNames: string[];
dataKey?: string;
className?: string;
colors?: string[];
Expand Down