Skip to content

Commit

Permalink
Merge pull request #1791 from JKinsman/jk_patch_pie_magic
Browse files Browse the repository at this point in the history
Cleaned up Pie for stylistic and parsing consistency for later patches (with revisions)
  • Loading branch information
kcarcia committed Sep 25, 2014
2 parents c234061 + 8d77d74 commit 2bc845b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 76 deletions.
75 changes: 18 additions & 57 deletions app/assets/javascripts/visualizations/highvis/pie.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,18 @@ $ ->
if data.normalFields.length > 1
@displayField = data.normalFields[1]
else @displayField = data.normalFields[0]

if !@select_name?


@selectName ?=
if data.textFields.length > 2
@select_name = data.textFields[2]
data.textFields[2]
else
@select_name = 'Percent'
'Percent'

@selected_field = @displayField

start: () ->
super()

update: () ->
@rel_data = []
@selected_field = @displayField
@select_name = data.fields[data.groupingFieldIndex].fieldName
@selectName = data.fields[data.groupingFieldIndex].fieldName
@getGroupedData()
while @chart.series.length > 0
@chart.series[@chart.series.length - 1].remove false
Expand All @@ -60,27 +55,29 @@ $ ->
@displayColors.push(globals.colors[number])
options =
showInLegend: false
data: @display_data
colors: @displayColors
@chart.setTitle { text: "#{@select_name} by #{data.fields[@selected_field].fieldName}" }
data: @displayData
colors: @displayColors
@chart.setTitle { text: "#{@selectName} by #{data.fields[@displayField].fieldName}" }
@chart.addSeries options, false

@chart.redraw()

getGroupedData: ->
@display_data = data.dataPoints.reduce (prev, next) =>
@displayData = data.dataPoints.reduce (prev, next) =>
if typeof prev[next[data.groupingFieldIndex]] != "undefined"
prev[next[data.groupingFieldIndex]] = prev[next[data.groupingFieldIndex]] + next[@selected_field]
prev[next[data.groupingFieldIndex]] = prev[next[data.groupingFieldIndex]] + next[@displayField]
else
prev[next[data.groupingFieldIndex]] = next[@selected_field]
prev[next[data.groupingFieldIndex]] = next[@displayField]
prev
, {}
@display_data = Object.keys(@display_data).reduce (prev, key) =>
@displayData = Object.keys(@displayData).reduce (prev, key) =>
if data.groups.indexOf(key.toLowerCase()) in globals.groupSelection
prev.push [key or "No #{@select_name}", @display_data[key]]
if (grouping[0] for grouping in prev).indexOf(key.toLowerCase()) isnt -1
prev.indexOf(grouping)[1] = @displayData[key] + prev.indexOf(grouping)[1]
else prev.push [key.toLowerCase() or "No #{@selectName}", @displayData[key]]
prev
, []

buildOptions: ->
super()

Expand All @@ -90,8 +87,6 @@ $ ->
$.extend true, @chartOptions,
chart:
type: "pie"
title:
text: "#{data.fields[@selected_field].fieldName}"
tooltip:
pointFormat: '{point.name}: <b>{point.percentage:.1f}%</b>'
plotOptions:
Expand All @@ -101,48 +96,14 @@ $ ->
dataLabels:
enabled: true
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
series: [{
type: 'pie'
data:
[['Firefox', 50], ['Other', 50]]
}]

drawLabelControls: ->
controls = '<div id="labelControl" class="vis_controls">'
controls += "<h3 class='clean_shrink'><a href='#'>Label:</a></h3>"
controls += "<div class='outer_control_div'>"
for fields, f_index in data.fields
do ->
controls += "<div class='inner_control_div'><div class='radio'><label>#{data.fields[fields].fieldName}"
controls += "<input class='label_input' type='radio' name='labels' value='#{fields}'"
if f_index == 0
controls += "checked"
controls += "></label></div></div>"

controls += '</div></div>'
($ '#controldiv').append controls

($ '.label_input').click (e) =>
@select_name = Number e.target.value
@delayedUpdate()

globals.labelOpen ?= 0
($ '#labelControl').accordion
collapsible: true
active: globals.labelOpen

($ '#labelControl > h3').click ->
globals.labelOpen = (globals.labelOpen + 1) % 2

drawControls: ->
super()
@drawGroupControls false, false, false
@drawYAxisControls true, false #horrible name for what im doing here
#@drawLabelControls()
@drawYAxisControls true, false # Naming here is less than ideal
@drawSaveControls()


if "Pie" in data.relVis
globals.pie = new Pie 'pie_canvas'
else
globals.pie = new DisabledVis 'pie_canvas'
globals.pie = new DisabledVis 'pie_canvas'
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ $ ->
if Number(input.value) == savedReg.fieldIndices[0]
input.checked = true

@update()
@start()

# Add a make the delete button remove the regression object
($ 'td#' + savedReg.series.name.id).click =>
Expand Down
36 changes: 18 additions & 18 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
t.string "title"
t.integer "user_id"
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "googleDoc"
t.text "data", default: "[]", null: false
t.string "key"
Expand All @@ -38,16 +38,16 @@
t.integer "field_type"
t.text "unit", limit: 255, default: ""
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "restrictions"
end

create_table "likes", force: true do |t|
t.integer "user_id"
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "media_objects", force: true do |t|
Expand All @@ -56,8 +56,8 @@
t.string "name"
t.integer "data_set_id"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "tutorial_id"
t.boolean "hidden", default: false
t.integer "visualization_id"
Expand All @@ -71,8 +71,8 @@
t.text "content"
t.text "summary"
t.boolean "hidden", default: true
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.integer "featured_media_id"
end
Expand All @@ -81,8 +81,8 @@
t.string "title"
t.integer "user_id"
t.text "content"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "featured", default: false
t.text "filter", limit: 255, default: ""
t.integer "cloned_from"
Expand All @@ -100,8 +100,8 @@
create_table "tutorials", force: true do |t|
t.text "content"
t.string "title"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.boolean "hidden", default: true
t.integer "featured_media_id"
Expand All @@ -116,8 +116,8 @@
t.integer "group_id"
t.boolean "validated", default: false
t.string "password_digest"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "validation_key"
t.boolean "admin", default: false
t.boolean "hidden", default: false
Expand All @@ -141,8 +141,8 @@
t.text "content"
t.text "data"
t.text "globals"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "hidden", default: false
t.boolean "featured", default: false
t.datetime "featured_at"
Expand Down

0 comments on commit 2bc845b

Please sign in to comment.