/*  hello I think you are cute
 */

// this should already be a Highcharts::chart
if('undefined' == typeof(chart)) throw new Error("rahdune.js needs someone, probably graph.php to define a variable that contains a Highcharts.chart called chart, okay bye");

/*  theGraph.series[] contains the various series objects, each identified to
 *  highcharts using theGraph.series[objN.id ..]
 *
 *  theGraph.series is actually associated with theGraph when it is instantiated
 *  as a property of options, seen here:
 *  const chart = Highcharts.chart('container', options);
 *
 *  I am sure that we can manipulate options, but unsure if references are
 *  maintained after instantiating, or maybe Highcharts::chart has a nice API
 *  for what we want, which is to group control groups of series
 */

// some buttons that know what is what
var defaultButton = document.createElement("button");
let buttons = [];

// make a toggle button to turn off all radon measurements
var rahdunBtn = defaultButton.cloneNode();
rahdunBtn.appendChild(document.createTextNode("rAhDuN3"));
//buttons.push(rahdunBtn);

// attach buttons
buttons.forEach(function(el, i, ar) { document.body.appendChild(el); });

// when users click the radon button it should turn off all the radon readins
rahdunBtn.onclick = function() {};


// add series to HighCharts, this requires a predefined variable called 'series'
series.forEach(function(el, i, ar) {
    /*  el properties:
     *      + data - Highcharts Series Options Structure
     *      + em - Emma id for sensors, A, B, C, D, ..., Z
     *      + type - what kind of sensor is this
     *  one el will be provided per sensor, it is possible for a single
     *  el.em to be provided multiple times, if a sensor has multiple sensors.
     *  If that does not make sense, lol.  We call a group of sensors a sensor,
     *  and sensors can move, so we really have to stick with Emma id.
     */
    let ser = chart.addSeries(el.data, /*redraw*/false);

    //document.body.appendChild(el);
    //chart.addSeries(
});

// render once all data has been added
chart.redraw();

