/*
Meteograms using Wxsim-forecast anh Highcharts javascript-package (highcharts.com)
V. 1.1, April 2010
Made by Henkka, nordicweather.net
*/

// LOOP FOR GETTING FREEZING POINT
    var below = false;
    for (var i = 0; i < tempdata.length; i++) {
    var value = tempdata[i],
        color = wxsimconf.tempcolor;
    if (value < changecolor && wxsimconf.showfreezingline) {
        color = wxsimconf.freezinglinecolor;
        var below = true;
    }
    tempdata[i] = {
        y: value,
        color: color
    }    
    }
// THE GRAPHS
var wxsim = {
/*
*************
* METEOGRAM *
*************
*/
'meteogram': 
{
options:
    {
chart: {
        renderTo: 'meteogram',
        plotBackgroundColor: wxsimconf.bgcolor,
        margin: [15, 120, 70, 60]
       },
title: {text: '' },
subtitle: { text: '' },
//Axe des X
xAxis:    {
    type: 'datetime',
    labels: {align: 'center', x:50, y: -4,
            formatter: function()
            {
            if(wxsimconf.showdaynames)
            {
            var dz= new Date( );
            dz.setTime(this.value);
            var dayname = wxsimconf.days[dz.getUTCDay()]+' '+Highcharts.dateFormat('%e', this.value)+' ';
            }
            else
            {
            var dayname = Highcharts.dateFormat('%e. %b', this.value)
            }
            return dayname;
            }
            },
    title:  {
        text: ''
            },
            minPadding: -0.06,
            maxPadding: -0.06,
            gridLineWidth: 0,
            tickColor: wxsimconf.gridcolor,
            lineColor: wxsimconf.gridcolor,
            gridLineColor: wxsimconf.gridcolor,
            alternateGridColor: wxsimconf.altnernatebgcolor,
            opposite: true
        },

// Left axis
yAxis:  [
        {
        labels: {formatter: function() {return this.value;},
        style: { color: wxsimconf.tempcoloraxis}
                },
        title: {
        //text: wxsimconf.tempname+' ('+tempunit+')',
        text: '',
                style: { color: wxsimconf.tempcoloraxis,font: wxsimconf.yaxistitlefont, fontWeight: 'normal' },
        margin: 5, //avant ancienne version highcharts.js : 40
        rotation: 270
                },
        opposite: false,
        lineWidth: 1,
        tickColor: wxsimconf.gridcolor,
        lineColor: wxsimconf.gridcolor,
        gridLineColor: wxsimconf.gridcolor,
        tickWidth: 1,

        plotLines: [{
        enabled: below,
        value: changecolor,
        width: 2,
        color: wxsimconf.freezinglinecolor
                    }]
        },

// Right 1 axis
        {
        labels: {formatter: function() {return this.value;},
        style: { color: wxsimconf.preccolor}
                },
         title: {
         //text: wxsimconf.precname+' ('+precunit+')',
         text: '',
         style: { color: wxsimconf.preccolor,font: wxsimconf.yaxistitlefont, fontWeight: 'normal' },
         margin: 12,//avant 35 //avant ancienne version highcharts.js : 20
         rotation: 270
                },
         opposite: true,
        offset: 0, //avant ancienne version highcharts.js : 60
         lineWidth: 1,
         tickColor: wxsimconf.gridcolor,
         lineColor: wxsimconf.gridcolor,
         gridLineColor: wxsimconf.gridcolor,
         tickWidth: 1
         },
// Right 2 axis
        {
        labels: {formatter: function() {return this.value;},
        style: { color: wxsimconf.barocolor}
                },
        title: {
        //text: wxsimconf.baroname+' ('+barounit+')',
        text: '',
style: { color: wxsimconf.barocolor,font: wxsimconf.yaxistitlefont, fontWeight: 'normal' },
        margin: 15,//avant 40 //avant ancienne version highcharts.js : 50
        rotation: 270
               },
        opposite: true,
        offset: 50, //avant ancienne version highcharts.js : 60
        lineWidth: 1,
        tickColor: wxsimconf.gridcolor,
        lineColor: wxsimconf.gridcolor,
        gridLineColor: wxsimconf.gridcolor,
        tickWidth: 1
        }
        ],

tooltip: {
    formatter: function() {
    var unit = tempunit;
    if(this.series.name == wxsimconf.baroname) { var unit = ' '+barounit; }
    if(this.series.name == wxsimconf.precname) { var unit = ' '+precunit; }
    if(wxsimconf.showdaynames) {
    var dz= new Date( );
    dz.setTime(this.x);
    var dayname = wxsimconf.days[dz.getUTCDay()];
    } else {
    var dayname = Highcharts.dateFormat('%e. %b', this.x)
    }
    return '<b>'+ this.series.name +'</b><br/>'+dayname+', '+
    Highcharts.dateFormat('%H:%M', this.x) +': '+ this.y + unit;
    }
         },
legend: {
        style: {
        bottom: '-12px',//avant ancienne version highcharts.js : -2px
        left: '95px'
               }
        },
credits:{enabled:false},
plotOptions: {
    spline: {
        marker: {enabled: false},
        states: {
        hover:  {
        marker: {
        enabled: true,
        symbol: 'circle',
        radius: 2,
        lineWidth: 1
                }
                }
                }
            }
            },
series: 
    [
// Temperature
    {
    name: wxsimconf.tempname,
    visible: wxsimconf.showtemp,
    color: wxsimconf.tempcolorline,
    type: 'spline',
    pointInterval: stepsec,
    pointStart: Date.UTC(startyr, startmo, startda, starthr, 0, 0),
    data: tempdata
    },
// Rain
    {
    name: wxsimconf.precname,
    visible: wxsimconf.showprecip,
    color: wxsimconf.precipcolor,
    type: 'column',
    pointPadding: -0.2,
    groupPadding: 0.2,
    yAxis: 1,
    pointInterval: rstep, // 3 hours
    pointStart: Date.UTC(startyr, startmo, startda, starthr, 0, 0),
    data: totprecdata
    },
// Windchill
    {
    name: wxsimconf.chillname,
    visible: wxsimconf.showwchill,
    color: wxsimconf.wchillcolor,
    type: 'spline',
    lineWidth: 1,
    pointInterval: stepsec,
    pointStart: Date.UTC(startyr, startmo, startda, starthr, 0, 0),
    data: chilldata
    },
// Heatindex
    {
    name: wxsimconf.heatname,
    visible: wxsimconf.showheat,
    color: wxsimconf.heatcolor,
    type: 'spline',
    lineWidth: 1,
    pointInterval: stepsec,
    pointStart: Date.UTC(startyr, startmo, startda, starthr, 0, 0),
    data: heatdata
    },
// Pressure
    {
    name: wxsimconf.baroname,
    visible: wxsimconf.showbaro,
    color: wxsimconf.barocolor,
    type: 'spline',
    yAxis: 2,
    pointInterval: stepsec,
    pointStart: Date.UTC(startyr, startmo, startda, starthr, 0, 0),
    data: barodata
    }
    ]
    }
},
/*
**************
* STORMGRAPH *
**************
*/
'stormgraph': {
options:
    {
chart:  {
        renderTo: 'stormgraph',
        plotBackgroundColor: wxsimconf.bgcolor,
        margin: [20, 120, 45, 60]
        },
title: { text: '' },
subtitle: { text: '' },
//Axe des X
xAxis: {
    type: 'datetime',
    labels: {align: 'left', x: 4, y: -8,
            formatter: function()
            {
            if(wxsimconf.showdaynames)
            {
            var dz= new Date( );
            dz.setTime(this.value);
            if(wxsimafdate.showdaynamesall) {
            var dayname = wxsimconf.days[dz.getUTCDay()]+' '+Highcharts.dateFormat('%e', this.value);
            }
            }
            else
            {
            var dayname = Highcharts.dateFormat('%e. %b', this.value)
            }
            return dayname;
            }
            },
    title:  {
      text: ''
            },
            minPadding: -0.00,
            maxPadding: -0.00,
            gridLineWidth: 0,
            tickColor: wxsimconf.gridcolor,
            lineColor: wxsimconf.gridcolor,
            gridLineColor: wxsimconf.gridcolor,
            alternateGridColor: wxsimconf.altnernatebgcolor,
            opposite: true
      },
// Left axis
yAxis:  [
        {
        labels: {formatter: function() {return this.value;},
        style: { color: wxsimconf.strmcolor }
                },
        title: {
        //text: wxsimconf.stormyaxisname,
        text: '',
        style: { color: wxsimconf.strmcolor,font: wxsimconf.yaxistitlefont, fontWeight: 'normal' },
        margin: 5,
        rotation: 270
               },
        min: 0,
        max: strmmax,
        lineWidth: 1,
        tickWidth: 1,
        tickInterval: wxsimconf.strmstep,
        tickColor: wxsimconf.gridcolor,
        lineColor: wxsimconf.gridcolor,
        gridLineColor: wxsimconf.gridcolor,
        plotLines: [{
        enabled: below,
        value: changecolor,
        width: 2
        //color: '#808080'
                    }]
        },
// Right 1 axis
       {
       labels: {formatter: function() {return this.value;},
       style: { color: wxsimconf.licolor }
               },
       title: {
       //text: wxsimconf.liname,
       text: '',
       style: { color: wxsimconf.licolor,font: wxsimconf.yaxistitlefont, fontWeight: 'normal' },
       margin: 12,
       rotation: 270
              },
       opposite: true,
       lineWidth: 1,    
       min: limin,
       max: 0,
       tickWidth: 1,
       tickInterval: wxsimconf.strmstep,
       tickColor: wxsimconf.gridcolor,
       lineColor: wxsimconf.gridcolor,
       gridLineColor: wxsimconf.gridcolor,
       reversed: true
       },
// Right 2 axis
       {
       labels: {formatter: function() {return this.value;},
       style: { color: wxsimconf.dewcolor}
               },
       title: {
       //text: wxsimconf.dewname+' ('+tempunit+')',
       text: '',
			 style: { color: wxsimconf.dewcolor,font: wxsimconf.yaxistitlefont, fontWeight: 'normal' },
       margin: 15,
       rotation: 270
                },
       opposite: true,
       offset: 60,
       lineWidth: 1,
       tickColor: wxsimconf.gridcolor,
       lineColor: wxsimconf.gridcolor,
       gridLineColor: wxsimconf.gridcolor,
       tickWidth: 1
       }
       ],
tooltip: {
    formatter: function() {
    var unit = '';
    if(this.series.name == wxsimconf.dewname) { var unit = tempunit; }
    if(wxsimconf.showdaynames) {
    var dz= new Date( );
    dz.setTime(this.x);
    var dayname = wxsimconf.days[dz.getUTCDay()];
    } else {
    var dayname = Highcharts.dateFormat('%e. %b', this.x)
    }
    return '<b>'+ this.series.name +'</b><br/>'+dayname+', '+
    Highcharts.dateFormat('%H:%M', this.x) +': '+ this.y + unit;
    }
        },
legend: {
    style: {
      bottom: '-2px',
      left: '95px'
           },
    labelFormatter: function()
    {
    if(this.name == wxsimconf.convname) { return this.name+' (0-5)'; }
    if(this.name == wxsimconf.severename) { return this.name+' (0-5)'; }
    if(this.name == wxsimconf.strmname) { return this.name+' (0-5)'; }
    else { return this.name; }
    }
       },
credits:{enabled:false},
plotOptions: {
spline: {
      marker: {enabled: false},
      states: {
        hover: {
          marker: {
          enabled: true,
          symbol: 'circle',
          radius: 2,
          lineWidth: 1
          }
        }
      }
    }
            },
series:
    [
// storm
    {
    name: wxsimconf.strmname,
    visible: wxsimconf.showstrm,
    color: wxsimconf.strmcolor,
    type: 'spline',
    //lineWidth: 1,
    pointInterval: stepsec,
    pointStart: Date.UTC(startyr, startmo, startda, starthr, 0, 0),
    data: strmdata
    },
// convection
    {
    name: wxsimconf.convname,
    visible: wxsimconf.showconv,
    color: wxsimconf.convcolor,
    type: 'spline',
    //lineWidth: 1,
    pointInterval: stepsec,
    pointStart: Date.UTC(startyr, startmo, startda, starthr, 0, 0),
    data: convdata
    },
// severe
    {
    name: wxsimconf.severename,
    visible: wxsimconf.showsevere,
    color: wxsimconf.severecolor,
    type: 'spline',
    //lineWidth: 1,
    pointInterval: stepsec,
    pointStart: Date.UTC(startyr, startmo, startda, starthr, 0, 0),
    data: sevedata
    },
// Lifted
    {
    name: wxsimconf.liname,
    visible: wxsimconf.showli,
    color: wxsimconf.licolor,
    yAxis: 1,
    type: 'spline',
    pointInterval: stepsec,
    pointStart: Date.UTC(startyr, startmo, startda, starthr, 0, 0),
    data: lidata
    },
// dewpoint
    {
    name: wxsimconf.dewname,
    color: wxsimconf.dewcolor,
    visible: wxsimconf.showdew,
    yAxis: 2,
    type: 'spline',
    pointInterval: stepsec,
    pointStart: Date.UTC(startyr, startmo, startda, starthr, 0, 0),
    data: dewdata
    }
    ]
    }
},
/*
**************
* SOLARGRAPH *
**************
*/
'solargraph': {
options:
    {
chart:  {
        renderTo: 'solargraph',
        plotBackgroundColor: wxsimconf.bgcolor,
        margin: [20, 120, 30, 60]
        },
title: { text: '' },
subtitle: { text: '' },
//Axe des X
xAxis: {
    type: 'datetime',
    labels: {align: 'left', x: 4, y: -8,
            formatter: function()
            {
            if(wxsimconf.showdaynames) {
            var dz= new Date( );
            dz.setTime(this.value);
            if(wxsimafdate.showdaynamesall) {
            var dayname = wxsimconf.days[dz.getUTCDay()]+' '+Highcharts.dateFormat('%e', this.value)+' ';
            }
            }
            else
            {
            var dayname = Highcharts.dateFormat('%e. %b', this.value)
            }
            return dayname;
            }
            },
    title: {
      text: ''
           },
           minPadding: -0.00,
           maxPadding: -0.00,
           gridLineWidth: 0,
           tickColor: wxsimconf.gridcolor,
           lineColor: wxsimconf.gridcolor,
           gridLineColor: wxsimconf.gridcolor,
           alternateGridColor: wxsimconf.altnernatebgcolor,
           opposite: true
      },
// Left axis
yAxis:  [
        {
        labels: {formatter: function() {return this.value;},
        style: { color: wxsimconf.solarcolor }
                },
        title: {
        //text: wxsimconf.solarname+' ('+solarunit+')',
        text: '',
        style: { color: wxsimconf.solarcolor,font: wxsimconf.yaxistitlefont, fontWeight: 'normal' },
        margin: 10 //avant ancienne version highcharts.js : 40
               },
        rotation: 270,
        min: 0,
        lineWidth: 1,
        tickWidth: 1,
        tickColor: wxsimconf.gridcolor,
        //tickInterval: wxsimconf.solarstep,
        lineColor: wxsimconf.gridcolor,
        gridLineColor: wxsimconf.gridcolor,
        plotLines: [{
        enabled: below,
        value: changecolor,
        width: 2
        //color: '#808080'
                    }]
        },
// Right 1 axis
       {
       labels: {formatter: function() {return this.value;},
       style: { color: wxsimconf.uvcolor }
               },
      title: {
      //text: wxsimconf.uvname,
      text: '',
      style: { color: wxsimconf.uvcolor,font: wxsimconf.yaxistitlefont, fontWeight: 'normal' },
      margin: 12,
      rotation: 270
             },
      opposite: true,
      lineWidth: 1,
      tickColor: wxsimconf.gridcolor,
      tickInterval: wxsimconf.uvstep,
      lineColor: wxsimconf.gridcolor,
      gridLineColor: wxsimconf.gridcolor,
      min: 0,
      tickWidth: 1
      },
      ],
tooltip: {
    formatter: function() {
    var unit = '';
    if(this.series.name == wxsimconf.solarname) { var unit = ' W/mē;'; }
    if(wxsimconf.showdaynames) {
    var dz= new Date( );
    dz.setTime(this.x);
    var dayname = wxsimconf.days[dz.getUTCDay()];
    } else {
    var dayname = Highcharts.dateFormat('%e. %b', this.x)
    }
    return '<b>'+ this.series.name +'</b><br/>'+dayname+', '+
    Highcharts.dateFormat('%H:%M', this.x) +': '+ this.y + unit;
    }
        },
legend: {
    style: {
    bottom: '-15px',//avant ancienne version highcharts.js : -2px
    left: '95px'
           },
    labelFormatter: function()
    {
    if(this.name == wxsimconf.convname) { return this.name+' (0-5)'; }
    else { return this.name; }
    }
        },
credits:{enabled:false},
plotOptions: {
areaspline: {
      marker: {enabled: false},
      states: {
        hover: {
          marker: {
          enabled: true,
          symbol: 'circle',
          radius: 2,
          lineWidth: 1
          }
        }
      }
      },
area: {
      fillColor: {
            linearGradient: [0, 20, 0, 120],
            stops: uvcls
      },
      marker: {enabled: false},
      states: {
        hover: {
          marker: {
          enabled: true,
          symbol: 'circle',
          radius: 2,
          lineWidth: 1
          }
        }
      }
    }
  },
series:
    [
// Solar
    {
    name: wxsimconf.solarname,
    visible: wxsimconf.showsolar,
    color: wxsimconf.solarcolor,
    type: 'areaspline',
    pointInterval: stepsec,
    pointStart: Date.UTC(startyr, startmo, startda, starthr, 0, 0),
    data: solardata
    },
// UV
    {
    name: wxsimconf.uvname,
    visible: wxsimconf.showuv,
    color: wxsimconf.uvcolor,
    yAxis: 1,
    type: 'area',
    //lineWidth: 1,
    pointInterval: stepsec,
    pointStart: Date.UTC(startyr, startmo, startda, starthr, 0, 0),
    data: uvdata
    }
    ]
    }
}
}

