Timeline.DefaultEventSource.Event.prototype.fillTime = function() {  }

var timeplot;

var timeScale = new Timeplot.DefaultTimeGeometry({
  //gridStep: 50,
  //gridColor: "#000000",
  //axisLabelsPlacement: "top"
});

var chapterScale = new Timeplot.DefaultValueGeometry({
  min: -20, max: 5
});

function onLoad() {
  var eventSourceR = new Timeplot.DefaultEventSource();
  var eventSourceC = new Timeplot.DefaultEventSource();
  var eventSourceG = new Timeplot.DefaultEventSource();
  var eventSourceH = new Timeplot.DefaultEventSource();
  var eventSourceD = new Timeplot.DefaultEventSource();
  var eventSourceI = new Timeplot.DefaultEventSource();

  var eventSourceE = new Timeplot.DefaultEventSource();

  var plotInfo = [

    Timeplot.createPlotInfo({
      id: "events",
      timeGeometry: timeScale,
      eventSource: eventSourceE,
      bubbleHeight: 70,
      lineColor: "#C0D8FF"
    }),

    Timeplot.createPlotInfo({
      id: "chapters",
      dataSource: new Timeplot.ColumnSource(eventSourceI,1),
      lineColor: "#FFFFFF",
      fillColor: "#C0D8FF",
      valueGeometry: chapterScale,
      timeGeometry: timeScale
    }),

    Timeplot.createPlotInfo({
      id: "chapters2",
      dataSource: new Timeplot.ColumnSource(eventSourceI,2),
      lineColor: "#FFFFFF",
      fillColor: "#C0D8FF",
      valueGeometry: chapterScale,
      timeGeometry: timeScale
    }),


    Timeplot.createPlotInfo({
      id: "richard-3",
      dataSource: new Timeplot.ColumnSource(eventSourceR,1),
      lineColor: "",
      dotColor: "#8000D0",
      valueGeometry: new Timeplot.DefaultValueGeometry({
        min: -4, max: 4
      }),
      timeGeometry: timeScale
    }),

    Timeplot.createPlotInfo({
      id: "gregory",
      dataSource: new Timeplot.ColumnSource(eventSourceG,1),
      lineColor: "",
      dotColor: "#C00000",
      valueGeometry: new Timeplot.DefaultValueGeometry({
        min: -3, max: 5
      }),
      timeGeometry: timeScale
    }),

    Timeplot.createPlotInfo({
      id: "cynthia",
      dataSource: new Timeplot.ColumnSource(eventSourceC,1),
      lineColor: "",
      dotColor: "#007000",
      valueGeometry: new Timeplot.DefaultValueGeometry({
        min: -2, max: 6
      }),
      timeGeometry: timeScale
    }),

    Timeplot.createPlotInfo({
      id: "dimi",
      dataSource: new Timeplot.ColumnSource(eventSourceD,1),
      lineColor: "",
      dotColor: "#605000",
      valueGeometry: new Timeplot.DefaultValueGeometry({
        min: -1, max: 7
      }),
      timeGeometry: timeScale
    }),

    Timeplot.createPlotInfo({
      id: "hywel",
      dataSource: new Timeplot.ColumnSource(eventSourceH,1),
      lineColor: "",
      dotColor: "#0000D0",
      valueGeometry: new Timeplot.DefaultValueGeometry({
        min: 0, max: 8
      }),
      timeGeometry: timeScale
    })
  ];
            
  timeplot = Timeplot.create(document.getElementById("draconc-timeplot"), plotInfo);
  timeplot.loadText("presencegraph/richard-3.txt", ",", eventSourceR);
  timeplot.loadText("presencegraph/gregory.txt", ",", eventSourceG);
  timeplot.loadText("presencegraph/cynthia.txt", ",", eventSourceC);
  timeplot.loadText("presencegraph/hywel.txt", ",", eventSourceH);
  timeplot.loadText("presencegraph/dimi.txt", ",", eventSourceD);
  timeplot.loadText("presencegraph/chapters.txt", ",", eventSourceI);

  timeplot.loadXML("presencegraph/events.xml", eventSourceE);
}

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