Skip to content

Commit 873f3ae

Browse files
committed
lib: rm circular deps
by: - not requiring Lib into plot_config.js to log error - rm useless Lib.log in lib/dates.js - require lib/loggers.js directly instead of Lib in lib/search.js
1 parent 5ee3c29 commit 873f3ae

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

src/lib/dates.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
var d3 = require('d3');
1313
var isNumeric = require('fast-isnumeric');
1414

15-
var Lib = require('../lib');
16-
1715

1816
/**
1917
* dateTime2ms - turn a date object or string s of the form
@@ -123,14 +121,11 @@ function lpad(val, digits) {
123121
* If rng is big, the later parts of time will be omitted
124122
*/
125123
exports.ms2DateTime = function(ms, r) {
126-
if(typeof(d3) === 'undefined') {
127-
Lib.error('d3 is not defined.');
128-
return;
129-
}
130-
131124
if(!r) r = 0;
125+
132126
var d = new Date(ms),
133127
s = d3.time.format('%Y-%m-%d')(d);
128+
134129
if(r < 7776000000) {
135130
// <90 days: add hours
136131
s += ' ' + lpad(d.getHours(), 2);

src/lib/loggers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
'use strict';
1010

11+
/* eslint-disable no-console */
12+
1113
var config = require('../plot_api/plot_config');
1214

1315
var loggers = module.exports = {};
@@ -18,7 +20,6 @@ var loggers = module.exports = {};
1820
* ------------------------------------------
1921
*/
2022

21-
/* eslint-disable no-console */
2223
loggers.log = function() {
2324
if(config.logging > 1) {
2425
var messages = ['LOG:'];
@@ -62,4 +63,3 @@ loggers.error = function() {
6263
console.error.apply(console, arguments);
6364
}
6465
};
65-
/* eslint-enable no-console */

src/lib/search.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
'use strict';
1111

1212
var isNumeric = require('fast-isnumeric');
13-
14-
var Lib = require('../lib');
13+
var loggers = require('./loggers');
1514

1615

1716
/**
@@ -47,7 +46,7 @@ exports.findBin = function(val, bins, linelow) {
4746
if(test(bins[n], val)) n1 = n + 1;
4847
else n2 = n;
4948
}
50-
if(c > 90) Lib.log('Long binary search...');
49+
if(c > 90) loggers.log('Long binary search...');
5150
return n1 - 1;
5251
}
5352
};

src/plot_api/plot_config.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
'use strict';
1010

11-
var Lib = require('../lib');
11+
/* eslint-disable no-console */
1212

1313
/**
1414
* This will be transferred over to gd and overridden by
@@ -98,10 +98,14 @@ module.exports = {
9898
};
9999

100100
// where and how the background gets set can be overridden by context
101-
// so we define the default (plotlyjs) behavior here
101+
// so we define the default (plotly.js) behavior here
102102
function defaultSetBackground(gd, bgColor) {
103103
try {
104104
gd._fullLayout._paper.style('background', bgColor);
105105
}
106-
catch(e) { Lib.error(e); }
106+
catch(e) {
107+
if(module.exports.logging > 0) {
108+
console.error(e);
109+
}
110+
}
107111
}

0 commit comments

Comments
 (0)