Merge pull request #161 from mistercrunch/chris/eslint

Add linting to package.json, do all of the linting.
This commit is contained in:
Chris Williams 2016-03-04 10:24:06 -08:00
commit 1782d8f278
24 changed files with 621 additions and 435 deletions

View File

@ -0,0 +1,3 @@
node_modules/*
vendor/*
javascripts/dist/*

234
panoramix/assets/.eslintrc Normal file
View File

@ -0,0 +1,234 @@
{
"root": true,
"globals": {
"Symbol": false,
"Map": false,
"Set": false,
"Reflect": false,
},
"env": {
"es6": false,
"browser": true,
"node": true,
},
"parserOptions": {
"ecmaVersion": 5,
"sourceType": "module"
},
"rules": {
"array-bracket-spacing": [2, "never", {
"singleValue": false,
"objectsInArrays": false,
"arraysInArrays": false
}],
"array-callback-return": [2],
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"callback-return": [2, ["callback"]],
"camelcase": [0],
"comma-dangle": [2, "never"],
"comma-spacing": [2],
"comma-style": [2, "last"],
"curly": [2, "all"],
"eqeqeq": 2,
"func-names": [0],
"id-length": [2, { "min": 1, "max": 25, "properties": "never" }],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [2, {
"before": true,
"after": true,
"overrides": {
"return": { "after": true },
"throw": { "after": true },
"case": { "after": true }
}
}],
"linebreak-style": [2, "unix"],
"lines-around-comment": [2, {
"beforeBlockComment": false,
"afterBlockComment": false,
"beforeLineComment": false,
"allowBlockStart": true,
"allowBlockEnd": true
}],
"max-depth": [2, 5],
"max-len": [0, 80, 4],
"max-nested-callbacks": [1, 2],
"max-params": [1, 3],
"new-parens": [2],
"newline-after-var": [0],
"no-bitwise": [0],
"no-cond-assign": [2],
"no-console": [2],
"no-const-assign": [2],
"no-constant-condition": [2],
"no-control-regex": [2],
"no-debugger": [2],
"no-delete-var": [2],
"no-dupe-args": [2],
"no-dupe-class-members": [2],
"no-dupe-keys": [2],
"no-duplicate-case": [2],
"no-else-return": [0],
"no-empty": [2],
"no-eq-null": [0],
"no-eval": [2],
"no-ex-assign": [2],
"no-extend-native": [2],
"no-extra-bind": [2],
"no-extra-boolean-cast": [2],
"no-extra-label": [2],
"no-extra-parens": [0], // needed for clearer #math eg (a - b) / c
"no-extra-semi": [2],
"no-fallthrough": [2],
"no-floating-decimal": [2],
"no-func-assign": [2],
"no-implied-eval": [2],
"no-implicit-coercion": [2, {
"boolean": false,
"number": true,
"string": true
}],
"no-implicit-globals": [2],
"no-inline-comments": [0],
"no-invalid-regexp": [2],
"no-irregular-whitespace": [2],
"no-iterator": [2],
"no-label-var": [2],
"no-labels": [2, { "allowLoop": false, "allowSwitch": false }],
"no-lone-blocks": [2],
"no-lonely-if": [2],
"no-loop-func": [2],
"no-magic-numbers": [0], // doesn't work well with vis cosmetic constant
"no-mixed-requires": [1, false],
"no-mixed-spaces-and-tabs": [2, false],
"no-multi-spaces": [2, {
"exceptions": {
"ImportDeclaration": true,
"Property": true,
"VariableDeclarator": true
}
}],
"no-multi-str": [2],
"no-multiple-empty-lines": [2, { "max": 1, "maxEOF": 1 }],
"no-native-reassign": [2],
"no-negated-condition": [2],
"no-negated-in-lhs": [2],
"no-nested-ternary": [0],
"no-new": [2],
"no-new-func": [2],
"no-new-object": [2],
"no-new-require": [0],
"no-new-symbol": [2],
"no-new-wrappers": [2],
"no-obj-calls": [2],
"no-octal": [2],
"no-octal-escape": [2],
"no-path-concat": [0],
"no-process-env": [0],
"no-process-exit": [2],
"no-proto": [2],
"no-redeclare": [2],
"no-regex-spaces": [2],
"no-restricted-modules": [0],
"no-restricted-imports": [0],
"no-restricted-syntax": [2,
"DebuggerStatement",
"LabeledStatement",
"WithStatement"
],
"no-return-assign": [2, "always"],
"no-script-url": [2],
"no-self-assign": [2],
"no-self-compare": [0],
"no-sequences": [2],
"no-shadow-restricted-names": [2],
"no-spaced-func": [2],
"no-sparse-arrays": [2],
"no-sync": [0],
"no-ternary": [0],
"no-this-before-super": [2],
"no-throw-literal": [2],
"no-trailing-spaces": [2, { "skipBlankLines": false }],
"no-undef": [2, { "typeof": true }],
"no-undef-init": [2],
"no-undefined": [0],
"no-underscore-dangle": [0], // __data__ sometimes
"no-unexpected-multiline": [2],
"no-unmodified-loop-condition": [2],
"no-unneeded-ternary": [2],
"no-unreachable": [2],
"no-unused-expressions": [2],
"no-unused-labels": [2],
"no-unused-vars": [2, {
"vars": "all",
"args": "none", // (d, i) pattern d3 func makes difficult to enforce
"varsIgnorePattern": "jQuery"
}],
"no-use-before-define": [0],
"no-useless-call": [2],
"no-useless-concat": [2],
"no-useless-constructor": [2],
"no-void": [0],
"no-warning-comments": [0, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],
"no-with": [2],
"no-whitespace-before-property": [2],
"object-curly-spacing": [2, "always"],
"object-shorthand": [2, "never"],
"one-var": [0],
"one-var-declaration-per-line": [2, "initializations"],
"operator-assignment": [0, "always"],
"padded-blocks": [0],
"prefer-arrow-callback": [0],
"prefer-const": [0],
"prefer-reflect": [0],
"prefer-rest-params": [0],
"prefer-spread": [0],
"prefer-template": [0],
"quote-props": [2, "as-needed", { "keywords": true }],
"radix": [2],
"require-yield": [2],
"semi": [2],
"semi-spacing": [2, { "before": false, "after": true }],
"sort-vars": [0],
"sort-imports": [0],
"space-before-function-paren": [2, { "anonymous": "always", "named": "never" }],
"space-before-blocks": [2, { "functions": "always", "keywords": "always" }],
"space-in-brackets": [0, "never", {
"singleValue": true,
"arraysInArrays": false,
"arraysInObjects": false,
"objectsInArrays": true,
"objectsInObjects": true,
"propertyName": false
}],
},
// Temporarily not enforced
"new-cap": [2], // @TODO more tricky for the moment
"newline-per-chained-call": [2, { "ignoreChainWithDepth": 6 }],
"no-param-reassign": [0], // turn on once default args supported
"no-shadow": [2, { // @TODO more tricky for the moment with eg 'data'
"builtinGlobals": false,
"hoist": "functions",
"allow": ["i", "d"]
}],
"space-in-parens": [2, "never"],
"space-infix-ops": [2],
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": [2, "always", { "markers": ["!"] }],
"spaced-line-comment": [0, "always"],
"strict": [2, "global"],
"template-curly-spacing": [2, "never"],
"use-isnan": [2],
"valid-jsdoc": [0],
"valid-typeof": [2],
"vars-on-top": [0],
"wrap-iife": [2],
"wrap-regex": [2],
"yield-star-spacing": [2, { "before": false, "after": true }],
"yoda": [2, "never", { "exceptRange": true, "onlyEquality": false }]
}

View File

@ -11,7 +11,6 @@ require('brace/theme/crimson_editor');
require('select2');
require('../node_modules/gridster/dist/jquery.gridster.min.js');
var Dashboard = function (dashboardData) {
var dashboard = $.extend(dashboardData, {
filters: {},
@ -30,7 +29,6 @@ var Dashboard = function(dashboardData) {
this.slices = sliceObjects;
},
setFilter: function (slice_id, col, vals) {
console.log([slice_id, col, vals]);
this.addFilter(slice_id, col, vals, false);
},
addFilter: function (slice_id, col, vals, merge) {
@ -90,7 +88,7 @@ var Dashboard = function(dashboardData) {
widget_margins: [5, 5],
widget_base_dimensions: [100, 100],
draggable: {
handle: '.drag',
handle: '.drag'
},
resize: {
enabled: true,
@ -107,7 +105,7 @@ var Dashboard = function(dashboardData) {
size_x: wgd.size_x,
size_y: wgd.size_y
};
},
}
}).data('gridster');
$("div.gridster").css('visibility', 'visible');
$("#savedash").click(function () {
@ -115,26 +113,27 @@ var Dashboard = function(dashboardData) {
$.each($(".slice_info"), function (i, d) {
var widget = $(this).parents('.widget');
var slice_description = widget.find('.slice_description');
if (slice_description.is(":visible"))
if (slice_description.is(":visible")) {
expanded_slices[$(d).attr('slice_id')] = true;
}
});
var data = {
positions: gridster.serialize(),
css: editor.getValue(),
expanded_slices: expanded_slices,
expanded_slices: expanded_slices
};
$.ajax({
type: "POST",
url: '/panoramix/save_dash/' + dashboard.id + '/',
data: {
'data': JSON.stringify(data)
data: JSON.stringify(data)
},
success: function () {
alert("Saved!");
},
error: function () {
alert("Error :(");
},
}
});
});
@ -144,7 +143,7 @@ var Dashboard = function(dashboardData) {
editor.setTheme("ace/theme/crimson_editor");
editor.setOptions({
minLines: 16,
maxLines: Infinity,
maxLines: Infinity
});
editor.getSession().setMode("ace/mode/css");
@ -189,5 +188,5 @@ var Dashboard = function(dashboardData) {
};
$(document).ready(function () {
var dashboard = Dashboard($('.dashboard').data('dashboard'));
Dashboard($('.dashboard').data('dashboard'));
});

View File

@ -6,7 +6,6 @@
var $ = window.$ = require('jquery');
var jQuery = window.jQuery = $;
var px = require('./modules/panoramix.js');
var d3 = require('d3');
require('jquery-ui');
$.widget.bridge('uitooltip', $.ui.tooltip); // Shutting down jq-ui tooltips
@ -28,7 +27,7 @@ function prepForm() {
$("#filters > div").each(function () {
$(this).attr("id", function () {
return "flt_" + i;
})
});
$(this).find("#flt_col_0")
.attr("id", function () {
return "flt_col_" + i;
@ -83,20 +82,8 @@ function initExploreView() {
var fieldset = parent.find(".legend_label").text();
var collapsed_fieldsets = get_collapsed_fieldsets();
var index;
if (!parent.hasClass("collapsed")) {
if (animation) {
parent.find(".fieldset_content").slideUp();
} else {
parent.find(".fieldset_content").hide();
}
parent.addClass("collapsed");
parent.find("span.collapser").text("[+]");
index = collapsed_fieldsets.indexOf(fieldset);
if (index === -1 && fieldset !== "" && fieldset !== undefined) {
collapsed_fieldsets.push(fieldset);
}
} else {
if (parent.hasClass("collapsed")) {
if (animation) {
parent.find(".fieldset_content").slideDown();
} else {
@ -110,7 +97,21 @@ function initExploreView() {
if (index !== -1) {
collapsed_fieldsets.splice(index, 1);
}
} else { // not collapsed
if (animation) {
parent.find(".fieldset_content").slideUp();
} else {
parent.find(".fieldset_content").hide();
}
parent.addClass("collapsed");
parent.find("span.collapser").text("[+]");
index = collapsed_fieldsets.indexOf(fieldset);
if (index === -1 && fieldset !== "" && fieldset !== undefined) {
collapsed_fieldsets.push(fieldset);
}
}
$("#collapsed_fieldsets").val(collapsed_fieldsets.join("||"));
}
@ -130,7 +131,7 @@ function initExploreView() {
try {
var successful = document.execCommand('copy');
if (!successful) {
throw "Not successful";
throw new Error("Not successful");
}
} catch (err) {
window.alert("Sorry, your browser does not support copying. Use Ctrl / Cmd + C!");
@ -144,12 +145,12 @@ function initExploreView() {
type: "POST",
url: '/r/shortner/',
data: {
'data': '/' + window.location.pathname + slice.querystring()
data: '/' + window.location.pathname + slice.querystring()
},
success: function (data) {
var close = '<a style="cursor: pointer;"><i class="fa fa-close" id="close_shortner"></i></a>';
var copy = '<a style="cursor: pointer;"><i class="fa fa-clipboard" title="Copy to clipboard" id="copy_url"></i></a>';
var spaces = '&nbsp;&nbsp;&nbsp;'
var spaces = '&nbsp;&nbsp;&nbsp;';
var popover = data + spaces + copy + spaces + close;
var $shortner = $('#shortner')
@ -163,21 +164,20 @@ function initExploreView() {
$('#copy_url').tooltip().click(function () {
var success = copyURLToClipboard(data);
if (success) {
$(this).attr("data-original-title", "Copied!").tooltip('fixTitle').tooltip('show');
window.setTimeout(function() {
$shortner.popover('destroy');
}, 1200);
window.setTimeout(destroyPopover, 1200);
}
});
$('#close_shortner').click(function() {
$('#close_shortner').click(destroyPopover);
function destroyPopover() {
$shortner.popover('destroy');
});
}
},
error: function () {
alert("Error :(");
},
}
});
});
$("#viz_type").change(function () {
@ -237,7 +237,6 @@ function initExploreView() {
returnLocation.reload();
});
$("#plus").click(add_filter);
$("#btn_save").click(function () {
var slice_name = prompt("Name your slice!");
@ -278,16 +277,6 @@ function initExploreView() {
});
}
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_freeform").each(function () {
var parent = $(this).parent();
var name = $(this).attr('name');
@ -302,7 +291,7 @@ function initExploreView() {
selected = this.options[i].value;
}
}
var obj = parent.append(
parent.append(
'<input class="' + $(this).attr('class') + '" name="' + name + '" type="text" value="' + selected + '">'
);
$("input[name='" + name + "']").select2({
@ -310,7 +299,7 @@ function initExploreView() {
initSelection: initSelectionToValue,
dropdownAutoWidth: true,
multiple: false,
data: l,
data: l
});
$(this).remove();
});
@ -323,7 +312,6 @@ $(document).ready(function() {
var visType = window.viz_type.value;
px.registerViz(visType);
var data = $('.slice').data('slice');
slice = px.Slice(data);

View File

@ -6,8 +6,8 @@ require('bootstrap');
$(document).ready(function () {
$('#dataset-table').DataTable({
"bPaginate": false,
"order": [
bPaginate: false,
order: [
[1, "asc"]
]
});

View File

@ -1,5 +1,5 @@
var $ = require('jquery'),
jQuery = $;
var $ = require('jquery');
var jQuery = $;
var d3 = require('d3');
// vis sources
@ -23,7 +23,7 @@ var sourceMap = {
sunburst: 'sunburst.js',
table: 'table.js',
word_cloud: 'word_cloud.js',
world_map: 'world_map.js',
world_map: 'world_map.js'
};
var color = function () {
@ -32,13 +32,13 @@ var color = function() {
//rausch hackb kazan babu lima beach barol
'#ff5a5f', '#7b0051', '#007A87', '#00d1c1', '#8ce071', '#ffb400', '#b4a76c',
'#ff8083', '#cc0086', '#00a1b3', '#00ffeb', '#bbedab', '#ffd266', '#cbc29a',
'#ff3339', '#ff1ab1', '#005c66', '#00b3a5', '#55d12e', '#b37e00', '#988b4e',
'#ff3339', '#ff1ab1', '#005c66', '#00b3a5', '#55d12e', '#b37e00', '#988b4e'
];
var spectrums = {
'blue_white_yellow': ['#00d1c1', 'white', '#ffb400'],
'fire': ['white', 'yellow', 'red', 'black'],
'white_black': ['white', 'black'],
'black_white': ['black', 'white'],
blue_white_yellow: ['#00d1c1', 'white', '#ffb400'],
fire: ['white', 'yellow', 'red', 'black'],
white_black: ['white', 'black'],
black_white: ['black', 'white']
};
var colorBnb = function () {
// Color factory
@ -46,8 +46,9 @@ var color = function() {
return function (s) {
// next line is for dashed series that should have the same color
s = s.replace('---', '');
if (seen[s] === undefined)
if (seen[s] === undefined) {
seen[s] = Object.keys(seen).length;
}
return this.bnbColors[seen[s] % this.bnbColors.length];
};
};
@ -72,14 +73,13 @@ var color = function() {
return {
bnbColors: bnbColors,
category21: colorBnb(),
colorScalerFactory: colorScalerFactory,
colorScalerFactory: colorScalerFactory
};
};
var px = (function () {
var visualizations = {};
var dashboard;
var slice;
function getParam(name) {
@ -137,7 +137,6 @@ var px = (function() {
var selector = '#' + container_id;
var container = $(selector);
var slice_id = data.slice_id;
var name = data.viz_name;
var dttm = 0;
var stopwatch = function () {
dttm += 10;
@ -212,8 +211,9 @@ var px = (function() {
var others = 0;
var widget = container.parents('.widget');
var slice_description = widget.find('.slice_description');
if (slice_description.is(":visible"))
if (slice_description.is(":visible")) {
others += widget.find('.slice_description').height() + 25;
}
others += widget.find('.slice_header').height();
return widget.height() - others;
},
@ -236,21 +236,25 @@ var px = (function() {
this.viz.resize();
},
addFilter: function (col, vals) {
if (dashboard !== undefined)
if (dashboard !== undefined) {
dashboard.addFilter(slice_id, col, vals);
}
},
setFilter: function (col, vals) {
if (dashboard !== undefined)
if (dashboard !== undefined) {
dashboard.setFilter(slice_id, col, vals);
}
},
clearFilter: function () {
if (dashboard !== undefined)
if (dashboard !== undefined) {
delete dashboard.clearFilter(slice_id);
}
},
removeFilter: function (col, vals) {
if (dashboard !== undefined)
if (dashboard !== undefined) {
delete dashboard.removeFilter(slice_id, col, vals);
},
}
}
};
var visType = data.form_data.viz_type;
px.registerViz(visType);
@ -267,47 +271,10 @@ var px = (function() {
visualizations[name] = visFactory;
}
} else {
console.error("require(", visType, ") failed.");
throw new Error("require(" + name + ") failed.");
}
}
function prepForm() {
var i = 1;
// Assigning the right id to form elements in filters
$("#filters > div").each(function() {
$(this).attr("id", function() {
return "flt_" + i;
});
$(this).find("#flt_col_0")
.attr("id", function() {
return "flt_col_" + i;
})
.attr("name", function() {
return "flt_col_" + i;
});
$(this).find("#flt_op_0")
.attr("id", function() {
return "flt_op_" + i;
})
.attr("name", function() {
return "flt_op_" + i;
});
$(this).find("#flt_eq_0")
.attr("id", function() {
return "flt_eq_" + i;
})
.attr("name", function() {
return "flt_eq_" + i;
});
i++;
});
}
function renderSlice() {
prepForm();
slice.render();
}
// Export public functions
return {
registerViz: registerViz,
@ -315,7 +282,7 @@ var px = (function() {
formatDate: formatDate,
timeFormatFactory: timeFormatFactory,
color: color(),
getParam: getParam,
getParam: getParam
};
})();

View File

@ -22,11 +22,11 @@ $(document).ready(function() {
editor.$blockScrolling = Infinity;
editor.getSession().setUseWrapMode(true);
var textarea = $('#sql').hide();
$('#sql').hide();
editor.setTheme("ace/theme/crimson_editor");
editor.setOptions({
minLines: 16,
maxLines: Infinity,
maxLines: Infinity
});
editor.getSession().setMode("ace/mode/sql");
editor.focus();
@ -44,16 +44,18 @@ $(document).ready(function() {
alert("Not implemented");
});
$(".sqlcontent").show();
$("#select_star").click(function() {
function selectStarOnClick() {
$.ajax('/panoramix/select_star/' + database_id + '/' + $("#dbtable").val() + '/')
.done(function (msg) {
editor.setValue(msg);
});
});
}
$("#select_star").click(selectStarOnClick);
editor.setValue(getParam('sql'));
$(window).bind("popstate", function (event) {
// Browser back button
var returnLocation = history.location || document.location;
// Could do something more lightweight here, but we're not optimizing
// for the use of the back button anyways
editor.setValue(getParam('sql'));
@ -67,9 +69,9 @@ $(document).ready(function() {
type: "POST",
url: '/panoramix/runsql/',
data: {
'data': JSON.stringify({
'database_id': $('#database_id').val(),
'sql': editor.getSession().getValue(),
data: JSON.stringify({
database_id: $('#database_id').val(),
sql: editor.getSession().getValue()
})
},
success: function (data) {
@ -77,17 +79,17 @@ $(document).ready(function() {
$('#results').show(0);
$('#results').html(data);
var datatable = $('table.sql_results').DataTable({
$('table.sql_results').DataTable({
paging: false,
searching: true,
aaSorting: [],
aaSorting: []
});
},
error: function (err, err2) {
$('#loading').hide(0);
$('#results').show(0);
$('#results').html(err.responseText);
},
}
});
});
}

View File

@ -2,7 +2,7 @@ var $ = window.$ = require('jquery');
var jQuery = window.jQuery = $;
var px = require('./modules/panoramix.js');
require('bootstrap')
require('bootstrap');
$(document).ready(function () {
var slice;

View File

@ -9,7 +9,9 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack -d --watch --colors",
"prod": "webpack -p --colors"
"prod": "webpack -p --colors",
"lint": "npm run --silent lint:js",
"lint:js": "eslint --ignore-path=.eslintignore --ext .js .; exit 0;"
},
"repository": {
"type": "git",
@ -65,6 +67,7 @@
},
"devDependencies": {
"css-loader": "^0.23.1",
"eslint": "^2.2.0",
"style-loader": "^0.13.0"
}
}

View File

@ -7,7 +7,6 @@ require('./big_number.css');
var px = require('../javascripts/modules/panoramix.js');
function bigNumberVis(slice) {
var data_attribute = slice.data;
var div = d3.select(slice.selector);
function render() {
@ -20,8 +19,6 @@ function bigNumberVis(slice) {
var fd = payload.form_data;
var json = payload.data;
var color_range = [-1, 1];
var compare_pos = -23;
var target_url = 'd3js.org';
var f = d3.format(fd.y_axis_format);
var fp = d3.format('+.1%');
@ -66,7 +63,8 @@ function bigNumberVis(slice) {
//Drawing trend line
var g = svg.append('g');
var path = g.append('path')
g.append('path')
.attr('d', function (d) {
return line(data);
})
@ -157,7 +155,7 @@ function bigNumberVis(slice) {
return {
render: render,
resize: render,
resize: render
};
}

View File

@ -29,7 +29,7 @@ function directedForceVis(slice) {
link.target = nodes[link.target] || (nodes[link.target] = {
name: link.target
});
link.value = +link.value;
link.value = Number(link.value);
var target_name = link.target.name;
var source_name = link.source.name;
@ -168,7 +168,7 @@ function directedForceVis(slice) {
};
return {
render: render,
resize: render,
resize: render
};
}

View File

@ -1,4 +1,6 @@
// JS
var $ = window.$ = require('jquery');
var jQuery = window.jQuery = $;
var d3 = window.d3 || require('d3');
// CSS
@ -28,6 +30,7 @@ function filterBox(slice) {
$.getJSON(slice.jsonEndpoint(), function (payload) {
var maxes = {};
for (var filter in payload.data) {
var data = payload.data[filter];
maxes[filter] = d3.max(data, function (d) {
@ -36,9 +39,10 @@ function filterBox(slice) {
var id = 'fltbox__' + filter;
var div = container.append('div');
div.append("label").text(filter);
var sel = div
.append('div')
div.append('div')
.attr('name', filter)
.classed('form-control', true)
.attr('multiple', '')
@ -50,7 +54,13 @@ function filterBox(slice) {
dropdownAutoWidth: true,
data: data,
multiple: true,
formatResult: function(result, container, query, escapeMarkup) {
formatResult: select2Formatter
})
.on('change', fltChanged);
}
slice.done();
function select2Formatter(result, container /*, query, escapeMarkup*/) {
var perc = Math.round((result.metric / maxes[result.filter]) * 100);
var style = 'padding: 2px 5px;';
style += "background-image: ";
@ -59,11 +69,7 @@ function filterBox(slice) {
$(container).attr('style', 'padding: 0px; background: white;');
$(container).addClass('filter_box');
return '<div style="' + style + '"><span>' + result.text + '</span></div>';
},
})
.on('change', fltChanged);
}
slice.done();
})
.fail(function (xhr) {
slice.error(xhr.responseText);
@ -71,7 +77,7 @@ function filterBox(slice) {
};
return {
render: refresh,
resize: refresh,
resize: refresh
};
}

View File

@ -126,21 +126,18 @@ function heatmapVis(slice) {
rect.call(tip);
var xscale_skip = 2;
var yscale_skip = 2;
var xAxis = d3.svg.axis()
.scale(xRbScale)
.tickValues(xRbScale.domain().filter(
function (d, i) {
return !(i % (parseInt(fd.xscale_interval)));
return !(i % (parseInt(fd.xscale_interval, 10)));
}))
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(yRbScale)
.tickValues(yRbScale.domain().filter(
function (d, i) {
return !(i % (parseInt(fd.yscale_interval)));
return !(i % (parseInt(fd.yscale_interval, 10)));
}))
.orient("left");
@ -163,9 +160,6 @@ function heatmapVis(slice) {
var context = canvas.node().getContext("2d");
context.imageSmoothingEnabled = false;
var imageObj;
var imageDim;
var imageScale;
createImageObj();
// Compute the pixel colors; scaled by CSS.
@ -178,10 +172,12 @@ function heatmapVis(slice) {
var x = xScale(d.x);
var y = yScale(d.y);
pixs[x + (y * xScale.domain().length)] = c;
if (matrix[x] === undefined)
if (matrix[x] === undefined) {
matrix[x] = {};
if (matrix[x][y] === undefined)
}
if (matrix[x][y] === undefined) {
matrix[x][y] = d;
}
});
var p = -1;
@ -206,7 +202,7 @@ function heatmapVis(slice) {
}
return {
render: refresh,
resize: refresh,
resize: refresh
};
}

View File

@ -18,7 +18,7 @@ function iframeWidget(slice) {
return {
render: refresh,
resize: refresh,
resize: refresh
};
}

View File

@ -16,7 +16,7 @@ function markupWidget(slice) {
return {
render: refresh,
resize: refresh,
resize: refresh
};
}

View File

@ -1,7 +1,8 @@
// JS
var $ = window.$ || require('jquery');
var d3 = window.d3 || require('d3');
var px = window.px || require('../javascripts/modules/panoramix.js');
require('nvd3');
var nv = require('nvd3');
// CSS
require('../node_modules/nvd3/build/nv.d3.min.css');
@ -9,7 +10,6 @@ require('./nvd3_vis.css');
function nvd3Vis(slice) {
var chart;
var data = {};
var render = function () {
$.getJSON(slice.jsonEndpoint(), function (payload) {
@ -21,7 +21,6 @@ function nvd3Vis(slice) {
nv.addGraph(function () {
switch (viz_type) {
case 'line':
if (fd.show_brush) {
chart = nv.models.lineWithFocusChart();
@ -122,7 +121,7 @@ function nvd3Vis(slice) {
break;
default:
console.error("unrecognized visualization for nvd3", viz_type);
throw new Error("Unrecognized visualization for nvd3" + viz_type);
}
if ("showLegend" in chart && typeof fd.show_legend !== 'undefined') {
@ -151,7 +150,7 @@ function nvd3Vis(slice) {
}
if (viz_type === 'bubble') {
chart.xAxis.tickFormat(d3.format('.3s'));
} else if (fd.x_axis_format == 'smart_date') {
} else if (fd.x_axis_format === 'smart_date') {
chart.xAxis.tickFormat(px.formatDate);
} else if (fd.x_axis_format !== undefined) {
chart.xAxis.tickFormat(px.timeFormatFactory(fd.x_axis_format));
@ -160,7 +159,7 @@ function nvd3Vis(slice) {
chart.yAxis.tickFormat(d3.format('.3s'));
}
if (fd.contribution || fd.num_period_compare || viz_type == 'compare') {
if (fd.contribution || fd.num_period_compare || viz_type === 'compare') {
chart.yAxis.tickFormat(d3.format('.3p'));
if (chart.y2Axis !== undefined) {
chart.y2Axis.tickFormat(d3.format('.3p'));
@ -202,7 +201,7 @@ function nvd3Vis(slice) {
return {
render: render,
resize: update,
resize: update
};
}

View File

@ -1,4 +1,5 @@
// JS
var $ = window.$ || require('jquery');
var d3 = window.d3 || require('d3');
d3.parcoords = require('../vendor/parallel_coordinates/d3.parcoords.js');
d3.divgrid = require('../vendor/parallel_coordinates/divgrid.js');
@ -28,7 +29,7 @@ function parallelCoordVis(slice) {
var container = d3.select(slice.selector);
var eff_height = fd.show_datatable ? (slice.height() / 2) : slice.height();
var div = container.append('div')
container.append('div')
.attr('id', 'parcoords_' + slice.container_id)
.style('height', eff_height + 'px')
.classed("parcoords", true);
@ -56,10 +57,10 @@ function parallelCoordVis(slice) {
.classed("parcoords", true)
.selectAll(".row")
.on({
"mouseover": function(d) {
mouseover: function (d) {
parcoords.highlight([d]);
},
"mouseout": parcoords.unhighlight
mouseout: parcoords.unhighlight
});
// update data table on brush event
parcoords.on("brush", function (d) {
@ -68,10 +69,10 @@ function parallelCoordVis(slice) {
.call(grid)
.selectAll(".row")
.on({
"mouseover": function(d) {
mouseover: function (d) {
parcoords.highlight([d]);
},
"mouseout": parcoords.unhighlight
mouseout: parcoords.unhighlight
});
});
}
@ -84,7 +85,7 @@ function parallelCoordVis(slice) {
return {
render: refresh,
resize: refresh,
resize: refresh
};
}

View File

@ -12,10 +12,10 @@ module.exports = function(slice) {
function refresh() {
$.getJSON(slice.jsonEndpoint(), function (json) {
container.html(json.data);
if (form_data.groupby.length == 1) {
if (form_data.groupby.length === 1) {
var table = container.find('table').DataTable({
paging: false,
searching: false,
searching: false
});
table.column('-1').order('desc').draw();
}
@ -26,6 +26,6 @@ module.exports = function(slice) {
}
return {
render: refresh,
resize: refresh,
resize: refresh
};
};

View File

@ -45,15 +45,9 @@ function sankeyVis(slice) {
var nodes = {};
// Compute the distinct nodes from the links.
links.forEach(function (link) {
link.source = nodes[link.source] ||
(nodes[link.source] = {
name: link.source
});
link.target = nodes[link.target] ||
(nodes[link.target] = {
name: link.target
});
link.value = +link.value;
link.source = nodes[link.source] || (nodes[link.source] = { name: link.source });
link.target = nodes[link.target] || (nodes[link.target] = { name: link.target });
link.value = Number(link.value);
});
nodes = d3.values(nodes);
@ -101,7 +95,8 @@ function sankeyVis(slice) {
})
.attr("width", sankey.nodeWidth())
.style("fill", function (d) {
return d.color = px.color.category21(d.name.replace(/ .*/, ""));
d.color = px.color.category21(d.name.replace(/ .*/, ""));
return d.color;
})
.style("stroke", function (d) {
return d3.rgb(d.color).darker(2);
@ -138,7 +133,7 @@ function sankeyVis(slice) {
};
return {
render: render,
resize: render,
resize: render
};
}

View File

@ -1,3 +1,4 @@
var d3 = window.d3 || require('d3');
require('./sunburst.css');
// Modified from http://bl.ocks.org/kerryrodden/7090426
@ -95,7 +96,6 @@ function sunburstVis(slice) {
.style("opacity", 1)
.on("mouseenter", mouseenter);
// Add the mouseleave handler to the bounding circle.
container.select("#container").on("mouseleave", mouseleave);
@ -116,11 +116,13 @@ function sunburstVis(slice) {
.classed("middle", true)
.style("font-size", "50px")
.text(percentageString);
gMiddleText.append("text")
.classed("middle", true)
.style("font-size", "20px")
.attr("y", "25")
.text("m1: " + f(d.m1) + " | m2: " + f(d.m2));
gMiddleText.append("text")
.classed("middle", true)
.style("font-size", "15px")
@ -129,21 +131,8 @@ function sunburstVis(slice) {
var sequenceArray = getAncestors(d);
function breadcrumbPoints(d, i) {
var points = [];
points.push("0,0");
points.push(b.w + ",0");
points.push(b.w + b.t + "," + (b.h / 2));
points.push(b.w + "," + b.h);
points.push("0," + b.h);
if (i > 0) { // Leftmost breadcrumb; don't include 6th vertex.
points.push(b.t + "," + (b.h / 2));
}
return points.join(" ");
}
// Update the breadcrumb trail to show the current sequence and percentage.
function updateBreadcrumbs(nodeArray, percentageString) {
function updateBreadcrumbs(nodeArray) {
var l = [];
for (var i = 0; i < nodeArray.length; i++) {
l.push(nodeArray[i].name);
@ -154,7 +143,7 @@ function sunburstVis(slice) {
.classed("middle", true)
.attr("y", -75);
}
updateBreadcrumbs(sequenceArray, percentageString);
updateBreadcrumbs(sequenceArray);
// Fade all the segments.
arcs.selectAll("path")
@ -210,13 +199,13 @@ function sunburstVis(slice) {
function buildHierarchy(rows) {
var root = {
"name": "root",
"children": []
name: "root",
children: []
};
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var m1 = +row[row.length - 2];
var m2 = +row[row.length - 1];
var m1 = Number(row[row.length - 2]);
var m2 = Number(row[row.length - 1]);
var parts = row.slice(0, row.length - 2);
if (isNaN(m1)) { // e.g. if this is a header row
continue;
@ -230,7 +219,7 @@ function sunburstVis(slice) {
// Not yet at the end of the sequence; move down the tree.
var foundChild = false;
for (var k = 0; k < children.length; k++) {
if (children[k].name == nodeName) {
if (children[k].name === nodeName) {
childNode = children[k];
foundChild = true;
break;
@ -239,8 +228,8 @@ function sunburstVis(slice) {
// If we don't already have a child node for this branch, create it.
if (!foundChild) {
childNode = {
"name": nodeName,
"children": []
name: nodeName,
children: []
};
children.push(childNode);
}
@ -248,9 +237,9 @@ function sunburstVis(slice) {
} else {
// Reached the end of the sequence; create a leaf node.
childNode = {
"name": nodeName,
"m1": m1,
'm2': m2
name: nodeName,
m1: m1,
m2: m2
};
children.push(childNode);
}
@ -278,7 +267,7 @@ function sunburstVis(slice) {
};
return {
render: render,
resize: render,
resize: render
};
}

View File

@ -1,5 +1,6 @@
var $ = window.$ = require('jquery');
var jQuery = window.jQuery = $;
var d3 = require('d3');
require('datatables');
// CSS
@ -13,7 +14,13 @@ function tableVis(slice) {
var fC = d3.format('0,000');
function refresh() {
$.getJSON(slice.jsonEndpoint(), function(json) {
$.getJSON(slice.jsonEndpoint(), onSuccess).fail(onError);
function onError(xhr) {
slice.error(xhr.responseText);
}
function onSuccess(json) {
var data = json.data;
var metrics = json.form_data.metrics;
@ -62,12 +69,14 @@ function tableVis(slice) {
}
})
.attr('title', function (d) {
if (!isNaN(d.val))
if (!isNaN(d.val)) {
return fC(d.val);
}
})
.attr('data-sort', function (d) {
if (d.isMetric)
if (d.isMetric) {
return d.val;
}
})
.on("click", function (d) {
if (!d.isMetric) {
@ -87,14 +96,15 @@ function tableVis(slice) {
}
})
.html(function (d) {
if (d.isMetric)
if (d.isMetric) {
return f(d.val);
else
} else {
return d.val;
}
});
var datatable = slice.container.find('.dataTable').DataTable({
paging: false,
searching: form_data.include_search,
searching: form_data.include_search
});
// Sorting table by main column
if (form_data.metrics.length > 0) {
@ -103,14 +113,12 @@ function tableVis(slice) {
}
slice.done(json);
slice.container.parents('.widget').find('.tooltip').remove();
}).fail(function(xhr) {
slice.error(xhr.responseText);
});
}
}
return {
render: refresh,
resize: function() {},
resize: function () {}
};
}

View File

@ -14,15 +14,15 @@ function wordCloudChart(slice) {
var data = json.data;
var range = [
json.form_data.size_from,
json.form_data.size_to,
json.form_data.size_to
];
var rotation = json.form_data.rotation;
var f_rotation;
if (rotation == "square") {
if (rotation === "square") {
f_rotation = function () {
return ~~(Math.random() * 2) * 90;
};
} else if (rotation == "flat") {
} else if (rotation === "flat") {
f_rotation = function () {
return 0;
};
@ -67,7 +67,7 @@ function wordCloudChart(slice) {
return d.size + "px";
})
.style("font-family", "Impact")
.style("fill", function(d, i) {
.style("fill", function (d) {
return px.color.category21(d.text);
})
.attr("text-anchor", "middle")
@ -84,7 +84,7 @@ function wordCloudChart(slice) {
return {
render: refresh,
resize: refresh,
resize: refresh
};
}

View File

@ -65,7 +65,7 @@ function worldMapChart(slice) {
highlightBorderWidth: 1,
popupTemplate: function (geo, data) {
return '<div class="hoverinfo"><strong>' + data.name + '</strong><br>' + f(data.m1) + '</div>';
},
}
},
bubblesConfig: {
borderWidth: 1,
@ -86,7 +86,7 @@ function worldMapChart(slice) {
highlightFillOpacity: 0.85,
exitDelay: 100,
key: JSON.stringify
},
}
});
map.updateChoropleth(d);
@ -103,7 +103,7 @@ function worldMapChart(slice) {
return {
render: render,
resize: render,
resize: render
};
}

View File

@ -1,6 +1,4 @@
var webpack = require('webpack');
var path = require('path');
var APP_DIR = path.resolve(__dirname, './'); // input
var BUILD_DIR = path.resolve(__dirname, './javascripts/dist'); // output
@ -11,7 +9,7 @@ var config = {
explore: APP_DIR + '/javascripts/explore.js',
featured: APP_DIR + '/javascripts/featured.js',
sql: APP_DIR + '/javascripts/sql.js',
standalone: APP_DIR + '/javascripts/standalone.js',
standalone: APP_DIR + '/javascripts/standalone.js'
},
output: {
path: BUILD_DIR,
@ -29,7 +27,7 @@ var config = {
test: /\.css$/,
//exclude: APP_DIR + '/node_modules',
loader: "style-loader!css-loader" // load css via require('../*.css')
},
}
]
},
plugins: []