-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ECOPROJECT-2338: Migration assesment discovery report update (#46)
* Change bart chart for pie chart Signed-off-by: Montse Ortega <[email protected]> * Add usage bar in Storage table Signed-off-by: Montse Ortega <[email protected]> * Changes in legend's label in the pie charts Signed-off-by: Montse Ortega <[email protected]> * Changes in titles in discovery report Signed-off-by: Montse Ortega <[email protected]> --------- Signed-off-by: Montse Ortega <[email protected]>
- Loading branch information
Showing
2 changed files
with
132 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
apps/demo/src/migration-wizard/steps/discovery/ReportPieChart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React from "react"; | ||
import { ChartPie } from "@patternfly/react-charts"; | ||
import { TextContent, Text } from "@patternfly/react-core"; | ||
|
||
type ChartBarDataEntry = { | ||
name: string; | ||
x: string; | ||
y: number; | ||
}; | ||
|
||
|
||
function histogramToPieChartData( | ||
histogram: ReportPieChart.Histogram, | ||
legendLabel: string, | ||
): ChartBarDataEntry[] { | ||
const { data } = histogram; | ||
return data | ||
.filter(y => y > 0) // Filtrar valores mayores que 0 | ||
.map((y, idx) => ({ | ||
name: legendLabel, | ||
x: `${idx + 1} ${legendLabel}`, // Cambia esto según tus necesidades | ||
y, | ||
})).sort((a, b) => a.y - b.y); | ||
} | ||
|
||
function getLegendData( histogram: ReportPieChart.Histogram,legendLabel:string): { name: string; }[] { | ||
return histogramToPieChartData(histogram, '').map(d => ({ name: `${d.x} ${legendLabel}: ${d.y} VM` })) | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
export namespace ReportPieChart { | ||
export type Histogram = { | ||
data: number[]; | ||
minValue: number; | ||
step: number; | ||
|
||
}; | ||
|
||
export type Props = { | ||
histogram: Histogram; | ||
title: string; | ||
legendLabel: string; | ||
}; | ||
} | ||
|
||
export function ReportPieChart(props: ReportPieChart.Props): React.ReactNode { | ||
const { title, histogram,legendLabel } = props; | ||
return ( | ||
<> | ||
<TextContent style={{ textAlign: "center" }}> | ||
<Text>{title}</Text> | ||
</TextContent> | ||
<ChartPie | ||
name={title.toLowerCase().split(" ").join("-")} | ||
ariaDesc={title + " chart"} | ||
ariaTitle={title + " chart"} | ||
constrainToVisibleArea | ||
data={histogramToPieChartData(histogram, legendLabel)} | ||
height={230} | ||
labels={({ datum }) => `${datum.x}: ${datum.y}`} | ||
legendData={getLegendData(histogram,legendLabel)} | ||
legendOrientation="vertical" | ||
legendPosition="right" | ||
padding={{ | ||
bottom: 20, | ||
left: 20, | ||
right: 140, // Adjusted to accommodate legend | ||
top: 20, | ||
}} | ||
width={450} | ||
colorScale={['#73BCF7','#73C5C5','#F9E0A2','#BDE5B8','#D2D2D2','#F4B678','#CBC1FF','#FF7468','#7CDBF3','#E4F5BC']}/> | ||
|
||
</> | ||
); | ||
} |