Created
April 27, 2015 14:07
-
-
Save ekalinichev/cc1f5b155f5ba921aeb8 to your computer and use it in GitHub Desktop.
Ember code sample
This file contains hidden or 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
`import Ember from 'ember'` | |
PLOT_CONTAINER_SELECTOR = '.plot-container' | |
LEGEND_CONTAINER_SELECTOR = '.legend-container' | |
OPTIONS = { | |
series: { | |
pie: { | |
show: true | |
innerRadius: 0.5 | |
} | |
}, | |
grid: { | |
hoverable: true | |
} | |
tooltip: true, | |
tooltipOpts: { | |
content: "%s, %p.1%", | |
shifts: { | |
x: 20, | |
y: 0 | |
}, | |
defaultTheme: false | |
}, | |
legend: { | |
container: LEGEND_CONTAINER_SELECTOR | |
} | |
} | |
PortfolioExposurePieComponent = Ember.Component.extend | |
investments: null | |
sortProperties: ["portfolioFraction:desc"] | |
classNames: ['pie-chart'] | |
title: ( -> | |
@get('kind').capitalize() + 's' | |
).property('kind') | |
filteredData: Ember.computed.filter('investments', (investment) -> | |
investment.get('portfolioFraction') > 0.005 | |
) | |
sortedData: Ember.computed.sort('filteredData', 'sortProperties') | |
chartData: ( -> | |
@get('sortedData').map (investment) -> | |
{ | |
label: investment.get('fund.name'), | |
data: investment.get('portfolioFraction') | |
} | |
).property('sortedData') | |
_drawPlot: -> | |
return unless OPTIONS | |
@$(PLOT_CONTAINER_SELECTOR).plot @get('chartData'), OPTIONS | |
plotUpdater: ( -> | |
@_drawPlot() | |
).observes('chartData') | |
didInsertElement: -> | |
@_drawPlot() | |
`export default PortfolioExposurePieComponent` |
This file contains hidden or 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
`import DS from "ember-data";` | |
`import Ember from "ember";` | |
`import ValuatedModelMixin from "ourea-admin/mixins/valuated-model";` | |
Investment = DS.Model.extend(ValuatedModelMixin, | |
portfolio: DS.belongsTo('portfolio', async: yes) | |
unitsCount: DS.attr('number') | |
fund: DS.belongsTo('fund', async: yes) | |
portfolioFraction: DS.attr('number') | |
title: ( -> | |
"#{@get 'unitsCount'} in #{@get 'fund.name'}" | |
).property('fund.name', 'unitsCount') | |
currency: Ember.computed.alias('fund.currency') | |
) | |
`export default Investment;` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment