function ClusteringDialog(columnName, expression) {
this._columnName = columnName;
this._expression = expression;
this._method = "binning";
this._function = "fingerprint";
this._params = {};
this._facets = [];
this._createDialog();
this._cluster();
}
ClusteringDialog.prototype._createDialog = function() {
var self = this;
var frame = DialogSystem.createDialog();
frame.width("900px");
var header = $('
No clusters were found with the selected method
Try selecting another method above or changing its parameters
'
);
}
};
ClusteringDialog.prototype._cluster = function() {
var self = this;
var container = this._elmts.tableContainer.html(
'').appendTo(this._elmts.facetContainer);
this._facets.push({
elmt: elmt,
facet: new ClusteringDialog.Facet(this, title, property, elmt, this._getBaseClusters())
});
};
ClusteringDialog.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._baseBins = [];
} 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);
} else if (this._binCount < 3) {
this._step /= 2;
this._binCount *= 2;
this._max = (Math.ceil(this._max / this._step) * this._step);
}
this._baseBins = this._computeDistribution(clusters);
this._from = this._min;
this._to = this._max;
elmt.addClass("clustering-dialog-facet");
var html = $(
'' +
'
' +
'
'
).appendTo(elmt);
this._elmts = DOM.bind(html);
this._histogram = new HistogramWidget(this._elmts.histogramContainer, { binColors: [ "#ccccff", "#6666ff" ] });
this._sliderWidget = new SliderWidget(this._elmts.sliderWidgetDiv);
this._elmts.sliderWidgetDiv.bind("slide", function(evt, data) {
self._from = data.from;
self._to = data.to;
self._setRangeIndicators();
}).bind("stop", function(evt, data) {
self._from = data.from;
self._to = data.to;
self._setRangeIndicators();
self._dialog._updateAll();
});
this._setRangeIndicators();
}
};
ClusteringDialog.Facet.prototype.dispose = function() {
};
ClusteringDialog.Facet.prototype.restrict = function(clusters) {
if (!this._baseBins.length || (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;
};
ClusteringDialog.Facet.prototype.update = function(clusters) {
if (!this._baseBins.length) {
return;
}
var bins = this._computeDistribution(clusters);
this._sliderWidget.update(
this._min,
this._max,
this._step,
this._from,
this._to
);
this._histogram.update(
this._min,
this._max,
this._step,
[ this._baseBins, bins ]
);
};
ClusteringDialog.Facet.prototype._setRangeIndicators = function() {
this._elmts.selectionContainer.html(this._from + " — " + this._to);
};
ClusteringDialog.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;
};