morpheus.ConditionalRenderingUI = function(heatmap) {
var _this = this;
this.heatmap = heatmap;
var $div = $('
');
html.push('
'); // morpheus-entry
var $el = $(html.join(''));
shapeField.$el.appendTo($el.find('[name=shapeHolder]'));
var $color = $el.find('[name=color]');
var $series = $el.find('[id=cond_series]');
var $v1 = $el.find('[name=v1]');
var $v2 = $el.find('[name=v2]');
var $v1Op = $el.find('[name=lower]');
var $v2Op = $el.find('[name=upper]');
$color.val(condition.color);
$series.val(condition.series);
shapeField.setShapeValue(condition.shape);
$v1.val(condition.v1);
$v2.val(condition.v2);
$v1Op.val(condition.v1Op);
$v2Op.val(condition.v2Op);
function updateAccept() {
var v1 = parseFloat($($v1).val());
if (isNaN(v1)) {
v1 = -Number.MAX_VALUE;
}
var v2 = parseFloat($($v2).val());
if (isNaN(v2)) {
v2 = Number.MAX_VALUE;
}
var v1Op = $v1Op.val();
var v2Op = $v2Op.val();
var gtf = v1Op === 'gt' ? function(val) {
return val > v1;
} : function(val) {
return val >= v1;
};
var ltf = v2Op === 'lt' ? function(val) {
return val < v2;
} : function(val) {
return val <= v2;
};
condition.v1 = v1;
condition.v2 = v2;
condition.v1Op = v1Op;
condition.v2Op = v2Op;
condition.accept = function(val) {
return gtf(val) && ltf(val);
};
_this.heatmap.revalidate();
}
$v1Op.on('change', function(e) {
updateAccept();
});
$v2Op.on('change', function(e) {
updateAccept();
});
$v1.on('keyup', _.debounce(function(e) {
updateAccept();
}, 100));
$v2.on('keyup', _.debounce(function(e) {
updateAccept();
}, 100));
$color.on('change', function(e) {
condition.color = $(this).val();
_this.heatmap.revalidate();
});
shapeField.on('change', function(e) {
condition.shape = e.shape;
_this.heatmap.revalidate();
});
$series.on('change', function(e) {
condition.series = $(this).val();
_this.heatmap.revalidate();
});
condition.series = $series.val();
return $el;
}
};