X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=experimental%2Fpalette%2Fpalette.js;h=514463f554c45d374cb8ec6497c0b672c9133a12;hb=7655a77a5e75c2626c10c4264c53d52fe9361f5b;hp=18303155eafdc7ab4b6bdc5107267318b089cba0;hpb=ce50b6e8a941e62959a543fabb536d8c55f045fe;p=dygraphs.git
diff --git a/experimental/palette/palette.js b/experimental/palette/palette.js
index 1830315..514463f 100644
--- a/experimental/palette/palette.js
+++ b/experimental/palette/palette.js
@@ -25,110 +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();
- };
-
- // CURRENTLY HIDDEN.
- var tmp = Palette.createChild("button", Palette.createChild("span", row));
- tmp.innerText = "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);
- 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("Function for " + opt, 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 = $("