From fa173d1f19a24df93e4581413ad497d7af240779 Mon Sep 17 00:00:00 2001 From: dario-cfpt Date: Tue, 4 Feb 2020 08:45:43 +0100 Subject: [PATCH] Add classes for the stat page Also removed the pie chart graph because it wasn't really useful. --- mobile/www/index.html | 1 + mobile/www/js/comparator.js | 20 +++------- mobile/www/js/feclass.js | 14 +++++++ mobile/www/js/graph.js | 35 ------------------ mobile/www/js/routes.js | 25 ++++++------- mobile/www/js/stats.js | 63 +++++++++++++++----------------- mobile/www/pages/comparator.html | 4 +- mobile/www/pages/stat.html | 13 ++++--- 8 files changed, 73 insertions(+), 102 deletions(-) create mode 100644 mobile/www/js/feclass.js diff --git a/mobile/www/index.html b/mobile/www/index.html index 0049461..05cb31d 100644 --- a/mobile/www/index.html +++ b/mobile/www/index.html @@ -90,6 +90,7 @@ + diff --git a/mobile/www/js/comparator.js b/mobile/www/js/comparator.js index 17acc86..be41e50 100644 --- a/mobile/www/js/comparator.js +++ b/mobile/www/js/comparator.js @@ -49,18 +49,7 @@ function displayComparedCharacters() { $$("#table-comparator-content").empty(); selectedCharacters.forEach(char => { - // Get all available classes for the character - const availableClasses = []; - - feData.classes.forEach(feClass => { - if (feClass.isAvailableForAll && (feClass.idGender == ID_GENDER_NON_RESTRICTED || feClass.idGender == char.idGender)) { - availableClasses.push(feClass); - } else { - if (feData.restrictedClasses.find(x => x.idClass == feClass.id && x.idCharacter == char.id)) { - availableClasses.push(feClass); - } - } - }); + const availableClasses = getAvailableClassesForCharacter(char); // Create the select of available classes const selectContainer = $$("
"); @@ -166,8 +155,11 @@ function computeCharacterGrowthRatesWithClass(char) { return charData; } -function switchGraph(event) { +/** + * Change the style of the buttons used to choose the graph displayed and call the method to display the graph + */ +function switchGraph(event, callback) { $$("." + BUTTON_ACTIVE_CLASS_NAME).removeClass(BUTTON_ACTIVE_CLASS_NAME); $$(event.target).addClass(BUTTON_ACTIVE_CLASS_NAME); - displayCurrentGraph(); + callback(); } diff --git a/mobile/www/js/feclass.js b/mobile/www/js/feclass.js new file mode 100644 index 0000000..52c84d8 --- /dev/null +++ b/mobile/www/js/feclass.js @@ -0,0 +1,14 @@ +function getAvailableClassesForCharacter(char) { + const availableClasses = []; + + feData.classes.forEach(feClass => { + if (feClass.isAvailableForAll && (feClass.idGender == ID_GENDER_NON_RESTRICTED || feClass.idGender == char.idGender)) { + availableClasses.push(feClass); + } else { + if (feData.restrictedClasses.find(x => x.idClass == feClass.id && x.idCharacter == char.id)) { + availableClasses.push(feClass); + } + } + }); + return availableClasses +} \ No newline at end of file diff --git a/mobile/www/js/graph.js b/mobile/www/js/graph.js index f81a0b1..bca39e9 100644 --- a/mobile/www/js/graph.js +++ b/mobile/www/js/graph.js @@ -81,39 +81,4 @@ function displayPolarSpider(containerId, categories, series) { }] } }); -} - -function displayPieChart(data) { - Highcharts.chart('container-char-gr', { - chart: { - plotBackgroundColor: null, - plotBorderWidth: null, - plotShadow: false, - type: 'pie' - }, - title: { - text: '' - }, - tooltip: { - pointFormat: '{series.name}: {point.y}%' - }, - credits: { - enabled: false - }, - plotOptions: { - pie: { - allowPointSelect: true, - cursor: 'pointer', - dataLabels: { - enabled: true, - format: '{point.name}: {point.y}%' - }, - } - }, - series: [{ - name: 'Growth Rates', - colorByPoint: true, - data: data, - }] - }); } \ No newline at end of file diff --git a/mobile/www/js/routes.js b/mobile/www/js/routes.js index 59b5da9..602ca26 100644 --- a/mobile/www/js/routes.js +++ b/mobile/www/js/routes.js @@ -28,12 +28,10 @@ routes = [ $$("#picture-char").attr("src", "img/characters/" + char.firstName + ".png"); actualCharId = charId; createTableOfStats(); + createListOfAvailableClasses() displayTableOfGrowthRates(); - - $$("#select-graph").on("change", () => { - displayGraphOfGrowthRates(); - }); } + createEventForGraphSwitch(displayGraphOfGrowthRates); } } }, @@ -42,14 +40,7 @@ routes = [ path: '/comparator/', templateUrl: './pages/comparator.html', on: { - pageInit: (e, page) => { - $$("#btn-graph-column-chart").on("click", (event) => { - switchGraph(event); - }); - $$("#btn-graph-spider-web").on("click", (event) => { - switchGraph(event); - }); - }, + pageInit: (e, page) => createEventForGraphSwitch(displayCurrentGraph), // We must use the pageAfterIn event in order to open the smartselect directly pageAfterIn: (e, page) => { configureSmartSelectOfCharacters(); @@ -67,4 +58,12 @@ routes = [ templateUrl: './pages/about.html' }, ]; - \ No newline at end of file + +function createEventForGraphSwitch(callback) { + $$("#btn-graph-column-chart").on("click", (event) => { + switchGraph(event, callback); + }); + $$("#btn-graph-spider-web").on("click", (event) => { + switchGraph(event, callback); + }); +} \ No newline at end of file diff --git a/mobile/www/js/stats.js b/mobile/www/js/stats.js index 22a3111..36e139e 100644 --- a/mobile/www/js/stats.js +++ b/mobile/www/js/stats.js @@ -3,9 +3,6 @@ File name : stats.js Description : Display the stats of a character and/or class with various graphs */ -const GRAPH_PIE_CHART_VALUE = "pie-chart"; -const GRAPH_SPIDER_WEB_VALUE = "spider-web"; -const GRAPH_COLUMN_CHART_VALUE = "column-chart"; const GRAPH_CONTAINER_GR_ID = "container-char-gr"; let actualCharId; @@ -29,21 +26,37 @@ function displayTableOfGrowthRates() { displayGraphOfGrowthRates(); } -function displayGraphOfGrowthRates() { - const selectedGraph = $$("#select-graph").val(); +function createListOfAvailableClasses() { + const char = feData.characters.find(x => x.id == actualCharId); + // Get all available classes for the character + const availableClasses = getAvailableClassesForCharacter(char); - switch (selectedGraph) { - case GRAPH_SPIDER_WEB_VALUE: - displayPolarSpiderOfGrowthRates(actualCharId); - break; - case GRAPH_PIE_CHART_VALUE: - displayPieChartOfGrowthRates(actualCharId); - break; - case GRAPH_COLUMN_CHART_VALUE: - default: - displayColumnChartOfGrowthRates(actualCharId); - // Column chart graph by default - break; + // Create the select of available classes + const select = $$("#select-classes"); + const defaultOption = $$(""); + select.append(defaultOption); + + availableClasses.forEach(feClass => { + const option = $$("