-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from aomra015/EmberCLI0.2.3
Ember cli0.2.3
- Loading branch information
Showing
9 changed files
with
96 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,60 @@ | ||
import Ember from 'ember'; | ||
|
||
export default Ember.Object.extend({ | ||
|
||
redraw: false, | ||
updateByType: function () { | ||
var data = this.get('data'); | ||
|
||
if (data.datasets) {return this.updateLinearCharts();} | ||
if (Array.isArray(data)) {return this.updatePieCharts();} | ||
return this.get('redraw'); | ||
}, | ||
|
||
updateLinearCharts: function () { | ||
var datasets = this.get('data').datasets; | ||
var chart = this.get('chart'); | ||
var self = this; | ||
|
||
datasets.forEach(function(dataset, i) { | ||
dataset.data.forEach(function(item, j) { | ||
item = item || 0; | ||
if (typeof chart.datasets[i] === 'undefined') { | ||
chart.segments[j].value = item; | ||
} else { | ||
var dataSet = chart.datasets[i]; | ||
|
||
if(typeof dataSet.bars !== 'undefined') { | ||
chart.datasets[i].bars[j].value = item; | ||
var chartDataset = chart.datasets[i]; | ||
|
||
try { | ||
dataset.data.forEach(function(item, j) { | ||
item = item || 0; | ||
if(typeof chartDataset.bars !== 'undefined') { | ||
chartDataset.bars[j].value = item; | ||
} else { | ||
chart.datasets[i].points[j].value = item; | ||
chartDataset.points[j].value = item; | ||
} | ||
} | ||
}); | ||
}); | ||
} catch (e) { | ||
if (e instanceof TypeError) { self.set('redraw', true); } | ||
else { console.error(e); } | ||
} | ||
}); | ||
return true; | ||
}, | ||
|
||
updatePieCharts: function () { | ||
var data = this.get('data'); | ||
var data = Ember.A(this.get('data')); | ||
var chart = this.get('chart'); | ||
var needUpdate = false; | ||
|
||
data.forEach(function(segment, i) { | ||
if (typeof chart.segments[i] !== 'undefined') { | ||
segment.value = segment.value || 0; | ||
if (chart.segments[i].value !== segment.value) { | ||
chart.segments[i].value = segment.value; | ||
needUpdate = true; | ||
} | ||
var chartSegments = Ember.A(chart.segments); | ||
|
||
chart.segments.forEach(function(segment, i) { | ||
var updatedSegment = data.findBy('label', segment.label); | ||
if (updatedSegment) { | ||
// Same segment exists in new data | ||
chart.segments[i].value = updatedSegment.value || 0; | ||
} else { | ||
// Segment does not exist anymore in new data | ||
chart.removeData(i); | ||
} | ||
else { | ||
// there are now more segments than the chart knows about; add them | ||
chart.addData(segment, i, true); | ||
needUpdate = true; | ||
}); | ||
|
||
data.forEach(function(segment) { | ||
var currentSegment = chartSegments.findBy('label', segment.label); | ||
if (!currentSegment) { | ||
chart.addData(segment); | ||
} | ||
}); | ||
return needUpdate; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters