X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=experimental%2Fpalette%2Fpalette.js;h=514463f554c45d374cb8ec6497c0b672c9133a12;hb=7775fca8b30bf3089749da9e66e448f4f05e98fe;hp=7588befd4d5fd363c9a2674faf39fdf3443fbdc0;hpb=f3fe39ed031e2ff2e6d699c06ad391013e84cac3;p=dygraphs.git diff --git a/experimental/palette/palette.js b/experimental/palette/palette.js index 7588bef..514463f 100644 --- a/experimental/palette/palette.js +++ b/experimental/palette/palette.js @@ -25,90 +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.prototype.create = function(document, parentElement) { +Palette.prototype.create = function(parentElement) { var palette = this; - var createChild = function(type, parentElement) { - var element = document.createElement(type); - parentElement.appendChild(element); - return element; - }; - - var table = createChild("table", parentElement); - table.class = "palette"; - - var row = createChild("tr", table); - row.style.display = "block"; - - createChild("td", row).innerText = "Filter:"; - this.filterBar = createChild("input", createChild("td", row)); - this.filterBar.onkeyup = function() { - palette.filter(palette.filterBar.value) - }; - var go = document.createElement("button"); - createChild("td", row).appendChild(go); - go.innerText = "Redraw" - go.onclick = function() { - palette.onchange(); - }; - - for (var opt in opts) { + + var table = $("
") + .addClass("palette") + .width(300) + .appendTo(parentElement); + + this.root = table; + this.tooltip = new Tooltip(); + + // 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 = createChild("tr", table); - var div = createChild("div", createChild("td", row)); - var a = createChild("a", div); - a.innerText = opt; - a.href = "http://dygraphs.com/options.html#" + opt; - a.title = Dygraph.OPTIONS_REFERENCE[opt].description; - a.target="_blank"; - - if (isFunction) { - var input = createChild("button", createChild("td", row)); - 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 + "{ }"; - } - var value = prompt("enter function", inputValue); - if (value != null) { - if (value.length == 0) { - value = null; - } - 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 = $("