').appendTo(this._elmts.facetContainer);
this._facets.push({
elmt: elmt,
facet: new FacetBasedEditDialog.Facet(this, title, property, elmt, this._getBaseClusters())
});
};
FacetBasedEditDialog.Facet = function(dialog, title, property, elmt, clusters) {
this._dialog = dialog;
this._property = property;
var self = this;
var max = Number.NEGATIVE_INFINITY;
var min = Number.POSITIVE_INFINITY;
for (var i = 0; i < clusters.length; i++) {
var cluster = clusters[i];
var val = cluster[property];
max = Math.max(max, val);
min = Math.min(min, val);
}
this._min = min;
this._max = max;
if (min >= max) {
this._step = 0;
this._bins = [];
} else {
var diff = max - min;
this._step = 1;
if (diff > 10) {
while (this._step * 100 < diff) {
this._step *= 10;
}
} else {
while (this._step * 100 > diff) {
this._step /= 10;
}
}
this._min = (Math.floor(this._min / this._step) * this._step);
this._max = (Math.ceil(this._max / this._step) * this._step);
this._binCount = 1 + Math.ceil((this._max - this._min) / this._step);
if (this._binCount > 100) {
this._step *= 2;
this._binCount = Math.round((1 + this._binCount) / 2);
}
this._baseBins = this._computeDistribution(clusters);
this._from = this._min;
this._to = this._max;
elmt.addClass("facet-based-edit-dialog-facet");
var html = $(
'' +
'
' +
'
' +
'
'
).appendTo(elmt);
this._elmts = DOM.bind(html);
this._elmts.slider.slider({
min: this._min,
max: this._max,
values: [ this._from, this._to ],
slide: function(evt, ui) {
self._from = ui.values[0];
self._to = ui.values[1];
self._setRangeIndicators();
self._dialog._updateAll();
}
});
this._setRangeIndicators();
}
};
FacetBasedEditDialog.Facet.prototype.dispose = function() {
};
FacetBasedEditDialog.Facet.prototype.restrict = function(clusters) {
if (this._baseBins.length == 0 || (this._from == this._min && this._to == this._max)) {
return clusters;
}
var clusters2 = [];
for (var i = 0; i < clusters.length; i++) {
var cluster = clusters[i];
var val = cluster[this._property];
if (val >= this._from && val <= this._to) {
clusters2.push(cluster);
}
}
return clusters2;
};
FacetBasedEditDialog.Facet.prototype.update = function(clusters) {
if (this._baseBins.length == 0) {
return;
}
var bins = this._computeDistribution(clusters);
var max = 0;
for (var i = 0; i < this._baseBins.length; i++) {
max = Math.max(max, this._baseBins[i]);
}
var values = [];
var diffs = [];
for (var i = 0; i < this._baseBins.length; i++) {
var v = Math.ceil(100 * bins[i] / max);
var diff = Math.ceil(100 * this._baseBins[i] / max) - v;
values.push(v == 0 ? 0 : Math.max(2, v)); // use min 2 to make sure something shows up
diffs.push(diff == 0 ? 0 : Math.max(2, diff));
}
this._elmts.histogramContainer.empty();
$('
![]()
').attr("src",
"http://chart.apis.google.com/chart?" + [
"chs=" + this._elmts.histogramContainer[0].offsetWidth + "x50",
"cht=bvs&chbh=r,0&chco=000088,aaaaff",
"chd=t:" + values.join(",") + "|" + diffs.join(",")
].join("&")
).appendTo(this._elmts.histogramContainer);
};
FacetBasedEditDialog.Facet.prototype._setRangeIndicators = function() {
this._elmts.selectionContainer.text(this._from + " to " + this._to);
};
FacetBasedEditDialog.Facet.prototype._computeDistribution = function(clusters) {
var bins = [];
for (var b = 0; b < this._binCount; b++) {
bins.push(0);
}
for (var i = 0; i < clusters.length; i++) {
var cluster = clusters[i];
var val = cluster[this._property];
var bin = Math.round((val - this._min) / this._step);
bins[bin]++;
}
return bins;
};