X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=experimental%2Fpalette%2Fpalette.js;h=514463f554c45d374cb8ec6497c0b672c9133a12;hb=a4c3ece0a11e4e5c4f1f51a8bc8b7878d34ee052;hp=86db6da524d6158e84fbffe799e423036f292b34;hpb=d95dc01489ed4862cf1ac5841b27d3d990bb5a53;p=dygraphs.git diff --git a/experimental/palette/palette.js b/experimental/palette/palette.js index 86db6da..514463f 100644 --- a/experimental/palette/palette.js +++ b/experimental/palette/palette.js @@ -25,108 +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) { - var element = document.createElement(type); - parentElement.appendChild(element); - return element; -}; - -Palette.prototype.create = function(document, parentElement) { +Palette.prototype.create = function(parentElement) { var palette = this; - var table = Palette.createChild("div", parentElement); - table.className = "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); - row.style.visibility = "visible"; - row.className = "header"; - - Palette.createChild("span", row).innerText = "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.innerText = "Redraw" - go.onclick = function() { - palette.onchange(); - }; - - var tmp = Palette.createChild("button", Palette.createChild("span", row)); - tmp.innerText = "Copy" - tmp.onclick = function() { - var textarea = new TextArea(); - textarea.show("Now is the time for all good men\nto come to the aid of their country"); - }; - - 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); - div.innerText = opt; - div.className = "name"; - - var value = Palette.createChild("span", row); - value.className = "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("enter function", inputValue); - textarea.okCallback = function(value) { - if (value != inputValue) { - entry.functionString = value; - entry.input.innerText = 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 = $("