Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2844 #3

Merged
merged 2 commits into from
May 29, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 68 additions & 55 deletions src/coffee/controllers/ChartController.coffee
Original file line number Diff line number Diff line change
@@ -1,57 +1,70 @@
#CR: I think that pie and line charts are two unrelated charts, which should not be tied together.
class $.ChartController extends $.Controller
constructor : ($viz = 'visualization')->
@id = 'chartViz'
@createSingleYearView = (div)->
new $.PieChartView div
@createMultiYearView = (div)->
new $.LineChartView div
@onSubSection = (subsection) ->
return

super $viz
return
dataLoaded : (budget) =>
singleYearData = []
# Latest year
latestYearData = budget.components[budget.components.length - 2]

# Take the net allocated value and display in the table
emptyItems = []
$.each latestYearData.items, (index, item) ->
if item.values.net_allocated?
singleYearData.push [item.title, item.values.net_allocated]
else
emptyItems.push item.title
return

console.log "subsections with no net_allocated value:"
console.log "****************"
console.log emptyItems

@getSingleYearView().setData singleYearData

# Create the multiYear data
sums = []
categories = []
$.each budget.components, (index, yearData) ->
currentYear = yearData.year
yearSum = 0
$.each yearData.items, (index, item) ->
if item.values.net_allocated?
yearSum += item.values.net_allocated
return
if yearSum > 0
sums.push yearSum
categories.push currentYear
return

mutliYearData =
title : budget.title
source: budget.author
categories : categories
sums : sums

@getMultiYearView().setData mutliYearData

return
constructor : ($viz = 'visualization')->
@id = 'chartViz'
@createSingleYearView = (div)->
new $.PieChartView div
@createMultiYearView = (div)->
new $.LineChartView div
@onSubSection = (subsection) ->
return

super $viz
return
dataLoaded : (budget) =>
singleYearData = []
# Latest year
latestYearData = budget.components[budget.components.length - 2]

# Take the net allocated value and display in the table
emptyItems = []
$.each latestYearData.items, (index, item) ->
if item.values.net_allocated?
singleYearData.push [item.title, item.values.net_allocated]
else
emptyItems.push item.title
return

console.log "subsections with no net_allocated value:"
console.log "****************"
console.log emptyItems

singleYearMaxLength = 9 # elemets after singleYearMaxLength will be lumped to 'other'
# sort the array from large value to small
singleYearData.sort (a,b) ->
return if a[1] < b[1] then 1 else -1

if singleYearData.length > singleYearMaxLength
otherPart = singleYearData[singleYearMaxLength..] # elements to be lumped
singleYearData = singleYearData[...singleYearMaxLength] # elements not lumped
sumOtherPart = 0
for item in otherPart # sum the 'others' value
sumOtherPart += item[1]
singleYearData.push ['סעיפים אחרים', sumOtherPart] # add an 'others' slice to the chart

@getSingleYearView().setData singleYearData

# Create the multiYear data
sums = []
categories = []
$.each budget.components, (index, yearData) ->
currentYear = yearData.year
yearSum = 0
$.each yearData.items, (index, item) ->
if item.values.net_allocated?
yearSum += item.values.net_allocated
return
if yearSum > 0
sums.push yearSum
categories.push currentYear
return

mutliYearData =
title : budget.title
source: budget.author
categories : categories
sums : sums

@getMultiYearView().setData mutliYearData

return
148 changes: 76 additions & 72 deletions src/coffee/views/TableView.coffee
Original file line number Diff line number Diff line change
@@ -1,76 +1,80 @@
$.extend
TableView : ($container, onSubSection)->
@container = $container
that = this
TableView : ($container, onSubSection)->
@container = $container
that = this

that.onSubSection = onSubSection;
that.onSubSection = onSubSection;

@setData = (data) ->
@setData = (data) ->

