Skip to content

Commit

Permalink
Merge pull request #45 from escottalexander/logarithmic
Browse files Browse the repository at this point in the history
Adds Logarithmic view to graph
  • Loading branch information
0xChijioke authored Feb 24, 2024
2 parents 411f878 + a6c0c92 commit 118f9d5
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/nextjs/components/impact-vector/ImpactVectorGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const transformData = (impactData: DataSet[]): any[] => {
const transformedItem: any = {
image: item.metadata["Meta: Project Image"],
name: item.metadata["Meta: Project Name"],
Rank: Math.floor(item.rank),
Rank: item.rank.toFixed(2),
profile: `${item.metadata["Meta: Project Name"]}===${item.metadata["Meta: Project Image"]}`,
};

Expand All @@ -40,6 +40,7 @@ const sortByTotalDescending = (dataSetArray: any[]) => {

export default function ImpactVectorGraph({ data }: { data: DataSet[] }) {
const [showVectors, setShowVectors] = useState(false);
const [isLogarithmic, setIsLogarithmic] = useState(false);
const [hoveredProject, setHoveredProject] = useState<string | null>(null);
const transformedData = transformData(sortByTotalDescending(data));

Expand Down Expand Up @@ -89,7 +90,14 @@ export default function ImpactVectorGraph({ data }: { data: DataSet[] }) {
}
}}
>
<YAxis axisLine={false} tickLine={false} className="text-xs opacity-50" tickMargin={10} />
<YAxis
axisLine={false}
tickLine={false}
className="text-xs opacity-50"
tickMargin={10}
scale={isLogarithmic ? "log" : "linear"}
domain={["auto", "auto"]}
/>
<XAxis
dataKey="profile"
onMouseMove={handleMouseMove}
Expand All @@ -110,7 +118,9 @@ export default function ImpactVectorGraph({ data }: { data: DataSet[] }) {
.filter(key => key.endsWith("_actual"))
.map(key => {
const value = data[key];
const formattedValue = !isNaN(value) ? Math.floor(parseFloat(value)) : value;
const formattedValue = !isNaN(value || "string")
? Math.floor(parseFloat(value)) || "none"
: value || "none";
return (
<p key={key}>{`${key.replace(/^OSO:/, "").replace("_actual", "")}: ${formattedValue}`}</p>
);
Expand Down Expand Up @@ -153,6 +163,9 @@ export default function ImpactVectorGraph({ data }: { data: DataSet[] }) {
{transformedData.length > 0 && (
<div className="items-center text-xs justify-end flex">
<button onClick={() => setShowVectors(!showVectors)}>{showVectors ? "Hide Vectors" : "Show Vectors"}</button>
<button className="px-3" onClick={() => setIsLogarithmic(!isLogarithmic)}>
{isLogarithmic ? "Linear" : "Logarithmic"}
</button>
</div>
)}
</div>
Expand Down

0 comments on commit 118f9d5

Please sign in to comment.