X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=experimental%2Fpalette%2Fpalette.js;h=d98ab15fd18ecb2179f0bbd02b9adc61562e69a1;hb=775146792861ea30657f1f2b683ef8011bd5f4d7;hp=d7c7cab42120a5e77bd413d16d49d0f49079c68d;hpb=e26b71566419e1c051f3fbd1f4f8f64b063a04c9;p=dygraphs.git diff --git a/experimental/palette/palette.js b/experimental/palette/palette.js index d7c7cab..d98ab15 100644 --- a/experimental/palette/palette.js +++ b/experimental/palette/palette.js @@ -25,113 +25,109 @@ */ "use strict"; -function Palette() { +/** + * scope is either "global", "series", "x", "y" or "y2". + */ +function Palette(scope) { + // Contains pair of "input" (the input object) and "row" (the parent row) + // Also contains functionString. this.model = {}; + // This is meant to be overridden by a palette host. this.onchange = function() {}; - this.filterBar = null; + this.scope = scope; + this.root = null; } -Palette.createChild = function(type, parentElement, className) { - var element = document.createElement(type); - parentElement.appendChild(element); - if (className) { - element.className = className; - } - return element; -}; - -Palette.prototype.create = function(document, parentElement) { +Palette.prototype.create = function(parentElement) { var palette = this; - var table = Palette.createChild("div", parentElement, "palette"); - table.width="300px"; + var table = $("
") + .addClass("palette") + .width(300) + .appendTo(parentElement); + this.root = table; this.tooltip = new Tooltip(); - var row = Palette.createChild("div", table, "header"); - row.style.visibility = "visible"; - - Palette.createChild("span", row).textContent = "Filter:"; - this.filterBar = Palette.createChild("input", Palette.createChild("span", row)); - this.filterBar.type = "search"; - this.filterBar.onkeyup = function() { - palette.filter(palette.filterBar.value) - }; - this.filterBar.onclick = this.filterBar.onkeyup; - var go = Palette.createChild("button", Palette.createChild("span", row)); - go.textContent = "Redraw" - go.onclick = function() { - palette.onchange(); - }; - - // CURRENTLY HIDDEN. - var tmp = Palette.createChild("button", Palette.createChild("span", row)); - tmp.textContent = "Copy" - tmp.onclick = function() { - var textarea = new TextArea(); - textarea.show("header", "Now is the time for all good men\nto come to the aid of their country"); - }; - tmp.style.display = "none"; - - for (var opt in opts) { + // One row per option. + $.each(opts, function(opt, optEntry) { try { - if (opts.hasOwnProperty(opt)) { - var type = opts[opt].type; - var isFunction = type.indexOf("function(") == 0; - var row = Palette.createChild("div", table); - row.onmouseover = function(source, title, type, body, e) { - return function(e) { - palette.tooltip.show(source, e, title, type, body); - }; - } (row, opt, type, Dygraph.OPTIONS_REFERENCE[opt].description); - row.onmouseout = function() { palette.tooltip.hide(); }; - - var div = Palette.createChild("span", row, "name"); - div.textContent = opt; - - var value = Palette.createChild("span", row, "option"); - - if (isFunction) { - var input = Palette.createChild("button", value); - input.onclick = function(opt, palette) { - return function(event) { - var entry = palette.model[opt]; - var inputValue = entry.functionString; - if (inputValue == null || inputValue.length == 0) { - inputValue = opts[opt].type + "{\n\n}"; - } - var textarea = new TextArea(); - textarea.show(opt, inputValue); - textarea.okCallback = function(value) { - if (value != inputValue) { - entry.functionString = value; - entry.input.textContent = value ? "defined" : "not defined"; - palette.onchange(); + var scope = optEntry.scope || [ "global" ]; // Scope can be empty, infer "global" only. + var valid = scope[0] == "*" || $.inArray(palette.scope, scope) >= 0; + if (!valid) { + return; + } + + var type = optEntry.type; + var isFunction = type.indexOf("function(") == 0; + + var input; + if (isFunction) { + input = $("