@container.html '
<table cellpadding="0" cellspacing="0" border="0" class="display">
<thead>
<tr>
<th>תקציב</th>
<th>שנה</th>
<th>מזהה</th>
</tr>
</thead>
<tbody>
<tr class="odd gradeX">
<td>1234.0</td>
<td>1948</td>
<td>0020</td>
</tr>
</tbody>
</table>
'
@container.html '
<table cellpadding="0" cellspacing="0" border="0" class="display">
<thead>
<tr>
<th>תקציב</th>
<th>שנה</th>
<th>מזהה</th>
</tr>
</thead>
<tbody>
<tr class="odd gradeX">
<td>1234.0</td>
<td>1948</td>
<td>0020</td>
</tr>
</tbody>
</table>
'

table = null
tableOptions = $.extend {}, tableDef
if that.onSubSection?
$.extend tableOptions, fnCreatedRow : ( nRow, aData, iDataIndex ) ->
$(nRow).click (event)->
that.onSubSection(aData)
return
table = $('table', @container).dataTable tableOptions
else
table = $('table', @container).dataTable tableOptions
table = null
tableOptions = $.extend {}, tableDef
if $(@container).hasClass('multiYear')
tableOptions.aaSorting = [[1, "desc"]]
else
tableOptions.aaSorting = [[0, "desc"]]
if that.onSubSection?
$.extend tableOptions, fnCreatedRow : ( nRow, aData, iDataIndex ) ->
$(nRow).click (event)->
that.onSubSection(aData)
return
table = $('table', @container).dataTable tableOptions
else
table = $('table', @container).dataTable tableOptions

table.fnClearTable false
table.fnAddData data
table.fnClearTable false
table.fnAddData data

@container.html '
<table cellpadding="0" cellspacing="0" border="0" class="display">
<thead>
<tr>
<th>תקציב</th>
<th>שנה</th>
<th>מזהה</th>
</tr>
</thead>
<tbody>
<tr class="odd gradeX">
<td>1234.0</td>
<td>1948</td>
<td>0020</td>
</tr>
</tbody>
</table>
'
@container.html '
<table cellpadding="0" cellspacing="0" border="0" class="display">
<thead>
<tr>
<th>תקציב</th>
<th>שנה</th>
<th>מזהה</th>
</tr>
</thead>
<tbody>
<tr class="odd gradeX">
<td>1234.0</td>
<td>1948</td>
<td>0020</td>
</tr>
</tbody>
</table>
'

$('table', @container).dataTable(tableDef)
return
$('table', @container).dataTable(tableDef)
return


tableDef = {}
tableDef.bDestroy = true

# make the virtual_id column invisible
tableDef.aoColumns = [
null,
null,
"bVisible": false]
null,
null,
"bVisible": false]

# tableDef.aoColumns = [
# .
Expand All @@ -79,18 +83,18 @@ tableDef.aoColumns = [
# ];
# Make GUI hebrew
tableDef.oLanguage =
"sProcessing": "מעבד..."
"sLengthMenu": "הצג _MENU_ פריטים"
"sZeroRecords": "לא נמצאו רשומות מתאימות"
"sInfo": "_START_ עד _END_ מתוך _TOTAL_ רשומות"
"sInfoEmpty": "0 עד 0 מתוך 0 רשומות"
"sInfoFiltered": "(מסונן מסך _MAX_ רשומות)"
"sInfoPostFix": ""
"sSearch": "חפש:"
"sUrl": ""
"oPaginate":
"sFirst": "ראשון",
"sPrevious": "קודם",
"sNext": "הבא",
"sLast": "אחרון"
"sProcessing": "מעבד..."
"sLengthMenu": "הצג _MENU_ פריטים"
"sZeroRecords": "לא נמצאו רשומות מתאימות"
"sInfo": "_START_ עד _END_ מתוך _TOTAL_ רשומות"
"sInfoEmpty": "0 עד 0 מתוך 0 רשומות"
"sInfoFiltered": "(מסונן מסך _MAX_ רשומות)"
"sInfoPostFix": ""
"sSearch": "חפש:"
"sUrl": ""
"oPaginate":
"sFirst": "ראשון",
"sPrevious": "קודם",
"sNext": "הבא",
"sLast": "אחרון"