/** * System graph module */ define([ 'jquery', 'app/init', 'app/util', 'morris' ], function($, Init, Util, Morris) { 'use strict'; var config = { // module info moduleClass: 'pf-module', // class for each module // system graph module systemGraphModuleClass: 'pf-system-graph-module', // class for this module systemGraphClass: 'pf-system-graph', // class for each graph // system graph labels systemGraphLabels: { jumps: { headline: 'Jumps', units: 'jumps', ykeys: ['y'], labels: ['jumps'], lineColors: ['#375959'], pointFillColors: ['#477372'] }, shipKills: { headline: 'Ship/POD Kills', units: 'kills', ykeys: ['y', 'z'], labels: ['Ship kills', 'POD kills'], lineColors: ['#375959', '#477372'], pointFillColors: ['#477372', '#568a89'] }, factionKills: { headline: 'NPC Kills', units: 'kills', ykeys: ['y'], labels: ['kills'], lineColors: ['#375959'], pointFillColors: ['#477372'] } } }; /** * get info for a given graph key * @param graphKey * @param option * @returns {string} */ var getInfoForGraph = function(graphKey, option){ var info = ''; if(config.systemGraphLabels.hasOwnProperty(graphKey)){ info = config.systemGraphLabels[graphKey][option]; } return info; }; /** * init Morris Graph * @param graphElement * @param graphKey * @param graphData */ var initGraph = function(graphElement, graphKey, graphData, eventLine){ if(graphData.length > 0){ var labelYFormat = function(y){ return Math.round(y); }; var graphConfig = { element: graphElement, data: graphData, xkey: 'x', ykeys: getInfoForGraph(graphKey, 'ykeys'), labels: getInfoForGraph(graphKey, 'labels'), parseTime: false, ymin: 0, yLabelFormat: labelYFormat, padding: 10, hideHover: true, pointSize: 3, lineColors: getInfoForGraph(graphKey, 'lineColors'), pointFillColors: getInfoForGraph(graphKey, 'pointFillColors'), pointStrokeColors: ['#141413'], lineWidth: 2, grid: true, gridStrokeWidth: 0.3, gridTextSize: 9, gridTextFamily: 'Oxygen Bold', gridTextColor: '#63676a', behaveLikeLine: false, goals: [], goalLineColors: ['#5cb85c'], smooth: true, fillOpacity: 0.2, resize: true, redraw: true, eventStrokeWidth: 2, eventLineColors: ['#5CB85C'] }; if(eventLine >= 0){ graphConfig.events = [eventLine]; } Morris.Area(graphConfig); } }; /** * draw graph module * @param parentElement * @param systemData */ var drawModule = function(parentElement, systemData){ // graph data is available for k-space systems if(systemData.type.id === 2){ var requestData = { systemIds: [systemData.systemId] }; // calculate time offset until system created var serverData = Util.getServerTime(); var timestampNow = Math.floor(serverData.getTime() / 1000); var timeSinceUpdate = timestampNow - systemData.updated; var timeInHours = Math.floor(timeSinceUpdate / 3600); var timeInMinutes = Math.floor((timeSinceUpdate % 3600) / 60); var timeInMinutesPercent = ( timeInMinutes / 60 ).toFixed(2); var eventLine = timeInHours + timeInMinutesPercent; // graph is from right to left -> convert event line eventLine = 23 - eventLine; $.ajax({ type: 'POST', url: Init.path.getSystemGraphData, data: requestData, dataType: 'json' }).done(function(systemGraphsData){ // create new (hidden) module container var moduleElement = $('