Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions devtools/test_dashboard/devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ var Tabs = {

// Set plot config options
setPlotConfig: function() {

// use local topojson files
Plotly.setPlotConfig({ topojsonURL: '../../dist/topojson/' });
Plotly.setPlotConfig({
// use local topojson files
topojsonURL: '../../dist/topojson/',
logging: 2
});
},

// Return the specified plot container (or default one)
Expand Down
3 changes: 2 additions & 1 deletion src/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"Uint8Array": true
},
"rules": {
"strict": [2, "global"]
"strict": [2, "global"],
"no-console": [2]
}
}
2 changes: 1 addition & 1 deletion src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ drawing.fillGroupStyle = function(s) {
shape.call(Color.fill, d[0].trace.fillcolor);
}
catch(e) {
console.log(e, s);
Lib.error(e, s);
shape.remove();
}
});
Expand Down
5 changes: 3 additions & 2 deletions src/components/rangeslider/range_plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

var d3 = require('d3');

var Lib = require('../../lib');
var Symbols = require('../drawing/symbol_defs');
var Drawing = require('../drawing');

Expand Down Expand Up @@ -53,7 +54,7 @@ module.exports = function rangePlot(gd, w, h) {
pointPairs = [];

if(allowedTypes.indexOf(trace.type) < 0) {
console.log('Trace type ' + trace.type + ' not supported for range slider!');
Lib.warn('Trace type ' + trace.type + ' not supported for range slider!');
continue;
}

Expand Down Expand Up @@ -161,7 +162,7 @@ function makeScatter(trace, pointPairs, w, h) {
break;

default:
console.log('Fill type ' + trace.fill + ' not supported for range slider! (yet...)');
Lib.warn('Fill type ' + trace.fill + ' not supported for range slider! (yet...)');
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/shapes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function getShapeLayer(gd, index) {
shapeLayer = gd._fullLayout._shapeUpperLayer;

if(!shape) {
console.log('getShapeLayer: undefined shape: index', index);
Lib.log('getShapeLayer: undefined shape: index', index);
}
else if(shape.layer === 'below') {
shapeLayer = (shape.xref === 'paper' && shape.yref === 'paper') ?
Expand Down Expand Up @@ -491,7 +491,7 @@ shapes.convertPath = function(pathIn, x2p, y2p) {

if(paramNumber > nParams) {
paramString = paramString.replace(/[\s,]*X.*/, '');
console.log('ignoring extra params in segment ' + segment);
Lib.log('Ignoring extra params in segment ' + segment);
}

return segmentType + paramString;
Expand Down
4 changes: 3 additions & 1 deletion src/lib/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
var d3 = require('d3');
var isNumeric = require('fast-isnumeric');

var Lib = require('../lib');


/**
* dateTime2ms - turn a date object or string s of the form
Expand Down Expand Up @@ -122,7 +124,7 @@ function lpad(val, digits) {
*/
exports.ms2DateTime = function(ms, r) {
if(typeof(d3) === 'undefined') {
console.log('d3 is not defined');
Lib.error('d3 is not defined.');
return;
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib/geo_location_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'use strict';

var countryRegex = require('country-regex');
var Lib = require('./');
var Lib = require('../lib');


// make list of all country iso3 ids from at runtime
Expand All @@ -32,8 +32,8 @@ exports.locationToFeature = function(locationmode, location, features) {
if(feature.id === locationId) return feature;
}

console.warn([
'location with id', locationId,
Lib.warn([
'Location with id', locationId,
'does not have a matching topojson feature at this resolution.'
].join(' '));
};
Expand All @@ -53,5 +53,5 @@ function countryNameToISO3(countryName) {
if(regex.test(countryName.toLowerCase())) return iso3;
}

console.warn('unrecognized country name: ' + countryName + '.');
Lib.warn('Unrecognized country name: ' + countryName + '.');
}
41 changes: 8 additions & 33 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ lib.extendFlat = extendModule.extendFlat;
lib.extendDeep = extendModule.extendDeep;
lib.extendDeepAll = extendModule.extendDeepAll;

var loggersModule = require('./loggers');
lib.log = loggersModule.log;
lib.warn = loggersModule.warn;
lib.error = loggersModule.error;

lib.notifier = require('./notifier');

/**
Expand Down Expand Up @@ -92,35 +97,6 @@ lib.pauseEvent = function(e) {
return false;
};

/**
* ------------------------------------------
* debugging tools
* ------------------------------------------
*/

// set VERBOSE to true to get a lot more logging and tracing
lib.VERBOSE = false;

// first markTime call will return time from page load
lib.TIMER = new Date().getTime();

// console.log that only runs if VERBOSE is on
lib.log = function() {
if(lib.VERBOSE) console.log.apply(console, arguments);
};

/**
* markTime - for debugging, mark the number of milliseconds
* since the previous call to markTime and log arbitrary info too
*/
lib.markTime = function(v) {
if(!lib.VERBOSE) return;
var t2 = new Date().getTime();
console.log(v, t2 - lib.TIMER, '(msec)');
if(lib.VERBOSE === 'trace') console.trace();
lib.TIMER = t2;
};

// constrain - restrict a number v to be between v0 and v1
lib.constrain = function(v, v0, v1) {
if(v0 > v1) return Math.max(v1, Math.min(v0, v));
Expand Down Expand Up @@ -271,18 +247,17 @@ lib.syncOrAsync = function(sequence, arg, finalStep) {
var ret, fni;

function continueAsync() {
lib.markTime('async done ' + fni.name);
return lib.syncOrAsync(sequence, arg, finalStep);
}

while(sequence.length) {
fni = sequence.splice(0, 1)[0];
ret = fni(arg);
// lib.markTime('done calling '+fni.name)

if(ret && ret.then) {
return ret.then(continueAsync)
.then(undefined, lib.promiseError);
}
lib.markTime('sync done ' + fni.name);
}

return finalStep && finalStep(arg);
Expand Down Expand Up @@ -433,7 +408,7 @@ lib.addStyleRule = function(selector, styleString) {
else if(styleSheet.addRule) {
styleSheet.addRule(selector, styleString, 0);
}
else console.warn('addStyleRule failed');
else lib.warn('addStyleRule failed');
};

lib.getTranslate = function(element) {
Expand Down
59 changes: 59 additions & 0 deletions src/lib/loggers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

var config = require('../plot_api/plot_config');

var loggers = module.exports = {};

/**
* ------------------------------------------
* debugging tools
* ------------------------------------------
*/

/* eslint-disable no-console */
loggers.log = function() {
if(config.logging > 1) {
var messages = ['LOG:'];

for(var i = 0; i < arguments.length; i++) {
messages.push(arguments[i]);
}

if(console.trace) {
console.trace.apply(console, messages);
} else {
console.log.apply(console, messages);
}
}
};

loggers.warn = function() {
if(config.logging > 0) {
var messages = ['WARN:'];

for(var i = 0; i < arguments.length; i++) {
messages.push(arguments[i]);
}

if(console.trace) {
console.trace.apply(console, messages);
} else {
console.log.apply(console, messages);
}
}
};

loggers.error = function() {
if(config.logging > 0) {
Copy link
Contributor

@n-riesco n-riesco Jun 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No prefix 'ERROR:'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was mainly because console.error marks it red as an error. Should I add it for consistency?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the prefix would be useful for users that want to capture the console and process the messages.

console.error.apply(console, arguments);
}
};
/* eslint-enable no-console */
4 changes: 3 additions & 1 deletion src/lib/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

var isNumeric = require('fast-isnumeric');

var Lib = require('../lib');


/**
* findBin - find the bin for val - note that it can return outside the
Expand Down Expand Up @@ -45,7 +47,7 @@ exports.findBin = function(val, bins, linelow) {
if(test(bins[n], val)) n1 = n + 1;
else n2 = n;
}
if(c > 90) console.log('Long binary search...');
if(c > 90) Lib.log('Long binary search...');
return n1 - 1;
}
};
Expand Down
5 changes: 3 additions & 2 deletions src/lib/svg_text_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
var Plotly = require('../plotly');
var d3 = require('d3');

var Lib = require('../lib');
var xmlnsNamespaces = require('../constants/xmlns_namespaces');

var util = module.exports = {};
Expand All @@ -36,7 +37,7 @@ d3.selection.prototype.appendSVG = function(_svgString) {
childNode = childNode.nextSibling;
}
if(dom.querySelector('parsererror')) {
console.log(dom.querySelector('parsererror div').textContent);
Lib.log(dom.querySelector('parsererror div').textContent);
return null;
}
return d3.select(this.node().lastChild);
Expand Down Expand Up @@ -202,7 +203,7 @@ function texToSVG(_texString, _config, _callback) {
var glyphDefs = d3.select('body').select('#MathJax_SVG_glyphs');

if(tmpDiv.select('.MathJax_SVG').empty() || !tmpDiv.select('svg').node()) {
console.log('There was an error in the tex syntax.', _texString);
Lib.log('There was an error in the tex syntax.', _texString);
_callback();
}
else {
Expand Down
Loading