@ -1,6 +1,31 @@
let combined _charts = [ ] ;
let player _charts = [ ] ;
const x _scale = {
display : true ,
type : "timeseries" ,
time : {
parser : "dd.MM.yy HH:mm" ,
tooltipFormat : "dd.MM.yy HH:mm" ,
unit : "day" ,
unitStepSize : 1 ,
displayFormats : {
"day" : "dd.MM.yy" ,
}
} ,
ticks : {
callback : ( value , index , ticks ) => {
let tickdate = new Date ( value ) ;
if ( index === 0 ) return ` ${ tickdate . getDate ( ) } . ${ tickdate . getMonth ( ) + 1 } . ` ;
let prev _tickdate = new Date ( ticks [ index - 1 ] . value ) ;
if ( prev _tickdate . getDate ( ) === tickdate . getDate ( ) ) {
return null ;
}
return ` ${ tickdate . getDate ( ) } . ${ tickdate . getMonth ( ) + 1 } . ` ;
}
}
}
window . onload = create _charts ;
async function create _charts ( ) {
@ -8,11 +33,10 @@ async function create_charts() {
combined _charts = [ ] ;
player _charts . forEach ( chart => chart . destroy ( ) ) ;
player _charts = [ ] ;
let all _dates = [ ] ; // Alle Daten für die für min. einen Spieler ein Rang gespeichert ist
let all _rank _yDatasets = [ ] ; // Datasets, also die einzelnen Linien im Graphen, beinhaltet player_points
let all _progress _yDatasets = [ ] ; // Datasets, also die einzelnen Linien im Graphen, beinhaltet die Differenz der aktuellen player_points und der start player_points
let player _points = { } ; // puuid zeigt auf eine Liste von Punkten, welche die y-Koordinaten im Graphen darstellen
let player _pointprogress = { } ; // puuid zeigt auf eine Liste von Punkten, welche die y-Koordinaten im Graphen darstellen
let player _rank _values = { } ;
let player _progress _values = { } ;
let player _entries = { } ; // puuid zeigt auf player entries
let player _entries _byName = { } ; // playername zeigt auf entries (damit im kombinierten Graphen die Tooltips korrekt gerendert werden können)
let player _accounts = { } ; // puuid zeigt auf player account
@ -24,39 +48,28 @@ async function create_charts() {
. then ( result => {
player _entries = result [ "entries" ] ;
player _accounts = result [ "accounts" ] ;
for ( const puuid in player _entries ) {
// Alle Daten für die Spieler Einträge haben sollen in all_dates
for ( const entry _date in player _entries [ puuid ] ) {
all _dates . push ( entry _date )
}
// Hier schonmal puuids/namen auf leere Arrays setzen, damit später einfach .push verwendet werden kann
player _points [ puuid ] = [ ] ;
player _pointprogress [ puuid ] = [ ] ;
player _entries _byName [ ` ${ player _accounts [ puuid ] [ "gameName" ] } # ${ player _accounts [ puuid ] [ "tagLine" ] } ` ] = [ ] ;
}
// Daten sortieren und Duplicates entfernen
all _dates . sort ( ) ;
all _dates = [ ... new Set ( all _dates ) ] ;
let all _rank _yDatasets = [ ] ; // Datasets, also die einzelnen Linien im Graphen, beinhaltet player_rank_values
let all _progress _yDatasets = [ ] ; // Datasets, also die einzelnen Linien im Graphen, beinhaltet player_progress_values
let color _counter = 0 ;
for ( const puuid in player _entries ) {
player _rank _values [ puuid ] = [ ] ;
player _progress _values [ puuid ] = [ ] ;
player _entries _byName [ ` ${ player _accounts [ puuid ] [ "gameName" ] } # ${ player _accounts [ puuid ] [ "tagLine" ] } ` ] = [ ] ;
let player _start _points = - 1 ;
for ( const date _string of all _dates ) {
// Für alle Player Entries Punktzahl berechnen und in player_points eintragen
for ( const timestamp in player _entries [ puuid ] ) {
// Für alle Player Entries Punktzahl und Punktedifferenz berechnen
// Bei der Gelegenheit auch Entries in player_entries_byName eintragen
if ( date _string in player _entries [ puuid ] ) {
const current _points = rank _to _points ( player _entries [ puuid ] [ date _string ] [ "tier" ] , player _entries [ puuid ] [ date _string ] [ "rank" ] , player _entries [ puuid ] [ date _string ] [ "points" ] ) ;
player _points [ puuid ] . push ( current _points ) ;
player _entries _byName [ ` ${ player _accounts [ puuid ] [ "gameName" ] } # ${ player _accounts [ puuid ] [ "tagLine" ] } ` ] [ date _string ] = player _entries [ puuid ] [ date _string ] ;
const current _points = rank _to _points ( player _entries [ puuid ] [ timestamp ] [ "tier" ] , player _entries [ puuid ] [ timestamp ] [ "rank" ] , player _entries [ puuid ] [ timestamp ] [ "points" ] ) ;
player _rank _values [ puuid ] . push ( { x : parseInt ( timestamp ) * 1000 , y : current _points } ) ;
player _entries _byName [ ` ${ player _accounts [ puuid ] [ "gameName" ] } # ${ player _accounts [ puuid ] [ "tagLine" ] } ` ] [ timestamp ] = player _entries [ puuid ] [ timestamp ] ;
if ( player _start _points === - 1 ) {
player _start _points = current _points ;
player _pointprogress [ puuid ] . push ( 0 ) ;
} else {
player _pointprogress [ puuid ] . push ( current _points - player _start _points ) ;
}
player _progress _values [ puuid ] . push ( { x : parseInt ( timestamp ) * 1000 , y : 0 } ) ;
} else {
player _points [ puuid ] . push ( null ) ;
player _pointprogress [ puuid ] . push ( null ) ;
player _progress _values [ puuid ] . push ( { x : parseInt ( timestamp ) * 1000 , y : current _points - player _start _points } ) ;
}
}
// Linie für den Spieler zu Datasets des Graphen hinzufügen
@ -65,7 +78,7 @@ async function create_charts() {
fill : false ,
borderColor : getColor ( color _counter ) ,
backgroundColor : getColor ( color _counter ) ,
data : player _point s [ puuid ] ,
data : player _rank _value s [ puuid ] ,
spanGaps : true ,
} )
all _progress _yDatasets . push ( {
@ -73,7 +86,7 @@ async function create_charts() {
fill : false ,
borderColor : getColor ( color _counter ) ,
backgroundColor : getColor ( color _counter ) ,
data : player _pointp rogress [ puuid ] ,
data : player _progress _value s [ puuid ] ,
spanGaps : true ,
} )
color _counter ++ ;
@ -82,7 +95,6 @@ async function create_charts() {
combined _charts . push ( new Chart ( ` progress-chart-combined ` , {
type : "line" ,
data : {
labels : all _dates ,
datasets : all _rank _yDatasets ,
} ,
options : {
@ -90,7 +102,7 @@ async function create_charts() {
tooltip : {
callbacks : {
label : function ( context ) {
return format _rank ( player _entries _byName [ context . dataset . label ] [ context . label ] [ "tier" ] , player _entries _byName [ context . dataset . label ] [ context . label ] [ "rank" ] , player _entries _byName [ context . dataset . label ] [ context . label ] [ "points" ] )
return format _rank ( player _entries _byName [ context . dataset . label ] [ context . parsed . x / 1000 ] [ "tier" ] , player _entries _byName [ context . dataset . label ] [ context . parsed . x / 1000 ] [ "rank" ] , player _entries _byName [ context . dataset . label ] [ context . parsed . x / 1000 ] [ "points" ] )
} ,
beforeTitle : function ( context ) {
return context [ 0 ] . dataset . label ;
@ -99,6 +111,7 @@ async function create_charts() {
}
} ,
scales : {
x : x _scale ,
y : {
display : true ,
stepSize : 100 ,
@ -116,7 +129,6 @@ async function create_charts() {
combined _charts . push ( new Chart ( ` progress-chart-combined-progress ` , {
type : "line" ,
data : {
labels : all _dates ,
datasets : all _progress _yDatasets ,
} ,
options : {
@ -124,7 +136,7 @@ async function create_charts() {
tooltip : {
callbacks : {
label : function ( context ) {
return format _rank ( player _entries _byName [ context . dataset . label ] [ context . label ] [ "tier" ] , player _entries _byName [ context . dataset . label ] [ context . label ] [ "rank" ] , player _entries _byName [ context . dataset . label ] [ context . label ] [ "points" ] )
return format _rank ( player _entries _byName [ context . dataset . label ] [ context . parsed . x / 1000 ] [ "tier" ] , player _entries _byName [ context . dataset . label ] [ context . parsed . x / 1000 ] [ "rank" ] , player _entries _byName [ context . dataset . label ] [ context . parsed . x / 1000 ] [ "points" ] )
} ,
beforeTitle : function ( context ) {
return context [ 0 ] . dataset . label ;
@ -133,6 +145,7 @@ async function create_charts() {
}
} ,
scales : {
x : x _scale ,
y : {
display : true ,
} ,
@ -149,23 +162,20 @@ async function create_charts() {
let puuid = chart . id . split ( "-" ) ;
puuid . splice ( 0 , 2 ) ;
puuid = puuid . join ( "-" ) ;
let xValues = [ ] ;
let yValues = [ ] ;
let values = [ ] ;
for ( const entriesKey in player _entries [ puuid ] ) {
let points = rank _to _points ( player _entries [ puuid ] [ entriesKey ] [ "tier" ] , player _entries [ puuid ] [ entriesKey ] [ "rank" ] , player _entries [ puuid ] [ entriesKey ] [ "points" ] ) ;
xValues . push ( entriesKey ) ;
yValues . push ( points ) ;
values . push ( { x : parseInt ( entriesKey ) * 1000 , y : points } ) ;
}
player _charts . push ( new Chart ( ` progress-chart- ${ puuid } ` , {
type : "line" ,
data : {
labels : xValues ,
datasets : [ {
label : ` ${ player _accounts [ puuid ] [ "gameName" ] } # ${ player _accounts [ puuid ] [ "tagLine" ] } ` ,
fill : false ,
borderColor : "rgba(150,150,175)" ,
backgroundColor : "rgba(150,150,175)" ,
data : yV alues
data : v alues
} ]
} ,
options : {
@ -174,7 +184,7 @@ async function create_charts() {
tooltip : {
callbacks : {
label : function ( context ) {
return format _rank ( player _entries [ puuid ] [ context . label ] [ "tier" ] , player _entries [ puuid ] [ context . label ] [ "rank" ] , player _entries [ puuid ] [ context . label ] [ "points" ] )
return format _rank ( player _entries [ puuid ] [ context . parsed . x / 1000 ] [ "tier" ] , player _entries [ puuid ] [ context . parsed . x / 1000 ] [ "rank" ] , player _entries [ puuid ] [ context . parsed . x / 1000 ] [ "points" ] )
} ,
beforeTitle : function ( context ) {
return context [ 0 ] . dataset . label ;
@ -183,6 +193,7 @@ async function create_charts() {
}
} ,
scales : {
x : x _scale ,
y : {
display : true ,
stepSize : 100 ,