SkullCoder

Untitled

Jul 4th, 2019
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Chart MissionControl
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       You
  7. // @match        https://missioncontrol.pseuco.com/
  8. // @grant        none
  9. // @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js
  10. // @require      http://code.jquery.com/jquery-3.3.1.min.js
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.     'use strict';
  15.  
  16.     var canv = document.createElement('canvas');
  17.     canv.id = 'canvas';
  18.  
  19.  
  20.     var checkbox=$(document.createElement('input')).attr({
  21.         id:    'myCheckbox'
  22.         ,name:  'myCheckbox'
  23.         ,value: 'myValue'
  24.         ,type:  'checkbox'
  25.     });
  26.  
  27.     var center=$(document.createElement('center'));
  28.     $(center).append(checkbox, "Logarithmic");
  29.  
  30.     $('body').append(
  31.         center//"<center>", checkbox, "Logarithmic", "</center>"
  32.     );
  33.  
  34.     document.body.appendChild(canv);
  35.  
  36.     window.chartColors = {
  37.         red: 'rgb(255, 99, 132)',
  38.         orange: 'rgb(255, 159, 64)',
  39.         yellow: 'rgb(255, 205, 86)',
  40.         green: 'rgb(75, 192, 192)',
  41.         blue: 'rgb(54, 162, 235)',
  42.         purple: 'rgb(153, 102, 255)',
  43.         grey: 'rgb(201, 203, 207)'
  44.     };
  45.  
  46.     var labels = [];
  47.     var points = [];
  48.     var labels2 = [];
  49.     var points2 = [];
  50.  
  51.     $("tbody tr").each(function( index ) {
  52.         var text=[];
  53.         $(this).children("td").each(function(index2) {
  54.             //console.log($(this).text());
  55.             text.push($(this).text());
  56.         });
  57.         labels.push(text[1]);
  58.         if(text[4]>0){
  59.         points.push(text[4]);
  60.         }else{
  61.         points.push(text[4]);
  62.         }
  63.         //console.log(text);
  64.         //console.log( index + ": " + $( this ).text() );
  65.     });
  66.  
  67.     //points.reverse();
  68.     //labels.reverse();
  69.     console.log(points);
  70.  
  71.         //var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
  72.         var color = Chart.helpers.color;
  73.         var barChartData = {
  74.             labels: labels, //['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  75.             datasets: [{
  76.                 label: 'Punkte',
  77.                 backgroundColor: color(window.chartColors.red).alpha(0.5).rgbString(),
  78.                 borderColor: window.chartColors.blue,
  79.                 borderWidth: 1,
  80.                 data: points
  81.             }/*,{
  82.                 //label: 'Punkte',
  83.                 backgroundColor: color(window.chartColors.blue).alpha(0.5).rgbString(),
  84.                 borderColor: window.chartColors.blue,
  85.                 borderWidth: 1,
  86.                 data: points2
  87.             }, {
  88.                 label: 'Dataset 2',
  89.                 backgroundColor: color(window.chartColors.blue).alpha(0.5).rgbString(),
  90.                 borderColor: window.chartColors.blue,
  91.                 borderWidth: 1,
  92.                 data: [
  93.                     randomScalingFactor(),
  94.                     randomScalingFactor(),
  95.                     randomScalingFactor(),
  96.                     randomScalingFactor(),
  97.                     randomScalingFactor(),
  98.                     randomScalingFactor(),
  99.                     randomScalingFactor()
  100.                 ]
  101.             }*/]
  102.  
  103.         };
  104.  
  105.         window.onload = function() {
  106.             var ctx = document.getElementById('canvas').getContext('2d');
  107.             var chart = new Chart(ctx, {
  108.                 type: 'bar',
  109.                 data: barChartData,
  110.                 options: {
  111.                     responsive: true,
  112.                     legend: {
  113.                         position: 'top',
  114.                     },
  115.                     title: {
  116.                         display: true,
  117.                         text: 'Chart.js Bar Chart'
  118.                     }
  119.                 }
  120.             });
  121.  
  122.             var xScale = chart.scales['x-axis-0'];
  123.             var yScale = chart.scales['y-axis-0'];
  124.             chart.options.scales = {
  125.                 xAxes: [{
  126.                     id: 'newId',
  127.                     display: true
  128.                 }],
  129.                 yAxes: [{
  130.                     display: true,
  131.                     ticks: {
  132.                         suggestedMax: 150,
  133.                         suggestedMin: -150,
  134.                         min: -150
  135.                     },
  136.                     type: 'linear'
  137.                 }]
  138.             };
  139.  
  140.             chart.update();
  141.  
  142.             checkbox.on("change",function(){
  143.                 //console.log($(this).is(':checked'));
  144.                 if($(this).is(':checked')){
  145.             chart.options.scales = {
  146.                 xAxes: [{
  147.                     id: 'newId',
  148.                     display: true
  149.                 }],
  150.                 yAxes: [{
  151.                     display: true,
  152.                     ticks: {
  153.                         suggestedMax: 150,
  154.                         suggestedMin: -150,
  155.                         min: -150
  156.                     },
  157.                     type: 'logarithmic'
  158.                 }]
  159.             };
  160.  
  161.             chart.update();
  162.                 }else{
  163.             chart.options.scales = {
  164.                 xAxes: [{
  165.                     id: 'newId',
  166.                     display: true
  167.                 }],
  168.                 yAxes: [{
  169.                     display: true,
  170.                     ticks: {
  171.                         suggestedMax: 150,
  172.                         suggestedMin: -150,
  173.                         min: -150
  174.                     },
  175.                     type: 'linear'
  176.                 }]
  177.             };
  178.  
  179.             chart.update();
  180.                 }
  181.             });
  182.  
  183.         };
  184.  
  185.     /*
  186.     $(function() {
  187.  
  188. //        var headers = $("span",$("#tblVersions")).map(function() {
  189. //            return this.innerHTML;
  190. //        }).get();
  191.  
  192.         var rows = $("tbody tr",$("#tblVersions")).map(function() {
  193.             return [$("td:eq(0) input:checkbox:checked",this).map(function() {
  194.                 return this.innerHTML;
  195.             }).get()];
  196.         }).get();
  197.  
  198.         console.log(rows);
  199.     });
  200.     */
  201. })();
Advertisement
Add Comment
Please, Sign In to add comment