Skip to content

Commit

Permalink
Update the projects page
Browse files Browse the repository at this point in the history
  • Loading branch information
CannonLock committed Feb 7, 2024
1 parent 55dbad3 commit 1422ec2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 27 deletions.
48 changes: 45 additions & 3 deletions assets/js/components/pie-chart.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Chart, registerables} from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'
import Color from "https://colorjs.io/dist/color.js";

Chart.register(...registerables);

Expand All @@ -21,6 +22,46 @@ const getOrCreateLegendList = (chart, id) => {
return listContainer;
};

/**
* Returns a hash code from a string
* @param {String} str The string to hash.
* @return {Number} A 32bit integer
* @see http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
*/
function hashCode(str) {
let hash = 0;
for (let i = 0, len = str.length; i < len; i++) {
let chr = str.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
}

const getColor = (context) => {

const colors = [
"#37a2eb",
"#ff6384",
"#ff9e40",
"#9966ff",
"#ffcd56",
"#4dbd74"
]

let hash = hashCode(context) ** 2 // Make sure its positive

let color = colors[hash % (colors.length - 1)]

let colorObj = new Color(color).to("lch");

// Manipulate the color based on the hash
colorObj = colorObj.lighten((hash % 19) / 100)
colorObj = colorObj.darken((hash % 23) / 100)

return colorObj.to("srgb").toString();
}

const htmlLegendPlugin = {
id: 'htmlLegend',
afterUpdate(chart, args, options) {
Expand Down Expand Up @@ -118,14 +159,14 @@ export class PieChart {
parent.className = 'row gx-0';

this.canvasContainer = document.createElement('div');
this.canvasContainer.className = "col-md-8 col-12"
this.canvasContainer.className = "col-8"

this.canvas = document.createElement('canvas');
this.canvas.id = `canvas-${this.id}`;

this.legend = document.createElement('div');
this.legend.id = `legend-${this.id}`;
this.legend.className = "col-md-4 col-12"
this.legend.className = "col-4"

// Empty the children out of the parent element
while (parent.firstChild) {
Expand All @@ -145,7 +186,8 @@ export class PieChart {
datasets: [{
label: this.label,
data: this.data['data'],
borderWidth: 1
borderWidth: 1,
backgroundColor: this.data['labels'].map(getColor),
}]
},
options: {
Expand Down
8 changes: 4 additions & 4 deletions assets/js/project-page-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +488,12 @@ class ProjectPage{
}

this.orgPieChart = new PieChart(
"project-institution-summary",
this.dataManager.reduceByKey.bind(this.dataManager, "Organization", "jobs"),
"# of Jobs by Institution"
"project-fos-cpu-summary",
this.dataManager.reduceByKey.bind(this.dataManager, "FieldOfScience", "cpuHours"),
"# of CPU Hours by Field of Science"
)
this.FosPieChart = new PieChart(
"project-fos-summary",
"project-fos-job-summary",
this.dataManager.reduceByKey.bind(this.dataManager, "FieldOfScience", "jobs"),
"# of Jobs by Field Of Science"
)
Expand Down
39 changes: 19 additions & 20 deletions projects.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@
}
</style>
<div class="container-xxl">
{% include layout/title.html %}
<h1>
{{page.title}}
<span class="badge bg-secondary text-dark" data-bs-toggle="tooltip" data-bs-placement="top" title="Number of Active Project in the OSPool">
<span id="project-count">X</span>
</span>
</h1>
<div>
<h6>Data updated: <span id="last-updated"></span></h6>
<script>
Expand All @@ -53,12 +58,9 @@ <h6>Data updated: <span id="last-updated"></span></h6>
<div class="bg-dark text-light pb-3">
<div class="container-xxl">
<div class="row">
<div class="col-12 col-xl-12 col-lg-12 col-md-12">
<h2 class="mini-bar" id="project-overview">Project Overview</h2>
</div>
<div class="col-md-4 col-12">
<h4 class="mt-3">
By Jobs
Projects by Jobs

<span data-bs-toggle="tooltip" data-bs-placement="top" title="Completed Jobs by Project">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-question-circle" viewBox="0 0 16 16">
Expand All @@ -75,7 +77,7 @@ <h4 class="mt-3">
</div>
<div class="col-md-4 col-12">
<h4 class="mt-3">
By CPU Hours
Projects by CPU Hours

<span data-bs-toggle="tooltip" data-bs-placement="top" title="Used CPU Hours by Project">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-question-circle" viewBox="0 0 16 16">
Expand All @@ -92,7 +94,7 @@ <h4 class="mt-3">
</div>
<div class="col-md-4 col-12">
<h4 class="mt-3">
By GPU Hours
Projects by GPU Hours

<span data-bs-toggle="tooltip" data-bs-placement="top" title="Used GPU Hours by Project">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-question-circle" viewBox="0 0 16 16">
Expand All @@ -108,38 +110,35 @@ <h4 class="mt-3">
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-xl-7 col-lg-8 col-md-10">
<h2 class="mini-bar">Job Aggregates</h2>
</div>
<div class="col-md-6 col-12">
<div class="row justify-content-center d-none d-md-flex">
<div class="col-md-6 col-lg-4 col-12">
<h4 class="mt-3">
By Project Institutions
<span data-bs-toggle="tooltip" data-bs-placement="top" title="Job Aggregates by Project Institutions">
Fields of Science by Jobs
<span data-bs-toggle="tooltip" data-bs-placement="top" title="Job Aggregates by Project Field of Science">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-question-circle" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16"/>
<path d="M5.255 5.786a.237.237 0 0 0 .241.247h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286m1.557 5.763c0 .533.425.927 1.01.927.609 0 1.028-.394 1.028-.927 0-.552-.42-.94-1.029-.94-.584 0-1.009.388-1.009.94"/>
</svg>
</span>
</h4>
<div id="project-institution-summary">
<div id="project-fos-job-summary">
<div class="spinner-grow text-light" style="width: 5rem; height: 5rem;" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</div>
<div class="col-md-6 col-12">
<div class="col-md-6 col-lg-4 col-12">
<h4 class="mt-3">
By Project Fields of Science
Fields of Science by CPU Hours

<span data-bs-toggle="tooltip" data-bs-placement="top" title="Job Aggregates by Project Field Of Science">
<span data-bs-toggle="tooltip" data-bs-placement="top" title="CPU Hour Aggregates by Project Field Of Science">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-question-circle" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16"/>
<path d="M5.255 5.786a.237.237 0 0 0 .241.247h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286m1.557 5.763c0 .533.425.927 1.01.927.609 0 1.028-.394 1.028-.927 0-.552-.42-.94-1.029-.94-.584 0-1.009.388-1.009.94"/>
</svg>
</span>
</h4>
<div id="project-fos-summary">
<div id="project-fos-cpu-summary">
<div class="spinner-grow text-light" style="width: 5rem; height: 5rem;" role="status">
<span class="visually-hidden">Loading...</span>
</div>
Expand All @@ -153,7 +152,7 @@ <h4 class="mt-3">
<div class="col-12 col-xl-7 col-lg-8 col-md-10">

<h2 class="mini-bar">By Project</h2>
<h5 class="pb-3"><span class="badge bg-secondary text-dark"><span id="project-count">X</span> Projects</span></h6>
<h5 class="pb-3"></h6>
<p class="d-none d-sm-block mb-2">
<b>Click on a row to view project details and their resource usage.</b>
</p>
Expand Down

0 comments on commit 1422ec2

Please sign in to comment.