 
(function(){



var series = [{"name":"2017 OCT", "y": 155.3 },{"name":"2017 NOV", "y": 155.1 },{"name":"2017 DEC", "y": 153.5 },{"name":"2018 JAN", "y": 154.1 },{"name":"2018 FEB", "y": 153.0 },{"name":"2018 MAR", "y": 152.6 },{"name":"2018 APR", "y": 152.0 },{"name":"2018 MAY", "y": 157.3 },{"name":"2018 JUN", "y": 158.8 },{"name":"2018 JUL", "y": 153.3 },{"name":"2018 AUG", "y": 156.1 },{"name":"2018 SEP", "y": 154.6 },{"name":"2018 OCT", "y": 154.7 },{"name":"2018 NOV", "y": 155.0 },{"name":"2018 DEC", "y": 155.7 },{"name":"2019 JAN", "y": 154.4 },{"name":"2019 FEB", "y": 155.3 },{"name":"2019 MAR", "y": 155.7 },{"name":"2019 APR", "y": 156.0 },{"name":"2019 MAY", "y": 157.2 },{"name":"2019 JUN", "y": 157.7 },{"name":"2019 JUL", "y": 158.4 },{"name":"2019 AUG", "y": 159.3 },{"name":"2019 SEP", "y": 159.7 },{"name":"2019 OCT", "y": 158.9 },{"name":"2019 NOV", "y": 158.3 },{"name":"2019 DEC", "y": 157.3 },{"name":"2020 JAN", "y": 157.2 },{"name":"2020 FEB", "y": 161.5 },{"name":"2020 MAR", "y": 165.0 },{"name":"2020 APR", "y": 164.7 },{"name":"2020 MAY", "y": 165.3 },{"name":"2020 JUN", "y": 164.6 },{"name":"2020 JUL", "y": 162.4 },{"name":"2020 AUG", "y": 160.3 },{"name":"2020 SEP", "y": 161.0 },]

var description = {"title":"3316000000: Repair & Maintenance Services of Aircraft & Spacecraft","contact":{"email":"business.prices@ons.gov.uk","name":"Emelia D'Silva-Parker","telephone":"+44 (0)1633 456907 "},"releaseDate":"2020-10-20T23:00:00.000Z","nextRelease":"18 November 2020","datasetId":"PPI","datasetUri":"/economy/inflationandpriceindices/datasets/producerpriceindexstatisticalbulletindataset","cdid":"JVU7","unit":"","preUnit":"","source":"","date":"2020 SEP","number":"161.0","sampleSize":"0"};
var linechart = {
   chart: {
     type: 'line',
     marginRight: 16,
    
    events: {
        load: function () {
            var chart = this,
                yAxis = chart.yAxis[0],
                tp = yAxis.tickPositions,
                firstLabel = yAxis.ticks[tp[0]].label.getBBox().width,
                lastLabel = yAxis.ticks[tp[tp.length - 1]].label.getBBox().width,
                bb = yAxis.axisTitle.getBBox();
            yAxis.update({
                title: {
                offset: -bb.width + (firstLabel > lastLabel ? firstLabel : lastLabel)
            }
            });
        }
    }
   },
   colors: ['#007dc3', '#409ed2', '#7fbee1', '#007dc3', '#409ed2', '#7fbee1'],

   title: {
     text: description.title
   },
   subtitle: {
     text: 'Source: ' + description.source,
     floating: true,
     align: 'right',
     x: 0,
     verticalAlign: 'bottom',
     y: 10
   },
   navigation: {
     buttonOptions: {
       enabled: false
     }
   },
   xAxis: {
     categories: ["2017 OCT","2017 NOV","2017 DEC","2018 JAN","2018 FEB","2018 MAR","2018 APR","2018 MAY","2018 JUN","2018 JUL","2018 AUG","2018 SEP","2018 OCT","2018 NOV","2018 DEC","2019 JAN","2019 FEB","2019 MAR","2019 APR","2019 MAY","2019 JUN","2019 JUL","2019 AUG","2019 SEP","2019 OCT","2019 NOV","2019 DEC","2020 JAN","2020 FEB","2020 MAR","2020 APR","2020 MAY","2020 JUN","2020 JUL","2020 AUG","2020 SEP",],
      tickPositioner: function () {
       var positions = [];
       var increment = Math.ceil(((this.dataMax) - (this.dataMin)) / 16);
       var tick = Math.floor(this.dataMin);
       for (tick; tick < this.dataMax; tick += increment) {
         positions.push(tick);
       }
       //prevent last tick label overlap the last data in the array if too close
       var diff = tick - this.dataMax;
       if(diff >= (increment /2) ) {
        var deleted = positions.pop();
       }

       positions.push(this.dataMax);
       return positions;
     },
     labels: {
        formatter: function() {
          var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
          var response = '';
          if (w < 768) {
            if (this.isFirst) {
              count = 0;
            }
            if (count % 4 === 0 || this.isLast) {
              response = this.value;
            }
            count++;
          } else {
            response = this.value;
          }
          return response;
        }
     },
     tickmarkPlacement: 'on'
   },
   yAxis: {
     title: {
        text: " " + " ",
       align: 'high',
       rotation: 360,
       x: -15,
       y: -10
     },
    labels: {
      format: '{value:,f}'
    }
   },

   credits: {
     enabled: false
   },

    annotationsOptions: {
        enabledButtons: false
    },

   plotOptions: {
     series: {
       turboThreshold:0,
       shadow: false,
       states: {
         hover: {
           enabled: true,
           shadow: false,
           lineWidth: 3,
           lineWidthPlus: 0,
           marker: {
             height: 0,
             width: 0,
             halo: false,
             enabled: true,
             fillColor: null,
             radiusPlus: null,
             lineWidth: 3,
             lineWidthPlus: 0
           }
         }
       }
     }
   },
   tooltip: {
     shared: true,
     width: '150px',
     crosshairs: {
       width: 2,
       color: '#f37121'
     },
     positioner: function(labelWidth, labelHeight, point) {
       var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
       var points = {
         x: 30,
         y: 42
       };
       var tooltipX, tooltipY;
       var chart = Highcharts.charts[Highcharts.charts.length - 1];
       if (w > 768) {

         if (point.plotX + labelWidth > chart.plotWidth) {
           tooltipX = point.plotX + chart.plotLeft - labelWidth - 20;
           $("#custom-tooltip").removeClass('tooltip-left');
         } else {
           tooltipX = point.plotX + chart.plotLeft + 20;
           $("#custom-tooltip").removeClass('tooltip-right');
         }

         tooltipY = 50;
         points = {
           x: tooltipX,
           y: tooltipY
         };
       } else {
         $("#custom-tooltip").removeClass('tooltip-left');
         $("#custom-tooltip").removeClass('tooltip-right');
       }

       return points;
     },

     formatter: function() {
       var id1 = '<div id="custom-tooltip" class="tooltip-left tooltip-right">';
       var block = id1 + "<div class='sidebar' >";
       var title = '<b class="title">' + this.points[0].key + ': </b>';
       var symbol = ['<div class="circle">●</div>', '<div class="square">■</div>', '<div class="diamond">♦</div>', '<div class="triangle">▲</div>', '<div class="triangle">▼</div>'];

       var content = block;

       // symbols
       $.each(this.points, function(i, val) {
         content += symbol[i];
       });

       content += "<br/></div>";
       content += "<div class='maintext maintext__fixed-width'>";
       content += title;

       // series names and values
       $.each(this.points, function(i, val) {
         content += '<div class="tiptext">' + val.point.series.chart.series[i].name + "<br/><b>Value: " + val.point.series.chart.series[i].options.preUnit + numberWithCommas(val.y) + " " + val.point.series.chart.series[i].options.unit + '</b></div>';
       });
       content += "</div>";
       return content;
     },

     backgroundColor: 'rgba(255, 255, 255, 0)',
     borderWidth: 0,
     borderColor: 'rgba(255, 255, 255, 0)',
     shadow: false,
     useHTML: true

   },
   series: [{
     name: description.title,
     id: description.id,
     unit: description.unit,
     preUnit: description.preUnit,
     data: series,
     marker: {
       enabled:true,
       radius:2,
       symbol: "circle",
       states: {
         hover: {
           fillColor: '#007dc3',
           radiusPlus: 0,
           lineWidthPlus: 0
         }
       }
     },
     dashStyle: 'Solid'
   }]
 };

if(!description.isIndex) {
  var min;
  for(i = 0; i<series.length; i++) {
   min = min ? Math.min(min, series[i].y) : series[i].y;
  }
       
  if(min > 0) {
   linechart.yAxis.min = 0;
  } else {
   linechart.yAxis.min = min - 1;
  }

 };


    function numberWithCommas(number) {
    var parts = number.toString().split(".");
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    return parts.join(".");
    }

window.linechart = linechart;
return linechart;


 })()