-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
385 additions
and
398 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
export const options_kappa_rho = { | ||
animation: { | ||
duration: 0, | ||
}, | ||
plugins: { | ||
legend: { | ||
display: false, | ||
}, | ||
title: { | ||
display: true, | ||
text: "Kappa / Rho Plot", | ||
font: { | ||
size: 20, | ||
weight: "bold", | ||
}, | ||
}, | ||
tooltip: { | ||
callbacks: { | ||
title: function (tooltipItem) { | ||
return tooltipItem[0].raw.label; | ||
}, | ||
label: function (tooltipItem) { | ||
return ( | ||
Math.round((tooltipItem.parsed.y + Number.EPSILON) * 100) / 100 | ||
); | ||
}, | ||
}, | ||
}, | ||
zoom: { | ||
zoom: { | ||
wheel: { | ||
enabled: true, | ||
}, | ||
pinch: { | ||
enabled: true, | ||
}, | ||
drag: { | ||
enabled: true, | ||
}, | ||
mode: "xy", | ||
}, | ||
limits: { | ||
x: { min: "original", max: "original" }, | ||
y: { min: "original", max: "original" }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const options_rho = { | ||
animation: { | ||
duration: 0, | ||
}, | ||
plugins: { | ||
legend: { | ||
display: false, | ||
}, | ||
title: { | ||
display: true, | ||
text: "Rho Rank", | ||
font: { | ||
size: 20, | ||
weight: "bold", | ||
}, | ||
}, | ||
tooltip: { | ||
callbacks: { | ||
title: function (tooltipItem) { | ||
return tooltipItem[0].raw.label; | ||
}, | ||
label: function (tooltipItem) { | ||
return ( | ||
Math.round((tooltipItem.parsed.y + Number.EPSILON) * 100) / 100 | ||
); | ||
}, | ||
}, | ||
}, | ||
zoom: { | ||
zoom: { | ||
wheel: { | ||
enabled: true, | ||
}, | ||
pinch: { | ||
enabled: true, | ||
}, | ||
drag: { | ||
enabled: true, | ||
}, | ||
mode: "xy", | ||
}, | ||
limits: { | ||
x: { min: "original", max: "original" }, | ||
y: { min: "original", max: "original" }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const options_kappa = { | ||
animation: { | ||
duration: 0, | ||
}, | ||
plugins: { | ||
legend: { | ||
display: false, | ||
}, | ||
title: { | ||
display: true, | ||
text: "Kappa Rank", | ||
font: { | ||
size: 20, | ||
weight: "bold", | ||
}, | ||
}, | ||
tooltip: { | ||
callbacks: { | ||
title: function (tooltipItem) { | ||
return tooltipItem[0].raw.label; | ||
}, | ||
label: function (tooltipItem) { | ||
return ( | ||
Math.round((tooltipItem.parsed.y + Number.EPSILON) * 100) / 100 | ||
); | ||
}, | ||
}, | ||
}, | ||
zoom: { | ||
zoom: { | ||
wheel: { | ||
enabled: true, | ||
}, | ||
pinch: { | ||
enabled: true, | ||
}, | ||
drag: { | ||
enabled: true, | ||
}, | ||
mode: "xy", | ||
}, | ||
limits: { | ||
x: { min: "original", max: "original" }, | ||
y: { min: "original", max: "original" }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const optionsPie = { | ||
animation: { | ||
duration: 0, | ||
}, | ||
responsive: true, | ||
maintainAspectRatio: true, | ||
plugins: { | ||
tooltip: { | ||
callbacks: { | ||
title: function (tooltipItem) { | ||
return tooltipItem[0].label; | ||
}, | ||
label: function (tooltipItem) { | ||
return ( | ||
Math.round((tooltipItem.parsed + Number.EPSILON) * 100) / 100 + "%" | ||
); | ||
}, | ||
}, | ||
}, | ||
legend: { | ||
display: false, | ||
}, | ||
title: { | ||
display: true, | ||
text: "Variance Explained View", | ||
font: { | ||
size: 20, | ||
weight: "bold", | ||
}, | ||
}, | ||
}, | ||
}; |
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,173 @@ | ||
const acceptedColor = "#A8E3A5"; | ||
const acceptedColorHover = "#68AC64"; | ||
const rejedtecColor = "#E99497"; | ||
const rejedtecColorHover = "#B35458"; | ||
const ignoredColor = "#B5DEFF"; | ||
const ignoredColorHover = "#689FCC"; | ||
|
||
// This functions converts the data into 4 objects corresponding to the 4 plots. | ||
// The objects have the necessary structure to feed the chartjs plots. | ||
export function parseData(data) { | ||
let kappa_rho = { | ||
labels: data.map((e) => e.Component), | ||
datasets: [ | ||
{ | ||
type: "scatter", | ||
borderColor: "black", | ||
pointBackgroundColor: data.map((e) => e.color), | ||
pointHoverBackgroundColor: data.map((e) => e.colorHover), | ||
pointBorderColor: data.map((e) => e.color), | ||
pointRadius: 5, | ||
borderWidth: 1, | ||
fill: false, | ||
data: data.map((e) => ({ x: e.rho, y: e.kappa, label: e.Component })), | ||
classification: data.map((e) => e.classification), | ||
}, | ||
], | ||
}; | ||
|
||
let rho = { | ||
labels: data.map((e) => e.Component), | ||
datasets: [ | ||
{ | ||
type: "scatter", | ||
borderColor: "black", | ||
pointBackgroundColor: data.map((e) => e.color), | ||
pointHoverBackgroundColor: data.map((e) => e.colorHover), | ||
pointBorderColor: data.map((e) => e.color), | ||
pointRadius: 5, | ||
borderWidth: 1, | ||
fill: false, | ||
data: data.map((e) => ({ | ||
x: e["rho rank"], | ||
y: e.rho, | ||
label: e.Component, | ||
})), | ||
classification: data.map((e) => e.classification), | ||
}, | ||
], | ||
}; | ||
|
||
let kappa = { | ||
labels: data.map((e) => e.Component), | ||
datasets: [ | ||
{ | ||
type: "scatter", | ||
borderColor: "black", | ||
pointBackgroundColor: data.map((e) => e.color), | ||
pointHoverBackgroundColor: data.map((e) => e.colorHover), | ||
pointBorderColor: data.map((e) => e.color), | ||
pointRadius: 5, | ||
borderWidth: 1, | ||
fill: false, | ||
data: data.map((e) => ({ | ||
x: e["kappa rank"], | ||
y: e.kappa, | ||
label: e.Component, | ||
})), | ||
classification: data.map((e) => e.classification), | ||
}, | ||
], | ||
}; | ||
|
||
data.sort(function (a, b) { | ||
return ( | ||
a.classification.localeCompare(b.classification) || | ||
b["variance explained"] - a["variance explained"] | ||
); | ||
}); | ||
|
||
let variance = { | ||
labels: data.map((e) => e.Component), | ||
datasets: [ | ||
{ | ||
label: data.map((e) => e.classification), | ||
borderColor: "black", | ||
backgroundColor: data.map((e) => e.color), | ||
hoverBackgroundColor: data.map((e) => e.colorHover), | ||
borderWidth: 0.5, | ||
data: data.map((e) => e["variance explained"]), | ||
classification: data.map((e) => e.classification), | ||
}, | ||
], | ||
}; | ||
|
||
return [kappa_rho, variance, kappa, rho]; | ||
} | ||
|
||
export function assignColor(data) { | ||
for (var i = 0; i < data.length; i++) { | ||
if (data[i].classification === "accepted") { | ||
data[i].color = acceptedColor; | ||
data[i].colorHover = acceptedColorHover; | ||
} else if (data[i].classification === "rejected") { | ||
data[i].color = rejedtecColor; | ||
data[i].colorHover = rejedtecColorHover; | ||
} else if (data[i].classification === "ignored") { | ||
data[i].color = ignoredColor; | ||
data[i].colorHover = ignoredColorHover; | ||
} | ||
} | ||
} | ||
|
||
export function resetColors(data, isPie) { | ||
for (var i = 0; i < data.labels.length; i++) { | ||
if (data.datasets[0].classification[i] === "accepted") { | ||
if (isPie) { | ||
data.datasets[0].backgroundColor[i] = acceptedColor; | ||
} else { | ||
data.datasets[0].pointBackgroundColor[i] = acceptedColor; | ||
data.datasets[0].pointBorderColor[i] = acceptedColor; | ||
} | ||
} else if (data.datasets[0].classification[i] === "rejected") { | ||
if (isPie) { | ||
data.datasets[0].backgroundColor[i] = rejedtecColor; | ||
} else { | ||
data.datasets[0].pointBackgroundColor[i] = rejedtecColor; | ||
data.datasets[0].pointBorderColor[i] = rejedtecColor; | ||
} | ||
} else if (data.datasets[0].classification[i] === "ignored") { | ||
if (isPie) { | ||
data.datasets[0].backgroundColor[i] = ignoredColor; | ||
} else { | ||
data.datasets[0].pointBackgroundColor[i] = ignoredColor; | ||
data.datasets[0].pointBorderColor[i] = ignoredColor; | ||
} | ||
} | ||
} | ||
} | ||
|
||
export function updatePieColors(data, index, color, isNew) { | ||
data.datasets[0].backgroundColor[index] = color; | ||
if (isNew) { | ||
data.datasets[0].hoverBackgroundColor[index] = color; | ||
} | ||
} | ||
|
||
export function updateScatterColors(data, index, color, isNew) { | ||
data.datasets[0].pointBackgroundColor[index] = color; | ||
data.datasets[0].pointBorderColor[index] = color; | ||
if (isNew) { | ||
data.datasets[0].pointHoverBackgroundColor[index] = color; | ||
} | ||
} | ||
|
||
export function resetAndUpdateColors(data, index, isVariance) { | ||
if (isVariance) { | ||
resetColors(data, isVariance); | ||
updatePieColors( | ||
data, | ||
index, | ||
data.datasets[0].hoverBackgroundColor[index], | ||
false | ||
); | ||
} else { | ||
resetColors(data, isVariance); | ||
updateScatterColors( | ||
data, | ||
index, | ||
data.datasets[0].pointHoverBackgroundColor[index], | ||
false | ||
); | ||
} | ||
} |
Oops, something went wrong.