var timeplot;

function onLoad() {
  var dataURL = "data.txt";
  var eventsURL = "events.xml";
  var brlURL = "brl.xml";

  var eventSource = new Timeplot.DefaultEventSource();
  var eventSource2 = new Timeplot.DefaultEventSource();
//  var eventSource3 = new Timeplot.DefaultEventSource();
  var kStroke = new Timeplot.ColumnSource(eventSource,27); 
  var cUsage = new Timeplot.ColumnSource(eventSource,22);
  var avgCUsage = new Timeplot.Processor(cUsage,Timeplot.Operator.average,{size: 15});

  var timeGeometry = new Timeplot.DefaultTimeGeometry({
    gridColor: "#000000",
    axisLabelsPlacement: "top"
  });
  var kStrokeGeometry = new Timeplot.DefaultValueGeometry({
	min: 0,
	max: 120000,
        gridColor: "#ff0000",
        axisLabelsPlacement: "left"
  });
  var cUsageGeometry = new Timeplot.DefaultValueGeometry({
	min: 0,
	max: 16,
        gridColor: "#000000",
        axisLabelsPlacement: "right",
  });
  var plotInfo = [
    Timeplot.createPlotInfo({
      id: "keyStrokes",
      dataSource: kStroke,
      timeGeometry: timeGeometry,
      valueGeometry: kStrokeGeometry,	
      lineColor: "#ff0000",
      fillColor: "#cc8080",
      showValues: true,
      roundValues: false
    }),
    Timeplot.createPlotInfo({
      id: "cUsage",
      dataSource: cUsage,
      valueGeometry: cUsageGeometry,
      timeGeometry: timeGeometry,
      lineColor: "#03212E",
      dotColor:	 "#03212E",
      showValues: true,
      roundValues: false
    }),
    Timeplot.createPlotInfo({
      id: "avgCUsage",
      dataSource: avgCUsage,
      valueGeometry: cUsageGeometry,
      timeGeometry: timeGeometry,
      lineColor: "#1200ff",
      lineWidth: 2,
    }),
    Timeplot.createPlotInfo({
      id: "Events",
      eventSource: eventSource2,
      timeGeometry: timeGeometry,
      lineColor: "#5CB32F"
    })/*,
    Timeplot.createPlotInfo({
      id: "BRL",
      eventSource: eventSource3,
      timeGeometry: timeGeometry,
      lineColor: "#AB12FF"
    })*/
  ];        
  timeplot = Timeplot.create(document.getElementById("yearplot"), plotInfo);
  timeplot.loadText(dataURL, " ", eventSource);
  timeplot.loadXML(eventsURL, eventSource2);
//  timeplot.loadXML(brlURL, eventSource3);
}

var resizeTimerID = null;
function onResize() {
    if (resizeTimerID == null) {
        resizeTimerID = window.setTimeout(function() {
            resizeTimerID = null;
            timeplot.repaint();
        }, 100);
    }
}


