X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=experimental%2Fpalette%2Fpalette.js;h=2e9acb2479c9e7eb3c1af9081e0384390bffadc9;hb=fe631b38a1490b6573018e266f512bce0207d2ab;hp=18303155eafdc7ab4b6bdc5107267318b089cba0;hpb=ce50b6e8a941e62959a543fabb536d8c55f045fe;p=dygraphs.git diff --git a/experimental/palette/palette.js b/experimental/palette/palette.js index 1830315..2e9acb2 100644 --- a/experimental/palette/palette.js +++ b/experimental/palette/palette.js @@ -25,72 +25,74 @@ */ "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) 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) { +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); - table.className = "palette"; + var table = Palette.createChild("div", parentElement[0], "palette"); + this.root = table; table.width="300px"; 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(); - }; + // Build the header + var header = Palette.createChild("div", table, "header"); + header.style.visibility = "visible"; // CURRENTLY HIDDEN. - var tmp = Palette.createChild("button", Palette.createChild("span", row)); - tmp.innerText = "Copy" + var tmp = Palette.createChild("button", Palette.createChild("span", header)); + 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"; + // One row per option. for (var opt in opts) { try { if (opts.hasOwnProperty(opt)) { var type = opts[opt].type; + + var scope = opts[opt].scope || [ "global" ]; // Scope can be empty, infer "global" only. + var valid = scope[0] == "*" || $.inArray(this.scope, scope) >= 0; + if (!valid) { + continue; + } + 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.onmouseover = function(source, title, type, body) { + return function() { + palette.tooltip.show(source, 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 div = Palette.createChild("span", row, "name"); + div.textContent = opt; - var value = Palette.createChild("span", row); - value.className = "option"; + var value = Palette.createChild("span", row, "option"); if (isFunction) { var input = Palette.createChild("button", value); @@ -101,19 +103,23 @@ Palette.prototype.create = function(document, parentElement) { if (inputValue == null || inputValue.length == 0) { inputValue = opts[opt].type + "{\n\n}"; } - var textarea = new TextArea(); - textarea.show("Function for " + opt, inputValue); - textarea.okCallback = function(value) { + var textarea = new TextArea(); + textarea.show(opt, inputValue); + textarea.okCallback = function(value) { if (value != inputValue) { entry.functionString = value; - entry.input.innerText = value ? "defined" : "not defined"; + entry.input.textContent = value ? "defined" : "undefined"; palette.onchange(); } } } }(opt, this); } else { - var input = Palette.createChild("input", value); + var input = Palette.createChild("input", value, "textInput"); + if (type == "boolean") { + input.size = "5"; + input.maxlength = "5"; + } input.onkeypress = function(event) { var keycode = event.which; if (keycode == 13 || keycode == 8) { @@ -203,7 +209,6 @@ Palette.prototype.read = function() { Palette.prototype.write = function(hash) { var results = {}; for (var opt in this.model) { - // && hash.hasOwnProperty(opt) if (this.model.hasOwnProperty(opt)) { var input = this.model[opt].input; var type = opts[opt].type; @@ -217,7 +222,7 @@ Palette.prototype.write = function(hash) { input.value = value.join(", "); } } else if (type.indexOf("function(") == 0) { - input.innerText = value ? "defined" : "not defined"; + input.textContent = value ? "defined" : "not defined"; this.model[opt].functionString = value ? value.toString() : null; } else { if (value) {