Permalink
Browse files

Improvement of __DEV__ define for error checking

  • Loading branch information...
1 parent cdd0c0d commit 303140d5e7626dd58b10528df6222ed2a671a6cf @pissang pissang committed Jun 14, 2016
@@ -69,8 +69,10 @@ define(function (require) {
});
});
- if (!visualMapOfThisSeries) {
- throw new Error('Heatmap must use with visualMap');
+ if (__DEV__) {
+ if (!visualMapOfThisSeries) {
+ throw new Error('Heatmap must use with visualMap');
+ }
}
this.group.removeAll();
@@ -90,7 +92,7 @@ define(function (require) {
var yAxis = cartesian.getAxis('y');
var group = this.group;
- if (typeof __DEV__ !== 'undefined') {
+ if (__DEV__) {
if (!(xAxis.type === 'category' && yAxis.type === 'category')) {
throw new Error('Heatmap on cartesian must have two category axes');
}
@@ -29,8 +29,10 @@ define(function(require) {
// If data is undefined
data = data || [];
- if (!zrUtil.isArray(data)) {
- throw new Error('Invalid data.');
+ if (__DEV__) {
+ if (!zrUtil.isArray(data)) {
+ throw new Error('Invalid data.');
+ }
}
var coordSysName = seriesModel.get('coordinateSystem');
@@ -116,8 +118,14 @@ define(function(require) {
cartesian2d: function (data, seriesModel, ecModel) {
var xAxisModel = ecModel.getComponent('xAxis', seriesModel.get('xAxisIndex'));
var yAxisModel = ecModel.getComponent('yAxis', seriesModel.get('yAxisIndex'));
- if (!xAxisModel || !yAxisModel) {
- throw new Error('Axis option not found');
+
+ if (__DEV__) {
+ if (!xAxisModel) {
+ throw new Error('xAxis "' + seriesModel.get('xAxisIndex') + '" not found');
+ }
+ if (!yAxisModel) {
+ throw new Error('yAxis "' + seriesModel.get('yAxisIndex') + '" not found');
+ }
}
var xAxisType = xAxisModel.get('type');
@@ -164,8 +172,13 @@ define(function(require) {
mainType: 'radiusAxis', filter: axisFinder
})[0];
- if (!angleAxisModel || !radiusAxisModel) {
- throw new Error('Axis option not found');
+ if (__DEV__) {
+ if (!angleAxisModel) {
+ throw new Error('angleAxis option not found');
+ }
+ if (!radiusAxisModel) {
+ throw new Error('radiusAxis option not found');
+ }
}
var radiusAxisType = radiusAxisModel.get('type');
@@ -12,6 +12,12 @@ define(function(require) {
dependencies: ['grid', 'polar'],
getInitialData: function (option, ecModel) {
+ if (__DEV__) {
+ var coordSys = option.coordinateSystem;
+ if (coordSys !== 'polar' && coordSys !== 'cartesian2d') {
+ throw new Error('Line not support coordinateSystem besides cartesian and polar');
+ }
+ }
return createListFromArray(option.data, this, ecModel);
},
@@ -26,16 +26,14 @@ define(function (require) {
));
});
- // var coordSys = option.coordinateSystem;
- // if (coordSys !== 'cartesian2d' && coordSys !== 'geo') {
- // throw new Error('Coordinate system can only be cartesian2d or geo in lines');
- // }
-
- // var dimensions = coordSys === 'geo' ? ['lng', 'lat'] : ['x', 'y'];
var coordSys = CoordinateSystem.get(option.coordinateSystem);
- if (!coordSys) {
- throw new Error('Invalid coordinate system');
+
+ if (__DEV__) {
+ if (!coordSys) {
+ throw new Error('Invalid coordinate system');
+ }
}
+
var dimensions = coordSys.dimensions;
var fromData = new List(dimensions, this);
@@ -23,8 +23,11 @@ define(function (require) {
* @overrite
*/
init: function (option, parentModel, ecModel, extraOpt) {
- if (this.type === 'marker') {
- throw new Error('Marker component is abstract component. Use markLine, markPoint, markArea instead.');
+
+ if (__DEV__) {
+ if (this.type === 'marker') {
+ throw new Error('Marker component is abstract component. Use markLine, markPoint, markArea instead.');
+ }
}
this.mergeDefaultAndTheme(option, ecModel);
this.mergeOption(option, ecModel, extraOpt.createdBySelf, true);
@@ -402,7 +402,7 @@ define(function(require, factory) {
var yAxisIndex = seriesModel.get('yAxisIndex');
var xAxisModel = ecModel.getComponent('xAxis', xAxisIndex);
- if (typeof __DEV__ !== 'undefined') {
+ if (__DEV__) {
var yAxisModel = ecModel.getComponent('yAxis', yAxisIndex);
if (xAxisModel.get('gridIndex') !== yAxisModel.get('gridIndex')) {
throw new Error('xAxis and yAxis must use the same grid');
View
@@ -222,8 +222,10 @@ define(function (require) {
listProto.initData = function (data, nameList, dimValueGetter) {
data = data || [];
- if (!zrUtil.isArray(data)) {
- throw new Error('Invalid data.');
+ if (__DEV__) {
+ if (!zrUtil.isArray(data)) {
+ throw new Error('Invalid data.');
+ }
}
this._rawData = data;
View
@@ -1,3 +1,17 @@
+// Enable DEV mode when using source code without build. which has no __DEV__ variable
+// In build process 'typeof __DEV__' will be replace with 'boolean'
+// So this code will be removed or disabled anyway after built.
+if (typeof __DEV__ === 'undefined') {
+ // In browser
+ if (typeof window !== 'undefined') {
+ window.__DEV__ = true;
+ }
+ // In node
+ else if (typeof global !== 'undefined') {
+ global.__DEV__ = true;
+ }
+}
+
/*!
* ECharts, a javascript interactive chart library.
*
@@ -13,6 +27,8 @@
*/
define(function (require) {
+ var env = require('zrender/core/env');
+
var GlobalModel = require('./model/Global');
var ExtensionAPI = require('./ExtensionAPI');
var CoordinateSystemManager = require('./CoordinateSystem');
@@ -28,7 +44,6 @@ define(function (require) {
var zrender = require('zrender');
var zrUtil = require('zrender/core/util');
var colorTool = require('zrender/tool/color');
- var env = require('zrender/core/env');
var Eventful = require('zrender/mixin/Eventful');
var each = zrUtil.each;
@@ -1052,17 +1067,22 @@ define(function (require) {
* @param {Object} opts
*/
echarts.init = function (dom, theme, opts) {
- // Check version
- if ((zrender.version.replace('.', '') - 0) < (echarts.dependencies.zrender.replace('.', '') - 0)) {
- throw new Error(
- 'ZRender ' + zrender.version
- + ' is too old for ECharts ' + echarts.version
- + '. Current version need ZRender '
- + echarts.dependencies.zrender + '+'
- );
- }
- if (!dom) {
- throw new Error('Initialize failed: invalid dom.');
+ if (__DEV__) {
+ // Check version
+ if ((zrender.version.replace('.', '') - 0) < (echarts.dependencies.zrender.replace('.', '') - 0)) {
+ throw new Error(
+ 'ZRender ' + zrender.version
+ + ' is too old for ECharts ' + echarts.version
+ + '. Current version need ZRender '
+ + echarts.dependencies.zrender + '+'
+ );
+ }
+ if (!dom) {
+ throw new Error('Initialize failed: invalid dom.');
+ }
+ if (!dom.clientWidth || !dom.clientHeight) {
+ console.error('Can\'t get dom width or height');
+ }
}
var chart = new ECharts(dom, theme, opts);
@@ -1163,8 +1183,10 @@ define(function (require) {
processorFunc = priority;
priority = PRIORITY_PROCESSOR_FILTER;
}
- if (isNaN(priority)) {
- throw new Error('Unkown processor priority');
+ if (__DEV__) {
+ if (isNaN(priority)) {
+ throw new Error('Unkown processor priority');
+ }
}
dataProcessorFuncs.push({
prio: priority,
@@ -1230,8 +1252,10 @@ define(function (require) {
layoutFunc = priority;
priority = PRIORITY_VISUAL_LAYOUT;
}
- if (isNaN(priority)) {
- throw new Error('Unkown layout priority');
+ if (__DEV__) {
+ if (isNaN(priority)) {
+ throw new Error('Unkown layout priority');
+ }
}
visualFuncs.push({
prio: priority,
@@ -1249,8 +1273,10 @@ define(function (require) {
visualFunc = priority;
priority = PRIORITY_VISUAL_CHART;
}
- if (isNaN(priority)) {
- throw new Error('Unkown visual priority');
+ if (__DEV__) {
+ if (isNaN(priority)) {
+ throw new Error('Unkown visual priority');
+ }
}
visualFuncs.push({
prio: priority,
View
@@ -743,8 +743,10 @@ define(function (require) {
function assertSeriesInitialized(ecModel) {
// Components that use _seriesIndices should depends on series component,
// which make sure that their initialization is after series.
- if (!ecModel._seriesIndices) {
- throw new Error('Series has not been initialized yet.');
+ if (__DEV__) {
+ if (!ecModel._seriesIndices) {
+ throw new Error('Series has not been initialized yet.');
+ }
}
}
View
@@ -79,8 +79,10 @@ define(function (require) {
componentType = parseClassType(componentType);
if (!componentType.sub) {
- if (storage[componentType.main]) {
- throw new Error(componentType.main + ' exists.');
+ if (__DEV__) {
+ if (storage[componentType.main]) {
+ console.warn(componentType.main + ' exists.');
+ }
}
storage[componentType.main] = Clazz;
}
View
@@ -4,7 +4,8 @@ var webpack = require('webpack');
module.exports = {
plugins: [
new webpack.DefinePlugin({
- 'typeof __DEV__': JSON.stringify(PROD ? 'undefined' : 'boolean')
+ 'typeof __DEV__': JSON.stringify('boolean'),
+ __DEV__: PROD ? false : true
})
],
entry: {

0 comments on commit 303140d

Please sign in to comment.