var xScale = new Plottable.Scales.Category();
var yScale = new Plottable.Scales.Linear();
var errors = [];

var errors_dataset = new Plottable.Dataset(errors);

var errors_chart = new Plottable.Plots.Line()
  .addDataset(errors_dataset)
  .x(function(d) { return d.x; }, xScale)
  .y(function(d) { return d.y; }, yScale)
  .renderTo("#lossChart");

window.i = 0;

function evaluate(result) {
}

function error (err) {
  if (window.i % 100 === 0) {
    errors.push({
      x: i,
      y: err
    });

    errors_dataset.data(errors);
  }

  window.i++;
}

function renderDataset() {
  fetch('./x.json').then((resp) => resp.json()).then(function (raw) {
    var xScale = new Plottable.Scales.Linear();
    var yScale = new Plottable.Scales.Linear();

    var colorScale = new Plottable.Scales.InterpolatedColor();
    colorScale.range(["#BDCEF0", "#5279C7", "#15A9BA"]);

    var data = [];
    var colors = [];

    for (var d of raw) {
      data.push({
        x: d[0][1],
        y: d[0][0],
        color: d[1]
      });

      colors.push(d[1]);
    }

    var plot = new Plottable.Plots.Scatter()
      .addDataset(new Plottable.Dataset(data))
      .x(function(d) { return d.x; }, xScale)
      .y(function(d) { return d.y; }, yScale)
      .attr("fill", function(d, i, dataset) { return d.color; }, colorScale)
      .size(10)
      .renderTo("#example");
  });
}

renderDataset();

var Module = {
  wasmBinaryFile: "demo-6b578c0de5265e6e.wasm"
};
