From: Robert Konigsberg Date: Thu, 27 Dec 2012 22:23:30 +0000 (-0500) Subject: Add some comments to index.js, the Index namespace for the palette. X-Git-Tag: v1.0.0~139^2~18 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=f8e9ac7374f9d56e65944598f5f20400709517bd;hp=776c426146810f64f58c9e792a56832dfc0e8a82;p=dygraphs.git Add some comments to index.js, the Index namespace for the palette. --- diff --git a/experimental/palette/index.js b/experimental/palette/index.js index 602bde4..9a299a3 100644 --- a/experimental/palette/index.js +++ b/experimental/palette/index.js @@ -41,6 +41,12 @@ Index.splitVariables = function() { // http://www.idealog.us/2006/06/javascript_ return args; } +/** + * Draw the graph. + * @param {Object} element the display element + * @param {Object} data the data to be shown + * @param {Object} options the options hash. + */ Index.draw = function(element, data, options) { element.innerHTML = ""; element.removeAttribute("style"); @@ -61,12 +67,12 @@ Index.addMessage = function(text) { messages.textContent = messages.textContent + text + "\n"; } +/** + * Start up the palette system. + */ Index.start = function() { var variables = Index.splitVariables(); - var sampleName = variables["sample"]; - if (!(sampleName)) { - sampleName = "interestingShapes"; - } + var sampleName = variables["sample"] || "interestingShapes"; var sampleIndex = Samples.indexOf(sampleName); var sample = Samples.data[sampleIndex]; var data = sample.data; @@ -74,6 +80,9 @@ Index.start = function() { Index.draw(document.getElementById("graph"), data, palette.read()); } + // Selector is the drop-down for selecting a set of data. + + // Popupate the selector with the set of data samples var selector = document.getElementById("selector").getElementsByTagName("select")[0]; for (var idx in Samples.data) { var entry = Samples.data[idx]; @@ -98,13 +107,17 @@ Index.start = function() { window.location = url; } selector.selectedIndex = sampleIndex; + + // Palette contains the widget that builds options. var palette = new Palette(); palette.create(document, document.getElementById("optionsPalette")); palette.write(sample.options); palette.onchange = redraw; palette.filterBar.focus(); + redraw(); + // Find all new options which we don't implement here in the palette. for (var opt in Dygraph.OPTIONS_REFERENCE) { if (!(opt in opts)) { var entry = Dygraph.OPTIONS_REFERENCE[opt];