@@ -750,8 +750,9 @@ async function prepareDrakePixel(blueJson, redJson){
750750
751751async function createGoldGraph ( ) {
752752 incrementTimeline = 0 ;
753+ var lengthTime = timeline . frames . length ;
754+ var positiveDiff = true ;
753755 timeline . frames . forEach ( item => {
754- console . log ( item ) ;
755756 tmp = 0 ;
756757 blueSideId . forEach ( participantId => {
757758 tmp = tmp + item . participantFrames [ participantId ] . totalGold ;
@@ -762,21 +763,42 @@ async function createGoldGraph(){
762763 tmp = tmp + item . participantFrames [ participantId ] . totalGold ;
763764 } )
764765 arrayRedGold [ incrementTimeline ] = tmp ;
765- arrayChartGold [ incrementTimeline ] = arrayBlueGold [ incrementTimeline ] - arrayRedGold [ incrementTimeline ]
766+ arrayChartGold [ incrementTimeline ] = arrayBlueGold [ incrementTimeline ] - arrayRedGold [ incrementTimeline ] ;
767+
768+ // console.log("time:"+incrementTimeline+"|diff:"+arrayChartGold[incrementTimeline]+"|color:"+arrayChartColor[incrementTimeline]);
766769 arrayLabel [ incrementTimeline ] = incrementTimeline . toString ( ) ;
767770 incrementTimeline ++ ;
768771 } ) ;
769772
770773 const cjs = new ChartJs ( 900 , 300 )
771774
772- var gradientFill = cjs . ctx . createLinearGradient ( 0 , 0 , 900 , 350 ) ;
775+ gradientFill = cjs . ctx . createLinearGradient ( 0 , 0 , 900 , 350 ) ;
773776
774- gradientFill . addColorStop ( 0 , 'blue' ) ;
775- gradientFill . addColorStop ( 23 / 32 , 'red' ) ;
776- gradientFill . addColorStop ( 1 , 'blue' )
777+ // console.log(arrayChartColor);
778+ // arrayChartColor.forEach(item=>{
779+ // gradientFill.addColorStop(parseFloat(item.time), item.color);
780+ // });
781+
782+ gradientFill . addColorStop ( 0 , 'red' ) ;
783+ if ( gradSave != null ) {
784+ gradientFill . addColorStop ( parseFloat ( 1 - ( gradSave / 300 ) - 0.000000001 ) , 'red' ) ;
785+ gradientFill . addColorStop ( parseFloat ( 1 - ( gradSave / 300 ) ) , 'blue' ) ;
786+ }
787+
788+ gradientFill . addColorStop ( 1 , 'blue' ) ;
789+ cjs . ctx . fillStyle = gradientFill ;
790+ // cjs.ctx.fillRect(10, 10, 200, 100);
777791
778792 const barConfig = {
779793 type : 'line' ,
794+ plugins : [ {
795+ afterLayout : chart => {
796+ let ctx = chart . chart . ctx ;
797+ let yAxis = chart . scales [ "y-axis-0" ] ;
798+ let yBottom = yAxis . getPixelForValue ( 0 ) ;
799+ gradSave = yBottom ;
800+ }
801+ } ] ,
780802 data : {
781803 labels : arrayLabel ,
782804 datasets : [ {
@@ -847,7 +869,89 @@ async function createGoldGraph(){
847869
848870 await cjs . makeChart ( barConfig )
849871 await cjs . drawChart ( )
850- await cjs . toFile ( path + '/graphs/test.bar.png' )
872+ await cjs . toFile ( path + '/graphs/test.bar2.png' )
873+
874+ const cjs2 = new ChartJs ( 900 , 300 ) ;
875+ gradientFill = cjs2 . ctx . createLinearGradient ( 450 , 0 , 450 , 350 ) ;
876+ gradientFill . addColorStop ( 0 , 'blue' ) ;
877+ console . log ( parseFloat ( ( gradSave / 350 ) ) ) ;
878+ gradientFill . addColorStop ( parseFloat ( ( gradSave / 350 ) - 0.000000001 ) , 'blue' ) ;
879+ gradientFill . addColorStop ( parseFloat ( ( gradSave / 350 ) ) , 'red' ) ;
880+ gradientFill . addColorStop ( 1 , 'red' ) ;
881+ cjs2 . ctx . fillStyle = gradientFill ;
882+ // cjs.ctx.fillRect(10, 10, 200, 100);
883+
884+ const barConfig2 = {
885+ type : 'line' ,
886+ data : {
887+ labels : arrayLabel ,
888+ datasets : [ {
889+ data : arrayChartGold ,
890+ backgroundColor : gradientFill ,
891+ fill :'origin'
892+ // backgroundColor: [
893+ // 'rgba(255, 99, 132, 0.2)',
894+ // 'rgba(54, 162, 235, 0.2)',
895+ // 'rgba(255, 206, 86, 0.2)',
896+ // 'rgba(75, 192, 192, 0.2)',
897+ // 'rgba(153, 102, 255, 0.2)',
898+ // 'rgba(255, 159, 64, 0.2)'
899+ // ],
900+ //backgroundColor: '#e04f31'
901+ } ]
902+ } ,
903+ options : {
904+ title : {
905+ fontSize : 26 ,
906+ fontStyle : 'bold' ,
907+ display : false ,
908+ text : 'Hours Online' ,
909+ // fontColor: '#818E9B',
910+ padding : 40
911+ } ,
912+ layout : {
913+ padding : 20 ,
914+ fontColor : '#FFFFFF'
915+ } ,
916+ legend : {
917+ display : false
918+ } ,
919+ scales : {
920+ yAxes : [ {
921+ ticks : {
922+ beginAtZero : true ,
923+ fontSize : 22 ,
924+ fontStyle : 'bold' ,
925+ padding : 40
926+ } ,
927+ gridLines : {
928+ color : '#F0F1F3' ,
929+ zeroLineColor : '#000000' ,
930+ drawBorder : false ,
931+ tickMarkLength : 20
932+ }
933+ } ] ,
934+ xAxes : [ {
935+ barThickness : 40 ,
936+ ticks : {
937+ fontColor : '#D0D4D8' ,
938+ fontStyle : 'bold' ,
939+ fontSize : 22 ,
940+ display : false
941+ } ,
942+ gridLines : {
943+ drawOnChartArea : false ,
944+ color : '#F0F1F3' ,
945+ zeroLineColor : '#F0F1F3' ,
946+ tickMarkLength : 20
947+ }
948+ } ]
949+ }
950+ }
951+ }
952+ await cjs2 . makeChart ( barConfig2 )
953+ await cjs2 . drawChart ( )
954+ await cjs2 . toFile ( path + '/graphs/test.bar.png' )
851955}
852956
853957async function createDamageGraphRed ( ) {
@@ -1053,6 +1157,7 @@ function retrieveData(){
10531157}
10541158
10551159function resetData ( ) {
1160+ gradSave = null ;
10561161 game = null ;
10571162 timeline = null ;
10581163 tab_runes = [ ] ;
@@ -1070,6 +1175,7 @@ function resetData(){
10701175 arrayBlueGold = [ ] ;
10711176 arrayRedGold = [ ] ;
10721177 arrayChartGold = [ ] ;
1178+ arrayChartColor = [ ] ;
10731179 arrayLabel = [ ] ;
10741180 arrayDamageBlue = [ ] ;
10751181 arrayDamageRed = [ ] ;
0 commit comments