Skip to content

Commit f417417

Browse files
committed
Refs #153; Replace custom checks with Epoch.isNonEmptyArray where applicable.
1 parent 8235849 commit f417417

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

src/data.coffee

+5-5
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Epoch.Data.Format.array = (->
6969
return result
7070

7171
format = (data=[], options={}) ->
72-
return [] unless Epoch.isArray(data) and data.length > 0
72+
return [] unless Epoch.isNonEmptyArray(data)
7373
opt = Epoch.Util.defaults options, defaultOptions
7474

7575
if opt.type == 'time.heatmap'
@@ -137,7 +137,7 @@ Epoch.Data.Format.tuple = (->
137137
return result
138138

139139
format = (data=[], options={}) ->
140-
return [] unless Epoch.isArray(data) and data.length > 0
140+
return [] unless Epoch.isNonEmptyArray(data)
141141
opt = Epoch.Util.defaults options, defaultOptions
142142

143143
if opt.type == 'pie' or opt.type == 'time.heatmap' or opt.type == 'time.gauge'
@@ -224,7 +224,7 @@ Epoch.Data.Format.keyvalue = (->
224224
value
225225

226226
format = (data=[], keys=[], options={}) ->
227-
return [] unless Epoch.isArray(data) and data.length > 0 and keys.length > 0
227+
return [] unless Epoch.isNonEmptyArray(data) and Epoch.isNonEmptyArray(keys)
228228
opt = Epoch.Util.defaults options, defaultOptions
229229

230230
if opt.type == 'pie' or opt.type == 'time.gauge'
@@ -237,7 +237,7 @@ Epoch.Data.Format.keyvalue = (->
237237
formatBasicPlot data, keys, opt
238238

239239
format.entry = (datum, keys=[], options={}) ->
240-
return [] unless datum? and keys? and keys.length > 0
240+
return [] unless datum? and Epoch.isNonEmptyArray(keys)
241241
unless options.startTime?
242242
options.startTime = parseInt(new Date().getTime() / 1000)
243243
(layer.values[0] for layer in format([datum], keys, options))
@@ -258,7 +258,7 @@ Epoch.data = (formatter, args...) ->
258258
# Abstracted here because we'd like to allow models and indivisual charts to
259259
# perform this action depending on the context.
260260
Epoch.Data.formatData = (data=[], type, dataFormat) ->
261-
return data unless dataFormat? and data.length > 0
261+
return data unless Epoch.isNonEmptyArray(data)
262262

263263
if Epoch.isString(dataFormat)
264264
opts = { type: type }

src/time.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class Epoch.Time.Plot extends Epoch.Chart.Canvas
196196
@topAxis.selectAll('.tick').remove() if @topAxis?
197197

198198
for layer in @data
199-
continue unless layer.values? and layer.values.length > 0
199+
continue unless Epoch.isNonEmptyArray(layer.values)
200200
[i, k] = [@options.windowSize-1, layer.values.length-1]
201201
while i >= 0 and k >= 0
202202
@_pushTick i, layer.values[k].time, false, true

src/time/bar.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Epoch.Time.Bar extends Epoch.Time.Stack
2929
[y, w] = [@y(), @w()]
3030

3131
for layer in @getVisibleLayers()
32-
continue unless layer.values.length > 0
32+
continue unless Epoch.isNonEmptyArray(layer.values)
3333
@setStyles(layer.className)
3434

3535
[i, k, trans] = [@options.windowSize, layer.values.length, @inTransition()]
@@ -43,5 +43,5 @@ class Epoch.Time.Bar extends Epoch.Time.Stack
4343

4444
@ctx.fillRect.apply(@ctx, args)
4545
@ctx.strokeRect.apply(@ctx, args)
46-
46+
4747
super()

src/time/heatmap.coffee

+1-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ class Epoch.Time.Heatmap extends Epoch.Time.Plot
141141

142142
# Redraws the entire heatmap for the current data.
143143
redraw: ->
144-
return unless Epoch.isArray(@data) and @data.length > 0 and @data[0].values? and @data[0].values.length > 0
145-
144+
return unless Epoch.isNonEmptyArray(@data) and Epoch.isNonEmptyArray(@data[0].values)
146145
entryIndex = @data[0].values.length
147146
drawColumn = @options.windowSize
148147

src/time/line.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Epoch.Time.Line extends Epoch.Time.Plot
1919
[y, w] = [@y(), @w()]
2020

2121
for layer in @getVisibleLayers()
22-
continue unless layer.values.length > 0
22+
continue unless Epoch.isNonEmptyArray(layer.values)
2323
@setStyles(layer.className)
2424
@ctx.beginPath()
2525

tests/unit/core/is.coffee

+3
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,8 @@ describe 'Epoch.Util', ->
8181
assert.notOk Epoch.isNonEmptyArray({})
8282
assert.notOk Epoch.isNonEmptyArray(->)
8383

84+
it 'should return false given a null value', ->
85+
assert.notOk Epoch.isNonEmptyArray(null)
86+
8487
it 'should return false given an empty array', ->
8588
assert.notOk Epoch.isNonEmptyArray([])

0 commit comments

Comments
 (0)