mirror of
https://github.com/morrisjs/morris.js.git
synced 2026-04-23 03:00:56 -04:00
Tidy up use of "is/isnt null" using ? operator.
This commit is contained in:
@@ -61,7 +61,7 @@ class Morris.Bar extends Morris.Grid
|
||||
for row, idx in @data
|
||||
row._x = @left + @width * (idx + 0.5) / @data.length
|
||||
row._y = for y in row.y
|
||||
if y is null then null else @transY(y)
|
||||
if y? then @transY(y) else null
|
||||
|
||||
# calculate hover margins
|
||||
#
|
||||
@@ -94,7 +94,7 @@ class Morris.Bar extends Morris.Grid
|
||||
labelBox = label.getBBox()
|
||||
# ensure a minimum of `xLabelMargin` pixels between labels, and ensure
|
||||
# labels don't overflow the container
|
||||
if (prevLabelMargin is null or prevLabelMargin >= labelBox.x + labelBox.width) and
|
||||
if (not prevLabelMargin? or prevLabelMargin >= labelBox.x + labelBox.width) and
|
||||
labelBox.x >= 0 and (labelBox.x + labelBox.width) < @el.width()
|
||||
prevLabelMargin = labelBox.x - xLabelMargin
|
||||
else
|
||||
@@ -178,7 +178,7 @@ class Morris.Bar extends Morris.Grid
|
||||
if index isnt null and @prevHilight isnt index
|
||||
@updateHover index
|
||||
@prevHilight = index
|
||||
if index is null
|
||||
if not index?
|
||||
@hideHover()
|
||||
|
||||
# @private
|
||||
|
||||
@@ -23,9 +23,7 @@ class Morris.EventEmitter
|
||||
# @example
|
||||
# Morris.commas(1234567) -> '1,234,567'
|
||||
Morris.commas = (num) ->
|
||||
if num is null
|
||||
"-"
|
||||
else
|
||||
if num?
|
||||
ret = if num < 0 then "-" else ""
|
||||
absnum = Math.abs(num)
|
||||
intnum = Math.floor(absnum).toFixed(0)
|
||||
@@ -34,6 +32,8 @@ Morris.commas = (num) ->
|
||||
if strabsnum.length > intnum.length
|
||||
ret += strabsnum.slice(intnum.length)
|
||||
ret
|
||||
else
|
||||
'-'
|
||||
|
||||
# Zero-pad numbers to two characters wide.
|
||||
#
|
||||
|
||||
@@ -9,7 +9,7 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
@el = $ document.getElementById(options.element)
|
||||
else
|
||||
@el = $ options.element
|
||||
if @el is null or @el.length == 0
|
||||
if not @el? or @el.length == 0
|
||||
throw new Error("Graph container element not found")
|
||||
|
||||
@options = $.extend {}, @gridDefaults, (@defaults || {}), options
|
||||
@@ -77,8 +77,8 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
if @options.goals.length > 0
|
||||
minGoal = Math.min.apply(null, @options.goals)
|
||||
maxGoal = Math.max.apply(null, @options.goals)
|
||||
ymin = if ymin is null then minGoal else Math.min(ymin, minGoal)
|
||||
ymax = if ymax is null then maxGoal else Math.max(ymax, maxGoal)
|
||||
ymin = if ymin? then Math.min(ymin, minGoal) else minGoal
|
||||
ymax = if ymax? then Math.max(ymax, maxGoal) else maxGoal
|
||||
|
||||
@data = for row, index in data
|
||||
ret = {}
|
||||
@@ -96,16 +96,16 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
yval = row[ykey]
|
||||
yval = parseFloat(yval) if typeof yval is 'string'
|
||||
yval = null unless typeof yval is 'number'
|
||||
unless yval is null
|
||||
if yval?
|
||||
if @cumulative
|
||||
total += yval
|
||||
else
|
||||
if ymax is null
|
||||
ymax = ymin = yval
|
||||
else
|
||||
if ymax?
|
||||
ymax = Math.max(yval, ymax)
|
||||
ymin = Math.min(yval, ymin)
|
||||
if @cumulative and total isnt null
|
||||
else
|
||||
ymax = ymin = yval
|
||||
if @cumulative and total?
|
||||
ymax = Math.max(total, ymax)
|
||||
ymin = Math.min(total, ymin)
|
||||
yval
|
||||
@@ -134,9 +134,9 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
# use Array.concat to flatten arrays and find the max y value
|
||||
if @options.ymax.length > 5
|
||||
@ymax = parseInt(@options.ymax[5..], 10)
|
||||
@ymax = Math.max(ymax, @ymax) unless ymax is null
|
||||
@ymax = Math.max(ymax, @ymax) if ymax?
|
||||
else
|
||||
@ymax = if ymax isnt null then ymax else 0
|
||||
@ymax = if ymax? then ymax else 0
|
||||
else
|
||||
@ymax = parseInt(@options.ymax, 10)
|
||||
else
|
||||
@@ -145,7 +145,7 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
if @options.ymin[0..3] is 'auto'
|
||||
if @options.ymin.length > 5
|
||||
@ymin = parseInt(@options.ymin[5..], 10)
|
||||
@ymin = Math.min(ymin, @ymin) unless ymin is null
|
||||
@ymin = Math.min(ymin, @ymin) if ymin?
|
||||
else
|
||||
@ymin = if ymin isnt null then ymin else 0
|
||||
else
|
||||
|
||||
@@ -70,10 +70,7 @@ class Morris.Line extends Morris.Grid
|
||||
for row in @data
|
||||
row._x = @transX(row.x)
|
||||
row._y = for y in row.y
|
||||
if y is null
|
||||
null
|
||||
else
|
||||
@transY(y)
|
||||
if y? then @transY(y) else null
|
||||
|
||||
# calculate hover margins
|
||||
#
|
||||
@@ -116,7 +113,7 @@ class Morris.Line extends Morris.Grid
|
||||
labelBox = label.getBBox()
|
||||
# ensure a minimum of `xLabelMargin` pixels between labels, and ensure
|
||||
# labels don't overflow the container
|
||||
if (prevLabelMargin is null or prevLabelMargin >= labelBox.x + labelBox.width) and
|
||||
if (not prevLabelMargin? or prevLabelMargin >= labelBox.x + labelBox.width) and
|
||||
labelBox.x >= 0 and (labelBox.x + labelBox.width) < @el.width()
|
||||
prevLabelMargin = labelBox.x - xLabelMargin
|
||||
else
|
||||
@@ -179,7 +176,7 @@ class Morris.Line extends Morris.Grid
|
||||
y2 = Math.min(@bottom, c.y - ix * g)
|
||||
path += "C#{x1},#{y1},#{x2},#{y2},#{c.x},#{c.y}"
|
||||
else
|
||||
path = "M" + $.map(coords, (c) -> "#{c.x},#{c.y}").join("L")
|
||||
path = "M" + ("#{c.x},#{c.y}" for c in coords).join("L")
|
||||
return path
|
||||
|
||||
# calculate a gradient at each point for a series of points
|
||||
@@ -261,7 +258,7 @@ class Morris.Line extends Morris.Grid
|
||||
@seriesPoints[i][index].animate @pointGrow
|
||||
@updateHover index
|
||||
@prevHilight = index
|
||||
if index is null
|
||||
if not index?
|
||||
@hideHover()
|
||||
|
||||
# @private
|
||||
|
||||
60
morris.js
60
morris.js
@@ -44,9 +44,7 @@
|
||||
|
||||
Morris.commas = function(num) {
|
||||
var absnum, intnum, ret, strabsnum;
|
||||
if (num === null) {
|
||||
return "-";
|
||||
} else {
|
||||
if (num != null) {
|
||||
ret = num < 0 ? "-" : "";
|
||||
absnum = Math.abs(num);
|
||||
intnum = Math.floor(absnum).toFixed(0);
|
||||
@@ -56,6 +54,8 @@
|
||||
ret += strabsnum.slice(intnum.length);
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
return '-';
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
} else {
|
||||
this.el = $(options.element);
|
||||
}
|
||||
if (this.el === null || this.el.length === 0) {
|
||||
if (!(this.el != null) || this.el.length === 0) {
|
||||
throw new Error("Graph container element not found");
|
||||
}
|
||||
this.options = $.extend({}, this.gridDefaults, this.defaults || {}, options);
|
||||
@@ -124,8 +124,8 @@
|
||||
if (this.options.goals.length > 0) {
|
||||
minGoal = Math.min.apply(null, this.options.goals);
|
||||
maxGoal = Math.max.apply(null, this.options.goals);
|
||||
ymin = ymin === null ? minGoal : Math.min(ymin, minGoal);
|
||||
ymax = ymax === null ? maxGoal : Math.max(ymax, maxGoal);
|
||||
ymin = ymin != null ? Math.min(ymin, minGoal) : minGoal;
|
||||
ymax = ymax != null ? Math.max(ymax, maxGoal) : maxGoal;
|
||||
}
|
||||
this.data = (function() {
|
||||
var _i, _len, _results;
|
||||
@@ -158,19 +158,19 @@
|
||||
if (typeof yval !== 'number') {
|
||||
yval = null;
|
||||
}
|
||||
if (yval !== null) {
|
||||
if (yval != null) {
|
||||
if (this.cumulative) {
|
||||
total += yval;
|
||||
} else {
|
||||
if (ymax === null) {
|
||||
ymax = ymin = yval;
|
||||
} else {
|
||||
if (ymax != null) {
|
||||
ymax = Math.max(yval, ymax);
|
||||
ymin = Math.min(yval, ymin);
|
||||
} else {
|
||||
ymax = ymin = yval;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.cumulative && total !== null) {
|
||||
if (this.cumulative && (total != null)) {
|
||||
ymax = Math.max(total, ymax);
|
||||
ymin = Math.min(total, ymin);
|
||||
}
|
||||
@@ -212,11 +212,11 @@
|
||||
if (this.options.ymax.slice(0, 4) === 'auto') {
|
||||
if (this.options.ymax.length > 5) {
|
||||
this.ymax = parseInt(this.options.ymax.slice(5), 10);
|
||||
if (ymax !== null) {
|
||||
if (ymax != null) {
|
||||
this.ymax = Math.max(ymax, this.ymax);
|
||||
}
|
||||
} else {
|
||||
this.ymax = ymax !== null ? ymax : 0;
|
||||
this.ymax = ymax != null ? ymax : 0;
|
||||
}
|
||||
} else {
|
||||
this.ymax = parseInt(this.options.ymax, 10);
|
||||
@@ -228,7 +228,7 @@
|
||||
if (this.options.ymin.slice(0, 4) === 'auto') {
|
||||
if (this.options.ymin.length > 5) {
|
||||
this.ymin = parseInt(this.options.ymin.slice(5), 10);
|
||||
if (ymin !== null) {
|
||||
if (ymin != null) {
|
||||
this.ymin = Math.min(ymin, this.ymin);
|
||||
}
|
||||
} else {
|
||||
@@ -506,10 +506,10 @@
|
||||
_results1 = [];
|
||||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||
y = _ref1[_j];
|
||||
if (y === null) {
|
||||
_results1.push(null);
|
||||
} else {
|
||||
if (y != null) {
|
||||
_results1.push(this.transY(y));
|
||||
} else {
|
||||
_results1.push(null);
|
||||
}
|
||||
}
|
||||
return _results1;
|
||||
@@ -581,7 +581,7 @@
|
||||
var label, labelBox;
|
||||
label = _this.r.text(_this.transX(xpos), ypos, labelText).attr('font-size', _this.options.gridTextSize).attr('fill', _this.options.gridTextColor);
|
||||
labelBox = label.getBBox();
|
||||
if ((prevLabelMargin === null || prevLabelMargin >= labelBox.x + labelBox.width) && labelBox.x >= 0 && (labelBox.x + labelBox.width) < _this.el.width()) {
|
||||
if ((!(prevLabelMargin != null) || prevLabelMargin >= labelBox.x + labelBox.width) && labelBox.x >= 0 && (labelBox.x + labelBox.width) < _this.el.width()) {
|
||||
return prevLabelMargin = labelBox.x - xLabelMargin;
|
||||
} else {
|
||||
return label.remove();
|
||||
@@ -673,9 +673,15 @@
|
||||
}
|
||||
}
|
||||
} else {
|
||||
path = "M" + $.map(coords, function(c) {
|
||||
return "" + c.x + "," + c.y;
|
||||
}).join("L");
|
||||
path = "M" + ((function() {
|
||||
var _j, _len, _results;
|
||||
_results = [];
|
||||
for (_j = 0, _len = coords.length; _j < _len; _j++) {
|
||||
c = coords[_j];
|
||||
_results.push("" + c.x + "," + c.y);
|
||||
}
|
||||
return _results;
|
||||
})()).join("L");
|
||||
}
|
||||
return path;
|
||||
};
|
||||
@@ -784,7 +790,7 @@
|
||||
this.updateHover(index);
|
||||
}
|
||||
this.prevHilight = index;
|
||||
if (index === null) {
|
||||
if (!(index != null)) {
|
||||
return this.hideHover();
|
||||
}
|
||||
};
|
||||
@@ -1069,10 +1075,10 @@
|
||||
_results1 = [];
|
||||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||
y = _ref1[_j];
|
||||
if (y === null) {
|
||||
_results1.push(null);
|
||||
} else {
|
||||
if (y != null) {
|
||||
_results1.push(this.transY(y));
|
||||
} else {
|
||||
_results1.push(null);
|
||||
}
|
||||
}
|
||||
return _results1;
|
||||
@@ -1110,7 +1116,7 @@
|
||||
row = this.data[this.data.length - 1 - i];
|
||||
label = this.r.text(row._x, ypos, row.label).attr('font-size', this.options.gridTextSize).attr('fill', this.options.gridTextColor);
|
||||
labelBox = label.getBBox();
|
||||
if ((prevLabelMargin === null || prevLabelMargin >= labelBox.x + labelBox.width) && labelBox.x >= 0 && (labelBox.x + labelBox.width) < this.el.width()) {
|
||||
if ((!(prevLabelMargin != null) || prevLabelMargin >= labelBox.x + labelBox.width) && labelBox.x >= 0 && (labelBox.x + labelBox.width) < this.el.width()) {
|
||||
_results.push(prevLabelMargin = labelBox.x - xLabelMargin);
|
||||
} else {
|
||||
_results.push(label.remove());
|
||||
@@ -1216,7 +1222,7 @@
|
||||
this.updateHover(index);
|
||||
}
|
||||
this.prevHilight = index;
|
||||
if (index === null) {
|
||||
if (!(index != null)) {
|
||||
return this.hideHover();
|
||||
}
|
||||
};
|
||||
|
||||
2
morris.min.js
vendored
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user