Restructured the Facets (#3097)
* added class to List Facet * added class to Timerange Facet * added class to Range Facet * added class to Text Filter Facet * added class to Scatterplot Facet * added base class * added end line in facet.js * fixed indentations facet.js * fixed indentation again * removed fields * added suggested changes
This commit is contained in:
parent
2a86927b2c
commit
5ca5f3cb7b
@ -466,6 +466,7 @@ function init() {
|
||||
"scripts/project/exporters.js",
|
||||
"scripts/project/scripting.js",
|
||||
|
||||
"scripts/facets/facet.js",
|
||||
"scripts/facets/list-facet.js",
|
||||
"scripts/facets/range-facet.js",
|
||||
"scripts/facets/timerange-facet.js",
|
||||
|
@ -333,6 +333,7 @@
|
||||
"core-facets/big-dot": "Big Dot Size",
|
||||
"core-facets/export-plot": "export plot",
|
||||
"core-facets/numeric": "Numeric",
|
||||
"core-facets/value-range": "$1 — $2",
|
||||
"core-project/open": "Open",
|
||||
"core-project/permalink": "Permalink",
|
||||
"core-project/export": "Export",
|
||||
|
67
main/webapp/modules/core/scripts/facets/facet.js
Normal file
67
main/webapp/modules/core/scripts/facets/facet.js
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
|
||||
Copyright 2010, Google Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
class Facet {
|
||||
constructor(div, config, options) {
|
||||
this._div = div;
|
||||
this._config = config;
|
||||
this._options = options || {};
|
||||
this._minimizeState = false;
|
||||
};
|
||||
|
||||
_minimize() {
|
||||
if(!this._minimizeState) {
|
||||
this._div.addClass("facet-state-minimize");
|
||||
} else {
|
||||
this._div.removeClass("facet-state-minimize");
|
||||
}
|
||||
|
||||
this._minimizeState = !this._minimizeState;
|
||||
};
|
||||
|
||||
_remove() {
|
||||
ui.browsingEngine.removeFacet(this);
|
||||
|
||||
this._div = null;
|
||||
this._config = null;
|
||||
|
||||
this._selection = null;
|
||||
this._blankChoice = null;
|
||||
this._errorChoice = null;
|
||||
this._data = null;
|
||||
this._options = null;
|
||||
};
|
||||
|
||||
dispose() {
|
||||
};
|
||||
};
|
@ -31,21 +31,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
function ListFacet(div, config, options, selection) {
|
||||
this._div = div;
|
||||
this._config = config;
|
||||
if (!("invert" in this._config)) {
|
||||
this._config.invert = false;
|
||||
}
|
||||
class ListFacet extends Facet {
|
||||
constructor(div, config, options, selection) {
|
||||
super(div, config, options);
|
||||
|
||||
this._options = options || {};
|
||||
if (!("sort" in this._options)) {
|
||||
this._options.sort = "name";
|
||||
}
|
||||
|
||||
this._selection = selection || [];
|
||||
|
||||
this._minimizeState = false;
|
||||
if (!("invert" in this._config)) {
|
||||
this._config.invert = false;
|
||||
}
|
||||
|
||||
this._blankChoice = (config.selectBlank) ? { s : true, c : 0 } : null;
|
||||
this._errorChoice = (config.selectError) ? { s : true, c : 0 } : null;
|
||||
@ -54,22 +52,15 @@ function ListFacet(div, config, options, selection) {
|
||||
|
||||
this._initializeUI();
|
||||
this._update();
|
||||
}
|
||||
};
|
||||
|
||||
ListFacet.reconstruct = function(div, uiState) {
|
||||
return new ListFacet(div, uiState.c, uiState.o, uiState.s);
|
||||
};
|
||||
|
||||
ListFacet.prototype.dispose = function() {
|
||||
};
|
||||
|
||||
ListFacet.prototype.reset = function() {
|
||||
reset() {
|
||||
this._selection = [];
|
||||
this._blankChoice = null;
|
||||
this._errorChoice = null;
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype.getUIState = function() {
|
||||
getUIState() {
|
||||
var json = {
|
||||
c: this.getJSON(),
|
||||
o: this._options
|
||||
@ -79,9 +70,9 @@ ListFacet.prototype.getUIState = function() {
|
||||
delete json.c.selection;
|
||||
|
||||
return json;
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype.getJSON = function() {
|
||||
getJSON() {
|
||||
var o = {
|
||||
type: "list",
|
||||
name: this._config.name,
|
||||
@ -101,15 +92,15 @@ ListFacet.prototype.getJSON = function() {
|
||||
o.selection.push(choice);
|
||||
}
|
||||
return o;
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype.hasSelection = function() {
|
||||
hasSelection() {
|
||||
return this._selection.length > 0 ||
|
||||
(this._blankChoice !== null && this._blankChoice.s) ||
|
||||
(this._errorChoice !== null && this._errorChoice.s);
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype.updateState = function(data) {
|
||||
updateState(data) {
|
||||
this._data = data;
|
||||
|
||||
if ("choices" in data) {
|
||||
@ -129,9 +120,9 @@ ListFacet.prototype.updateState = function(data) {
|
||||
}
|
||||
|
||||
this._update();
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype._reSortChoices = function() {
|
||||
_reSortChoices() {
|
||||
this._data.choices.sort(this._options.sort === "name" ?
|
||||
function(a, b) {
|
||||
return a.v.l.toLowerCase().localeCompare(b.v.l.toLowerCase());
|
||||
@ -141,9 +132,9 @@ ListFacet.prototype._reSortChoices = function() {
|
||||
return c !== 0 ? c : a.v.l.localeCompare(b.v.l);
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype._initializeUI = function() {
|
||||
_initializeUI() {
|
||||
var self = this;
|
||||
|
||||
var facet_id = this._div.attr("id");
|
||||
@ -226,9 +217,9 @@ ListFacet.prototype._initializeUI = function() {
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype._copyChoices = function() {
|
||||
_copyChoices() {
|
||||
var self = this;
|
||||
var frame = DialogSystem.createDialog();
|
||||
frame.width("600px");
|
||||
@ -262,9 +253,9 @@ ListFacet.prototype._copyChoices = function() {
|
||||
textarea.value = lines.join("\n");
|
||||
textarea.focus();
|
||||
textarea.select();
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype._update = function(resetScroll) {
|
||||
_update(resetScroll) {
|
||||
var self = this;
|
||||
|
||||
var invert = this._config.invert;
|
||||
@ -330,15 +321,15 @@ ListFacet.prototype._update = function(resetScroll) {
|
||||
|
||||
// None of the following alternatives are significantly faster
|
||||
|
||||
// this._elmts.bodyInnerDiv.innerHtml = '';
|
||||
// this._elmts.bodyInnerDiv.innerHtml = '';
|
||||
|
||||
// this._elmts.bodyInnerDiv.detach();
|
||||
// this._elmts.bodyInnerDiv.children().remove();
|
||||
// this._elmts.bodyInnerDiv.appendTo('.facet-body');
|
||||
// this._elmts.bodyInnerDiv.detach();
|
||||
// this._elmts.bodyInnerDiv.children().remove();
|
||||
// this._elmts.bodyInnerDiv.appendTo('.facet-body');
|
||||
|
||||
// this._elmts.bodyInnerDiv.remove();
|
||||
// this._elmts.bodyInnerDiv.html('<div class="facet-body-inner" bind="bodyInnerDiv"></div>');
|
||||
// this._elmts.bodyInnerDiv.appendTo('.facet-body');
|
||||
// this._elmts.bodyInnerDiv.remove();
|
||||
// this._elmts.bodyInnerDiv.html('<div class="facet-body-inner" bind="bodyInnerDiv"></div>');
|
||||
// this._elmts.bodyInnerDiv.appendTo('.facet-body');
|
||||
|
||||
//this._elmts.statusDiv.show();
|
||||
this._elmts.controlsDiv.show();
|
||||
@ -482,9 +473,9 @@ ListFacet.prototype._update = function(resetScroll) {
|
||||
});
|
||||
};
|
||||
window.setTimeout(wireEvents, 100);
|
||||
}; // end _update()
|
||||
}; // end _update()
|
||||
|
||||
ListFacet.prototype._renderBodyControls = function() {
|
||||
_renderBodyControls() {
|
||||
var self = this;
|
||||
var bodyControls = $('<div>')
|
||||
.addClass("facet-body-controls")
|
||||
@ -509,9 +500,9 @@ ListFacet.prototype._renderBodyControls = function() {
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype._getMetaExpression = function() {
|
||||
_getMetaExpression() {
|
||||
var r = Scripting.parse(this._config.expression);
|
||||
|
||||
return r.language + ':facetCount(' + [
|
||||
@ -519,13 +510,13 @@ ListFacet.prototype._getMetaExpression = function() {
|
||||
JSON.stringify(this._config.expression),
|
||||
JSON.stringify(this._config.columnName)
|
||||
].join(', ') + ')';
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype._doEdit = function() {
|
||||
_doEdit() {
|
||||
new ClusteringDialog(this._config.columnName, this._config.expression);
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype._editChoice = function(choice, choiceDiv) {
|
||||
_editChoice(choice, choiceDiv) {
|
||||
var self = this;
|
||||
|
||||
var menu = MenuSystem.createMenu().addClass("data-table-cell-editor").width("400px");
|
||||
@ -622,9 +613,9 @@ ListFacet.prototype._editChoice = function(choice, choiceDiv) {
|
||||
elmts.cancelButton.click(function() {
|
||||
MenuSystem.dismissAll();
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype._select = function(choice, only) {
|
||||
_select(choice, only) {
|
||||
if (only) {
|
||||
this._selection = [];
|
||||
if (this._blankChoice !== null) {
|
||||
@ -641,9 +632,9 @@ ListFacet.prototype._select = function(choice, only) {
|
||||
}
|
||||
|
||||
this._updateRest();
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype._deselect = function(choice) {
|
||||
_deselect(choice) {
|
||||
if (choice === this._errorChoice || choice === this._blankChoice) {
|
||||
choice.s = false;
|
||||
} else {
|
||||
@ -655,50 +646,28 @@ ListFacet.prototype._deselect = function(choice) {
|
||||
}
|
||||
}
|
||||
this._updateRest();
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype._reset = function() {
|
||||
_reset() {
|
||||
this._selection = [];
|
||||
this._blankChoice = null;
|
||||
this._errorChoice = null;
|
||||
this._config.invert = false;
|
||||
|
||||
this._updateRest();
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype._invert = function() {
|
||||
_invert() {
|
||||
this._config.invert = !this._config.invert;
|
||||
|
||||
this._updateRest();
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype._remove = function() {
|
||||
ui.browsingEngine.removeFacet(this);
|
||||
|
||||
this._div = null;
|
||||
this._config = null;
|
||||
|
||||
this._selection = null;
|
||||
this._blankChoice = null;
|
||||
this._errorChoice = null;
|
||||
this._data = null;
|
||||
};
|
||||
|
||||
ListFacet.prototype._minimize = function() {
|
||||
if(!this._minimizeState) {
|
||||
this._div.addClass("facet-state-minimize");
|
||||
} else {
|
||||
this._div.removeClass("facet-state-minimize");
|
||||
}
|
||||
|
||||
this._minimizeState = !this._minimizeState;
|
||||
};
|
||||
|
||||
ListFacet.prototype._updateRest = function() {
|
||||
_updateRest() {
|
||||
Refine.update({ engineChanged: true });
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype._editExpression = function() {
|
||||
_editExpression() {
|
||||
var self = this;
|
||||
var title = (this._config.columnName) ?
|
||||
($.i18n('core-facets/edit-based-col')+" " + this._config.columnName) :
|
||||
@ -731,9 +700,9 @@ ListFacet.prototype._editExpression = function() {
|
||||
self._elmts.expressionDiv.hide();
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.prototype._setChoiceCountLimit = function(choiceCount) {
|
||||
_setChoiceCountLimit(choiceCount) {
|
||||
var limit = Math.ceil(choiceCount / 1000) * 1000;
|
||||
var s = window.prompt($.i18n('core-facets/set-max-choices'), limit);
|
||||
if (s) {
|
||||
@ -758,4 +727,10 @@ ListFacet.prototype._setChoiceCountLimit = function(choiceCount) {
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
ListFacet.reconstruct = function(div, uiState) {
|
||||
return new ListFacet(div, uiState.c, uiState.o, uiState.s);
|
||||
};
|
||||
|
||||
|
@ -31,12 +31,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
function RangeFacet(div, config, options) {
|
||||
this._div = div;
|
||||
this._config = config;
|
||||
this._options = options;
|
||||
|
||||
this._minimizeState = false;
|
||||
class RangeFacet extends Facet {
|
||||
constructor(div, config, options) {
|
||||
super(div, config, options);
|
||||
|
||||
this._from = ("from" in this._config) ? this._config.from : null;
|
||||
this._to = ("to" in this._config) ? this._config.to : null;
|
||||
@ -46,6 +43,9 @@ function RangeFacet(div, config, options) {
|
||||
this._selectBlank = ("selectBlank" in this._config) ? this._config.selectBlank : true;
|
||||
this._selectError = ("selectError" in this._config) ? this._config.selectError : true;
|
||||
|
||||
this._lang = Refine.getPreference('userLang', 'en');
|
||||
this._formatter = new Intl.NumberFormat(this._lang, { useGrouping: true, maximumFractionDigits: 2 });
|
||||
|
||||
this._baseNumericCount = 0;
|
||||
this._baseNonNumericCount = 0;
|
||||
this._baseBlankCount = 0;
|
||||
@ -58,9 +58,9 @@ function RangeFacet(div, config, options) {
|
||||
|
||||
this._error = false;
|
||||
this._initializedUI = false;
|
||||
}
|
||||
};
|
||||
|
||||
RangeFacet.prototype.reset = function() {
|
||||
reset() {
|
||||
this._from = this._config.min;
|
||||
this._to = this._config.max;
|
||||
this._sliderWidget.update(
|
||||
@ -77,25 +77,18 @@ RangeFacet.prototype.reset = function() {
|
||||
this._selectError = true;
|
||||
|
||||
this._setRangeIndicators();
|
||||
};
|
||||
};
|
||||
|
||||
RangeFacet.reconstruct = function(div, uiState) {
|
||||
return new RangeFacet(div, uiState.c, uiState.o);
|
||||
};
|
||||
|
||||
RangeFacet.prototype.dispose = function() {
|
||||
};
|
||||
|
||||
RangeFacet.prototype.getUIState = function() {
|
||||
getUIState() {
|
||||
var json = {
|
||||
c: this.getJSON(),
|
||||
o: this._options
|
||||
};
|
||||
|
||||
return json;
|
||||
};
|
||||
};
|
||||
|
||||
RangeFacet.prototype.getJSON = function() {
|
||||
getJSON() {
|
||||
var o = {
|
||||
type: "range",
|
||||
name: this._config.name,
|
||||
@ -115,18 +108,18 @@ RangeFacet.prototype.getJSON = function() {
|
||||
}
|
||||
|
||||
return o;
|
||||
};
|
||||
};
|
||||
|
||||
RangeFacet.prototype.hasSelection = function() {
|
||||
hasSelection() {
|
||||
if (!this._selectNumeric || !this._selectNonNumeric || !this._selectBlank || !this._selectError) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (this._from !== null && (!this._initializedUI || this._from > this._config.min)) ||
|
||||
(this._to !== null && (!this._initializedUI || this._to < this._config.max));
|
||||
};
|
||||
};
|
||||
|
||||
RangeFacet.prototype._initializeUI = function() {
|
||||
_initializeUI() {
|
||||
var self = this;
|
||||
this._div
|
||||
.empty()
|
||||
@ -192,9 +185,9 @@ RangeFacet.prototype._initializeUI = function() {
|
||||
self._selectNumeric = true;
|
||||
self._updateRest();
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
RangeFacet.prototype._renderOtherChoices = function() {
|
||||
_renderOtherChoices() {
|
||||
var self = this;
|
||||
var container = this._elmts.otherChoicesDiv.empty();
|
||||
|
||||
@ -267,25 +260,13 @@ RangeFacet.prototype._renderOtherChoices = function() {
|
||||
// --------------------------
|
||||
|
||||
choices.appendTo(container);
|
||||
};
|
||||
};
|
||||
|
||||
RangeFacet.prototype._setRangeIndicators = function() {
|
||||
this._elmts.statusDiv.html(this._addCommas(this._from.toFixed(2)) + " — " + this._addCommas(this._to.toFixed(2)));
|
||||
};
|
||||
_setRangeIndicators() {
|
||||
this._elmts.statusDiv.html($.i18n('core-facets/value-range', this._formatter.format(this._from), this._formatter.format(this._to)));
|
||||
};
|
||||
|
||||
RangeFacet.prototype._addCommas = function(nStr) {
|
||||
nStr += '';
|
||||
x = nStr.split('.');
|
||||
x1 = x[0];
|
||||
x2 = x.length > 1 ? '.' + x[1] : '';
|
||||
var rgx = /(\d+)(\d{3})/;
|
||||
while (rgx.test(x1)) {
|
||||
x1 = x1.replace(rgx, '$1' + ',' + '$2');
|
||||
}
|
||||
return x1 + x2;
|
||||
};
|
||||
|
||||
RangeFacet.prototype.updateState = function(data) {
|
||||
updateState(data) {
|
||||
if ("min" in data && "max" in data) {
|
||||
this._error = false;
|
||||
|
||||
@ -326,9 +307,9 @@ RangeFacet.prototype.updateState = function(data) {
|
||||
}
|
||||
|
||||
this.render();
|
||||
};
|
||||
};
|
||||
|
||||
RangeFacet.prototype.render = function() {
|
||||
render() {
|
||||
if (!this._initializedUI) {
|
||||
this._initializeUI();
|
||||
this._initializedUI = true;
|
||||
@ -365,31 +346,13 @@ RangeFacet.prototype.render = function() {
|
||||
|
||||
this._setRangeIndicators();
|
||||
this._renderOtherChoices();
|
||||
};
|
||||
};
|
||||
|
||||
RangeFacet.prototype._remove = function() {
|
||||
ui.browsingEngine.removeFacet(this);
|
||||
|
||||
this._div = null;
|
||||
this._config = null;
|
||||
this._data = null;
|
||||
};
|
||||
|
||||
RangeFacet.prototype._minimize = function() {
|
||||
if(!this._minimizeState) {
|
||||
this._div.addClass("facet-state-minimize");
|
||||
} else {
|
||||
this._div.removeClass("facet-state-minimize");
|
||||
}
|
||||
|
||||
this._minimizeState = !this._minimizeState;
|
||||
};
|
||||
|
||||
RangeFacet.prototype._updateRest = function() {
|
||||
_updateRest() {
|
||||
Refine.update({ engineChanged: true });
|
||||
};
|
||||
};
|
||||
|
||||
RangeFacet.prototype._editExpression = function() {
|
||||
_editExpression() {
|
||||
var self = this;
|
||||
var title = (this._config.columnName) ?
|
||||
($.i18n('core-facets/edit-based-col')+" " + this._config.columnName) :
|
||||
@ -416,4 +379,9 @@ RangeFacet.prototype._editExpression = function() {
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
RangeFacet.reconstruct = function(div, uiState) {
|
||||
return new RangeFacet(div, uiState.c, uiState.o);
|
||||
};
|
@ -31,62 +31,55 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
function ScatterplotFacet(div, config, options) {
|
||||
this._div = div;
|
||||
this._config = config;
|
||||
this._options = options;
|
||||
|
||||
this._minimizeState = false;
|
||||
class ScatterplotFacet extends Facet {
|
||||
constructor(div, config, options) {
|
||||
super(div, config, options);
|
||||
|
||||
this._error = false;
|
||||
this._initializedUI = false;
|
||||
}
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype.update = function() {
|
||||
update() {
|
||||
this._plotAreaSelector.update();
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype.reset = function() {
|
||||
reset() {
|
||||
delete this._config.from_x;
|
||||
delete this._config.from_y;
|
||||
delete this._config.to_x;
|
||||
delete this._config.to_y;
|
||||
this._plotAreaSelector.setOptions({ hide : true });
|
||||
this._plotAreaSelector.update();
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.reconstruct = function(div, uiState) {
|
||||
return new ScatterplotFacet(div, uiState.c, uiState.o);
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype.dispose = function() {
|
||||
dispose() {
|
||||
this._elmts.plotImg.imgAreaSelect({ hide : true });
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype.getUIState = function() {
|
||||
getUIState() {
|
||||
var json = {
|
||||
c: this.getJSON(),
|
||||
o: this._options
|
||||
};
|
||||
|
||||
return json;
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype.getJSON = function() {
|
||||
getJSON() {
|
||||
this._config.type = "scatterplot";
|
||||
var dot = this._config.dot;
|
||||
if (typeof dot == 'number') this._config.dot.toFixed(2);
|
||||
return this._config;
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype.hasSelection = function() {
|
||||
hasSelection() {
|
||||
return ("from_x" in this._config && this._config.from_x !== 0) ||
|
||||
("from_y" in this._config && this._config.from_y !== 0) ||
|
||||
("to_x" in this._config && this._config.to_x !== 1) ||
|
||||
("to_y" in this._config && this._config.to_y !== 1);
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype._initializeUI = function() {
|
||||
_initializeUI() {
|
||||
var self = this;
|
||||
var container = this._div.empty().show();
|
||||
|
||||
@ -225,9 +218,9 @@ ScatterplotFacet.prototype._initializeUI = function() {
|
||||
});
|
||||
|
||||
this._elmts.selectors.find(".buttonset").buttonset();
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype._fillSelectionOptions = function(ops) {
|
||||
_fillSelectionOptions(ops) {
|
||||
if (this.hasSelection()) {
|
||||
ops.x1 = this._config.l * this._config.from_x;
|
||||
ops.x2 = this._config.l * this._config.to_x;
|
||||
@ -239,9 +232,9 @@ ScatterplotFacet.prototype._fillSelectionOptions = function(ops) {
|
||||
ops.x2 = ops.y2 = this._config.l;
|
||||
ops.hide = true;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype._putSelectionOptions = function(selection) {
|
||||
_putSelectionOptions(selection) {
|
||||
if (selection.height === 0 || selection.width === 0) {
|
||||
this.reset();
|
||||
} else {
|
||||
@ -251,21 +244,21 @@ ScatterplotFacet.prototype._putSelectionOptions = function(selection) {
|
||||
this._config.from_y = (this._config.l - selection.y2) / this._config.l;
|
||||
this._config.to_y = (this._config.l - selection.y1) / this._config.l;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype._formulateCurrentImageUrl = function() {
|
||||
_formulateCurrentImageUrl() {
|
||||
return this._formulateImageUrl(ui.browsingEngine.getJSON(false, this), { color: "ff6a00" });
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype._formulateBaseImageUrl = function() {
|
||||
_formulateBaseImageUrl() {
|
||||
return this._formulateImageUrl({},{ color: "888888", dot : this._config.dot * 0.9 });
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype._formulateExportImageUrl = function() {
|
||||
_formulateExportImageUrl() {
|
||||
return this._formulateImageUrl(ui.browsingEngine.getJSON(false, this), { dot : this._config.dot * 5, l: 500, base_color: "888888" });
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype._formulateImageUrl = function(engineConfig, conf) {
|
||||
_formulateImageUrl(engineConfig, conf) {
|
||||
var options = {};
|
||||
for (var p in this._config) {
|
||||
if (this._config.hasOwnProperty(p)) {
|
||||
@ -283,9 +276,9 @@ ScatterplotFacet.prototype._formulateImageUrl = function(engineConfig, conf) {
|
||||
plotter: JSON.stringify(options)
|
||||
};
|
||||
return "command/core/get-scatterplot?" + $.param(params);
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype.updateState = function(data) {
|
||||
updateState(data) {
|
||||
if ("error" in data) {
|
||||
this._error = true;
|
||||
this._errorMessage = "error" in data ? data.error : $.i18n('core-facets/unknown-error')+".";
|
||||
@ -324,15 +317,15 @@ ScatterplotFacet.prototype.updateState = function(data) {
|
||||
}
|
||||
|
||||
this.render();
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype.changePlot = function() {
|
||||
changePlot() {
|
||||
this._elmts.plotBaseImg.attr("src", this._formulateBaseImageUrl());
|
||||
this._elmts.plotImg.attr("src", this._formulateCurrentImageUrl());
|
||||
this._elmts.exportPlotLink.attr("href", this._formulateExportImageUrl());
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype.render = function() {
|
||||
render() {
|
||||
if (!this._initializedUI) {
|
||||
this._initializeUI();
|
||||
this._initializedUI = true;
|
||||
@ -351,25 +344,13 @@ ScatterplotFacet.prototype.render = function() {
|
||||
|
||||
this._elmts.plotImg.attr("src", this._formulateCurrentImageUrl());
|
||||
this._elmts.exportPlotLink.attr("href", this._formulateExportImageUrl());
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype._remove = function() {
|
||||
ui.browsingEngine.removeFacet(this);
|
||||
|
||||
this._div = null;
|
||||
this._config = null;
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype._minimize = function() {
|
||||
if(!this._minimizeState) {
|
||||
this._div.addClass("facet-state-minimize");
|
||||
} else {
|
||||
this._div.removeClass("facet-state-minimize");
|
||||
}
|
||||
|
||||
this._minimizeState = !this._minimizeState;
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype._updateRest = function() {
|
||||
_updateRest() {
|
||||
Refine.update({ engineChanged: true });
|
||||
};
|
||||
};
|
||||
|
||||
ScatterplotFacet.reconstruct = function(div, uiState) {
|
||||
return new ScatterplotFacet(div, uiState.c, uiState.o);
|
||||
};
|
||||
|
@ -31,46 +31,37 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
function TextSearchFacet(div, config, options) {
|
||||
this._div = div;
|
||||
this._config = config;
|
||||
class TextSearchFacet extends Facet {
|
||||
constructor(div, config, options) {
|
||||
super(div, config, options);
|
||||
if (!("invert" in this._config)) {
|
||||
this._config.invert = false;
|
||||
}
|
||||
|
||||
this._options = options;
|
||||
|
||||
this._minimizeState = false;
|
||||
|
||||
this._query = config.query || null;
|
||||
this._timerID = null;
|
||||
|
||||
this.textSearchFacetCounterForLabels = 0;
|
||||
|
||||
this._initializeUI();
|
||||
this._update();
|
||||
}
|
||||
};
|
||||
|
||||
TextSearchFacet.reconstruct = function(div, uiState) {
|
||||
return new TextSearchFacet(div, uiState.c, uiState.o);
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype.dispose = function() {
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype.reset = function() {
|
||||
reset() {
|
||||
this._query = null;
|
||||
this._div.find(".input-container input").each(function() { this.value = ""; });
|
||||
};
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype.getUIState = function() {
|
||||
getUIState() {
|
||||
var json = {
|
||||
c: this.getJSON(),
|
||||
o: this._options
|
||||
};
|
||||
|
||||
return json;
|
||||
};
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype.getJSON = function() {
|
||||
getJSON() {
|
||||
var o = {
|
||||
type: "text",
|
||||
name: this._config.name,
|
||||
@ -81,13 +72,13 @@ TextSearchFacet.prototype.getJSON = function() {
|
||||
query: this._query
|
||||
};
|
||||
return o;
|
||||
};
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype.hasSelection = function() {
|
||||
hasSelection() {
|
||||
return this._query !== null;
|
||||
};
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype._initializeUI = function() {
|
||||
_initializeUI() {
|
||||
var self = this;
|
||||
var counter = this._uniqueIdForLabels();
|
||||
this._div.empty().show().html(
|
||||
@ -121,7 +112,7 @@ TextSearchFacet.prototype._initializeUI = function() {
|
||||
|
||||
this._elmts.titleSpan.text(this._config.name);
|
||||
if (this._config.caseSensitive) {
|
||||
this._elmts.caseSensitiveCheckbox.prop("checked", true);
|
||||
this._elmts.caseSensitiveCheckbox.prop('checked', true);
|
||||
}
|
||||
if (this._config.mode === "regex") {
|
||||
this._elmts.regexCheckbox.prop('checked', true);
|
||||
@ -158,17 +149,17 @@ TextSearchFacet.prototype._initializeUI = function() {
|
||||
self._scheduleUpdate();
|
||||
}).focus();
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype.updateState = function(data) {
|
||||
updateState(data) {
|
||||
this._update();
|
||||
};
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype.render = function() {
|
||||
render() {
|
||||
this._setRangeIndicators();
|
||||
};
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype._reset = function() {
|
||||
_reset() {
|
||||
this._query = null;
|
||||
this._config.mode = "text";
|
||||
this._config.caseSensitive = false;
|
||||
@ -178,33 +169,15 @@ TextSearchFacet.prototype._reset = function() {
|
||||
this._config.invert = false;
|
||||
|
||||
this._updateRest();
|
||||
};
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype._invert = function() {
|
||||
_invert() {
|
||||
this._config.invert = !this._config.invert;
|
||||
|
||||
this._updateRest();
|
||||
};
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype._remove = function() {
|
||||
ui.browsingEngine.removeFacet(this);
|
||||
|
||||
this._div = null;
|
||||
this._config = null;
|
||||
this._options = null;
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype._minimize = function() {
|
||||
if(!this._minimizeState) {
|
||||
this._div.addClass("facet-state-minimize");
|
||||
} else {
|
||||
this._div.removeClass("facet-state-minimize");
|
||||
}
|
||||
|
||||
this._minimizeState = !this._minimizeState;
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype._update = function () {
|
||||
_update() {
|
||||
var invert = this._config.invert;
|
||||
if (invert) {
|
||||
this._elmts.facetTitle.addClass("facet-title-inverted");
|
||||
@ -213,9 +186,9 @@ TextSearchFacet.prototype._update = function () {
|
||||
this._elmts.facetTitle.removeClass("facet-title-inverted");
|
||||
this._elmts.invertButton.removeClass("facet-mode-inverted");
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype._scheduleUpdate = function() {
|
||||
_scheduleUpdate() {
|
||||
if (!this._timerID) {
|
||||
var self = this;
|
||||
this._timerID = window.setTimeout(function() {
|
||||
@ -223,13 +196,18 @@ TextSearchFacet.prototype._scheduleUpdate = function() {
|
||||
self._updateRest();
|
||||
}, self._config.mode === 'regex' ? 1500 : 500);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
TextSearchFacet.prototype._updateRest = function() {
|
||||
_updateRest() {
|
||||
Refine.update({ engineChanged: true });
|
||||
};
|
||||
|
||||
_uniqueIdForLabels() {
|
||||
return this.textSearchFacetCounterForLabels++;
|
||||
};
|
||||
};
|
||||
|
||||
var textSearchFacetCounterForLabels = 0;
|
||||
TextSearchFacet.prototype._uniqueIdForLabels = function() {
|
||||
return textSearchFacetCounterForLabels++;
|
||||
|
||||
TextSearchFacet.reconstruct = function(div, uiState) {
|
||||
return new TextSearchFacet(div, uiState.c, uiState.o);
|
||||
};
|
||||
|
@ -31,12 +31,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
function TimeRangeFacet(div, config, options) {
|
||||
this._div = div;
|
||||
this._config = config;
|
||||
this._options = options;
|
||||
|
||||
this._minimizeState = false;
|
||||
class TimeRangeFacet extends Facet{
|
||||
constructor(div, config, options) {
|
||||
super(div, config, options);
|
||||
|
||||
this._from = ("from" in this._config) ? this._config.from : null;
|
||||
this._to = ("to" in this._config) ? this._config.to : null;
|
||||
@ -59,9 +56,9 @@ function TimeRangeFacet(div, config, options) {
|
||||
|
||||
this._error = false;
|
||||
this._initializedUI = false;
|
||||
}
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype.reset = function() {
|
||||
reset() {
|
||||
this._from = this._config.min;
|
||||
this._to = this._config.max;
|
||||
this._sliderWidget.update(
|
||||
@ -78,25 +75,18 @@ TimeRangeFacet.prototype.reset = function() {
|
||||
this._selectError = true;
|
||||
|
||||
this._setRangeIndicators();
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeFacet.reconstruct = function(div, uiState) {
|
||||
return new TimeRangeFacet(div, uiState.c, uiState.o);
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype.dispose = function() {
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype.getUIState = function() {
|
||||
getUIState() {
|
||||
var json = {
|
||||
c: this.getJSON(),
|
||||
o: this._options
|
||||
};
|
||||
|
||||
return json;
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype.getJSON = function() {
|
||||
getJSON() {
|
||||
var o = {
|
||||
type: "timerange",
|
||||
name: this._config.name,
|
||||
@ -116,18 +106,18 @@ TimeRangeFacet.prototype.getJSON = function() {
|
||||
}
|
||||
|
||||
return o;
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype.hasSelection = function() {
|
||||
hasSelection() {
|
||||
if (!this._selectTime || !this._selectNonTime || !this._selectBlank || !this._selectError) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (this._from !== null && (!this._initializedUI || this._from > this._config.min)) ||
|
||||
(this._to !== null && (!this._initializedUI || this._to < this._config.max));
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype._initializeUI = function() {
|
||||
_initializeUI() {
|
||||
var self = this;
|
||||
this._div
|
||||
.empty()
|
||||
@ -193,9 +183,9 @@ TimeRangeFacet.prototype._initializeUI = function() {
|
||||
self._selectTime = true;
|
||||
self._updateRest();
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype._renderOtherChoices = function() {
|
||||
_renderOtherChoices() {
|
||||
var self = this;
|
||||
var container = this._elmts.otherChoicesDiv.empty();
|
||||
|
||||
@ -268,23 +258,9 @@ TimeRangeFacet.prototype._renderOtherChoices = function() {
|
||||
// --------------------------
|
||||
|
||||
choices.appendTo(container);
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype.steps = [
|
||||
1, // msec
|
||||
1000, // sec
|
||||
1000*60, // min
|
||||
1000*60*60, // hour
|
||||
1000*60*60*24, // day
|
||||
1000*60*60*24*7, // week
|
||||
1000*2629746, // month (average Gregorian year / 12)
|
||||
1000*31556952, // year (average Gregorian year)
|
||||
1000*31556952*10, // decade
|
||||
1000*31556952*100, // century
|
||||
1000*31556952*1000 // millennium
|
||||
];
|
||||
|
||||
TimeRangeFacet.prototype._setRangeIndicators = function() {
|
||||
_setRangeIndicators() {
|
||||
var fromDate = new Date(this._from);
|
||||
var toDate = new Date(this._to);
|
||||
|
||||
@ -299,21 +275,9 @@ TimeRangeFacet.prototype._setRangeIndicators = function() {
|
||||
var dayOfYearFormat = "yyyy-MM-dd";
|
||||
this._elmts.statusDiv.html("<b>" + fromDate.toString(dayOfYearFormat) + "</b> " + fromDate.toString(timeOfDayformat) + " — " + "<b>" + toDate.toString(dayOfYearFormat) + "</b> " + toDate.toString(timeOfDayformat) );
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype._addCommas = function(nStr) {
|
||||
nStr += '';
|
||||
x = nStr.split('.');
|
||||
x1 = x[0];
|
||||
x2 = x.length > 1 ? '.' + x[1] : '';
|
||||
var rgx = /(\d+)(\d{3})/;
|
||||
while (rgx.test(x1)) {
|
||||
x1 = x1.replace(rgx, '$1' + ',' + '$2');
|
||||
}
|
||||
return x1 + x2;
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype.updateState = function(data) {
|
||||
updateState(data) {
|
||||
if ("min" in data && "max" in data) {
|
||||
this._error = false;
|
||||
|
||||
@ -356,9 +320,9 @@ TimeRangeFacet.prototype.updateState = function(data) {
|
||||
}
|
||||
|
||||
this.render();
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype.render = function() {
|
||||
render() {
|
||||
if (!this._initializedUI) {
|
||||
this._initializeUI();
|
||||
this._initializedUI = true;
|
||||
@ -395,31 +359,13 @@ TimeRangeFacet.prototype.render = function() {
|
||||
|
||||
this._setRangeIndicators();
|
||||
this._renderOtherChoices();
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype._remove = function() {
|
||||
ui.browsingEngine.removeFacet(this);
|
||||
|
||||
this._div = null;
|
||||
this._config = null;
|
||||
this._data = null;
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype._minimize = function() {
|
||||
if(!this._minimizeState) {
|
||||
this._div.addClass("facet-state-minimize");
|
||||
} else {
|
||||
this._div.removeClass("facet-state-minimize");
|
||||
}
|
||||
|
||||
this._minimizeState = !this._minimizeState;
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype._updateRest = function() {
|
||||
_updateRest() {
|
||||
Refine.update({ engineChanged: true });
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype._editExpression = function() {
|
||||
_editExpression() {
|
||||
var self = this;
|
||||
var title = (this._config.columnName) ?
|
||||
($.i18n('core-facets/edit-based-col')+" " + this._config.columnName) :
|
||||
@ -446,4 +392,23 @@ TimeRangeFacet.prototype._editExpression = function() {
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeFacet.reconstruct = function(div, uiState) {
|
||||
return new TimeRangeFacet(div, uiState.c, uiState.o);
|
||||
};
|
||||
|
||||
TimeRangeFacet.prototype.steps = [
|
||||
1, // msec
|
||||
1000, // sec
|
||||
1000*60, // min
|
||||
1000*60*60, // hour
|
||||
1000*60*60*24, // day
|
||||
1000*60*60*24*7, // week
|
||||
1000*2629746, // month (average Gregorian year / 12)
|
||||
1000*31556952, // year (average Gregorian year)
|
||||
1000*31556952*10, // decade
|
||||
1000*31556952*100, // century
|
||||
1000*31556952*1000 // millennium
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user