Skip to content
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

refractor:widget/statistics-lint, prettify and documentation #2770

Merged
merged 2 commits into from
Jan 24, 2021
Merged
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
75 changes: 50 additions & 25 deletions js/widgets/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
// License along with this library; if not, write to the Free Software
// Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA

/**
* This widget makes displays the status of selected parameters and notes as they are being played.
/*
global logo, blocks, docById, _showHideAuxMenu, analyzeProject, runAnalytics, scoreToChartData,
getChartOptions, loading:writable, Chart
*/

/* exported StatsWindow, loading */

/** This widget displays the status of selected parameters and notes as they are being played. */
class StatsWindow {
constructor() {
this.isOpen = true;
Expand All @@ -27,54 +32,74 @@ class StatsWindow {
this.doAnalytics();

this.widgetWindow.sendToCenter();
};
}

/**
* Renders and carries out analysis of the MB project.
*/
/** Renders and carries out analysis of the MB project. */
doAnalytics() {
toolbar.closeAuxToolbar(_showHideAuxMenu);
blocks.activeBlock = null;
let myChart = docById("myChart");
const myChart = docById("myChart");

let ctx = myChart.getContext("2d");
const ctx = myChart.getContext("2d");
loading = true;
document.body.style.cursor = "wait";

let myRadarChart = null;
let scores = analyzeProject(blocks);
const scores = analyzeProject(blocks);
runAnalytics(logo);
let data = scoreToChartData(scores);
const data = scoreToChartData(scores);
const __callback = () => {
let imageData = myRadarChart.toBase64Image();
let img = new Image();
const imageData = myRadarChart.toBase64Image();
const img = new Image();
img.src = imageData;
img.width = 200;
this.widgetWindow.getWidgetBody().appendChild(img);
blocks.hideBlocks();
logo.showBlocksAfterRun = false;
document.body.style.cursor = "default";
};
let options = getChartOptions(__callback);
const options = getChartOptions(__callback);
myRadarChart = new Chart(ctx).Radar(data, options);

this.jsonObject = document.createElement("ul");
this.jsonObject.style.float = "left";
this.widgetWindow.getWidgetBody().appendChild(this.jsonObject);
};
}

displayInfo(stats) {
let lowHertz = stats["lowestNote"][2] + 0.5;
let highHertz = stats["highestNote"][2] + 0.5;
const lowHertz = stats["lowestNote"][2] + 0.5;
const highHertz = stats["highestNote"][2] + 0.5;
this.jsonObject.innerHTML =
'<li>duples: ' + stats["duples"] + '</li>' +
'<li>triplets: ' + stats["triplets"] + '</li>' +
'<li>quintuplets: ' + stats["quintuplets"] + '</li>' +
'<li>pitch names: ' + Array.from(stats["pitchNames"]) + '</li>' +
'<li>number of notes: ' + stats["numberOfNotes"] + '</li>' +
'<li>lowest note: ' + stats["lowestNote"][0] + " , " + lowHertz.toFixed(0) + 'Hz</li>' +
'<li>highest note: ' + stats["highestNote"][0] + " , " + highHertz.toFixed(0) + 'Hz</li>' +
'<li>rests used: ' + stats["rests"] + '</li>' +
'<li>ornaments used: ' + stats["ornaments"] + '</li>'
"<li>duples: " +
stats["duples"] +
"</li>" +
"<li>triplets: " +
stats["triplets"] +
"</li>" +
"<li>quintuplets: " +
stats["quintuplets"] +
"</li>" +
"<li>pitch names: " +
Array.from(stats["pitchNames"]) +
"</li>" +
"<li>number of notes: " +
stats["numberOfNotes"] +
"</li>" +
"<li>lowest note: " +
stats["lowestNote"][0] +
" , " +
lowHertz.toFixed(0) +
"Hz</li>" +
"<li>highest note: " +
stats["highestNote"][0] +
" , " +
highHertz.toFixed(0) +
"Hz</li>" +
"<li>rests used: " +
stats["rests"] +
"</li>" +
"<li>ornaments used: " +
stats["ornaments"] +
"</li>";
}
}