Clarifying time filters, small refactor

This commit is contained in:
Maxime Beauchemin 2015-11-03 09:52:19 -08:00
parent 4e6aa4c5b5
commit 0889947394
2 changed files with 37 additions and 29 deletions

View File

@ -99,44 +99,52 @@ function initializeDatasourceView() {
function initSelectionToValue(element, callback) {
callback({id: element.val(), text: element.val()});
}
function list_data(arr) {
var obj = [];
for (var i=0; i<arr.length; i++){
obj.push({id: arr[i], text: arr[i]});
}
return obj;
}
$(".select2_free_since").select2({
createSearchChoice: create_choices,
initSelection: initSelectionToValue,
multiple: false,
data: [
{id: '-1 hour', text: '-1 hour'},
{id: '-12 hours', text: '-12 hours'},
{id: '-1 day', text: '-1 day'},
{id: '-7 days', text: '-7 days'},
{id: '-28 days', text: '-28 days'},
{id: '-90 days', text: '-90 days'},
]
data: list_data([
'1 hour ago',
'12 hours ago',
'1 day ago',
'7 days ago',
'28 days ago',
'90 days ago',
'1 year ago'])
});
$(".select2_free_until").select2({
createSearchChoice: create_choices,
initSelection: initSelectionToValue,
multiple: false,
data: [
{id: 'now', text: 'now'},
{id: '-1 day', text: '-1 day'},
{id: '-7 days', text: '-7 days'},
{id: '-28 days', text: '-28 days'},
{id: '-90 days', text: '-90 days'},
]
data: list_data([
'now',
'1 day ago',
'7 days ago',
'28 days ago',
'90 days ago',
'1 year ago'])
});
$(".select2_free_granularity").select2({
createSearchChoice: create_choices,
initSelection: initSelectionToValue,
multiple: false,
data: [
{id: 'all', text: 'all'},
{id: '5 seconds', text: '5 seconds'},
{id: '30 seconds', text: '30 seconds'},
{id: '1 minute', text: '1 minute'},
{id: '5 minutes', text: '5 minutes'},
{id: '1 day', text: '1 day'},
{id: '7 days', text: '7 days'},
]
data: list_data([
'all',
'5 seconds',
'30 seconds',
'1 minute',
'5 minutes',
'1 hour',
'6 hour',
'1 day',
'7 days'])
});
}

View File

@ -6,6 +6,11 @@ px.registerWidget('word_cloud', function(data_attribute) {
function refresh() {
d3.json(json_callback, function(error, json) {
if (error != null){
var err = '<div class="alert alert-danger">' + error.responseText + '</div>';
token.html(err);
return '';
}
var data = json.data;
var range = [
json.form_data.size_from,
@ -24,11 +29,6 @@ px.registerWidget('word_cloud', function(data_attribute) {
var box = token.node().getBoundingClientRect();
var size = [box.width, box.height - 25];
if (error != null){
var err = '<div class="alert alert-danger">' + error.responseText + '</div>';
token.html(err);
return '';
}
scale = d3.scale.linear()
.range(range)
.domain(d3.extent(data, function(d) { return d.size; }));