Skip to content

Commit

Permalink
Merge pull request #2713 from doug-salvati/ds2609
Browse files Browse the repository at this point in the history
Detect when vis fails to render 2.0
  • Loading branch information
doug-salvati authored Oct 12, 2017
2 parents efb975d + 94dbc51 commit 82c4aed
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
<div class="item-desc item-photo-desc">
<div class="item-title word-wrap">
Data Set: {{d_name}} ({{d_id}})
<i class="fa fa-search-plus"></i> Data Set: {{d_name}} ({{d_id}})
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/visualizations/highvis/bar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ $ ->
super(@canvas)

start: ->
# Validate fields exist
if @validate_fields(true) is -4
window.location = '/'

@configs.analysisType ?= @ANALYSISTYPE_TOTAL
@configs.histogramDensity ?= false

Expand Down
50 changes: 50 additions & 0 deletions app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,56 @@ $ ->
analysisTypeNames: ['Total', 'Maximum', 'Mininum', 'Mean (Average)',
'Mean with Deviation', 'Mean with 2 SEM', 'Median', 'Row Count']

###
Makes sure default fields are still in existence
Return values:
0 -> Everything checks out.
There is a field selected and it exists.
-1 -> There is no field selected.
This is not ALWAYS an error, think about table.
-2 -> There is a field selected which does not exist.
User needs to reset their defaults.
-3 -> Case -1 occurred but the problem could not be
auto-fixed.
-4 -> Case -2 occurred but the problem could not be
auto-fixed. This case could cause serious prolems
and should be handled.
###
validate_fields: (should_fix_problem) ->
fieldIds = for field in data.fields
field.fieldID
l = globals.configs.fieldSelection.length

for id in globals.configs.fieldSelectionIds
if not (id in fieldIds)
if should_fix_problem
# Choose the first normal field
idx = data.normalFields.slice(1)[0]
id = fieldIds[idx]
if not id?
alert "A critical error has occured and the chart can't be drawn.\nIf you are the owner,
please login and reset your defaults.\nYou probably deleted a field."
return -4
else
globals.configs.fieldSelection = [idx]
globals.configs.fieldSelectionIds = [id]
alert "The default field that you chose has been removed from the project, so a different
one was selected. If you are the owner, consider clicking 'Make Default' in the Save menu to reset."
return -2

if l is 0
if should_fix_problem
# Choose the first normal field
idx = data.normalFields.slice(1)[0]
id = fieldIds[idx]
if not id?
return -3
else
globals.configs.fieldSelection = [idx]
globals.configs.fieldSelectionIds = [id]
return -1
return 0

###
Start sequence used by runtime
###
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/visualizations/highvis/box.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ $ ->
@configs.whiskerMode ?= 'iqr'

start: ->
# Validate fields exist
if @validate_fields(true) is -4
window.location = '/'

@configs.displayField = Math.min globals.configs.fieldSelection...
super()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ $ ->
updatedTooltips: false

start: ->
# Validate fields exist
if @validate_fields(true) is -4
window.location = '/'

@configs.displayField = Math.min globals.configs.fieldSelection...
@configs.binSize ?= @defaultBinSize()
super()
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/visualizations/highvis/map.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ $ ->
delete @timeLines

start: ->
# Validate fields exist
if @validate_fields(true) is -4
window.location = '/'

$('#compass').show()

# Map needs this canvas visible to draw correctly
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/visualizations/highvis/photos.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ $ ->
constructor: (@canvas) ->

start: ->
# Validate fields exist
if @validate_fields(true) is -4
window.location = '/'

super()

# Photos doesn't have any fancy group by options, so set it to a default
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/visualizations/highvis/pie.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ $ ->
else 'Percent'

start: () ->
# Validate fields exist
if @validate_fields(true) is -4
window.location = '/'

@configs.displayField = Math.min globals.configs.fieldSelection...
@configs.analysisType ?= @ANALYSISTYPE_TOTAL
super()
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/visualizations/highvis/summary.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ $ ->
@isSummary = true

start: ->
# Validate fields exist
if @validate_fields(true) is -4
window.location = '/'

@configs.displayField = Math.min(globals.configs.fieldSelection...)
super()

Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/visualizations/highvis/table.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ $ ->
globals.dateFormatter cellvalue

start: ->
# Validate fields exist
if @validate_fields(true) is -4
window.location = '/'

# Make table visible? (or something)
$('#' + @canvas).show()

Expand Down

0 comments on commit 82c4aed

Please sign in to comment.