X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=experimental%2Fpalette%2Findex.js;h=924b1390c75a769077b01642d0f22fbb834c51aa;hb=b5c7c7a99d83e928e06c45bff23b07bdff4c46f4;hp=8aeced1e544494b19a50c6fc028920f5a4d34ea5;hpb=f4463776380ee90f90bb95b156e758775669c106;p=dygraphs.git diff --git a/experimental/palette/index.js b/experimental/palette/index.js index 8aeced1..924b139 100644 --- a/experimental/palette/index.js +++ b/experimental/palette/index.js @@ -50,6 +50,17 @@ Index.splitVariables = function() { // http://www.idealog.us/2006/06/javascript_ Index.draw = function(element, data, options) { element.innerHTML = ""; element.removeAttribute("style"); + + // Replace the drawCallback function with one that also lets us track + // all labels (for the palette.) + // If the drawCallback option is not specified, use a null function. + var originalDraw = options["drawCallback"] || function() {}; + options.drawCallback = function(g, isInitial) { + Index.palette.setSeries(g.getLabels()); + // Call the original function, too. + originalDraw(g, isInitial); + }; + var g = new Dygraph( element, data, @@ -77,7 +88,7 @@ Index.start = function() { var sample = Samples.data[sampleIndex]; var data = sample.data; var redraw = function() { - Index.draw(document.getElementById("graph"), data, palette.read()); + Index.draw(document.getElementById("graph"), data, Index.palette.read()); } // Selector is the drop-down for selecting a set of data. @@ -109,11 +120,11 @@ Index.start = function() { selector.selectedIndex = sampleIndex; // Palette contains the widget that builds options. - var palette = new MultiPalette(); - palette.create(document.getElementById("optionsPalette")); - palette.write(sample.options); - palette.onchange = redraw; - palette.filterBar.focus(); + Index.palette = new MultiPalette(); + Index.palette.create(document.getElementById("optionsPalette")); + Index.palette.write(sample.options); + Index.palette.onchange = redraw; + Index.palette.filterBar.focus(); redraw();