-
Notifications
You must be signed in to change notification settings - Fork 6
Introducing Layouts #22
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
Open
spencer516
wants to merge
6
commits into
master
Choose a base branch
from
add-layouts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import Ember from 'ember'; | ||
| const {guidFor} = Ember; | ||
|
|
||
| let e3Layout = Ember.Component.extend({ | ||
| tagName: '', | ||
|
|
||
| /* | ||
| At minimum, we should provide data array to a layout. | ||
| */ | ||
| attrs: { | ||
| data: null | ||
| }, | ||
|
|
||
| /* | ||
| Any attributes changed; recalculate the layout. | ||
| */ | ||
| didUpdateAttrs() { | ||
| this.getAttr('_e3Context').updateMeta( | ||
| 'layouts', | ||
| this.getAttr('name'), | ||
| this._generateLayout() | ||
| ); | ||
| }, | ||
|
|
||
| /* | ||
| Internal private hook to trigger the layout's implementation of the | ||
| using component's `generateLayout()` | ||
| */ | ||
| _generateLayout() { | ||
| let data = this.getData(); | ||
| return this.generateLayout(data); | ||
| }, | ||
|
|
||
| /* | ||
| Hook to get the data that will be used to generate the layout. | ||
| */ | ||
| getData() { | ||
| return this.getAttr('data'); | ||
| }, | ||
|
|
||
| /* | ||
| Generate item layout | ||
| */ | ||
| _generateItemLayout(data) { | ||
| return this.generateItemLayout(data); | ||
| }, | ||
|
|
||
| /* | ||
| Actually generate the layout | ||
| */ | ||
| generateLayout(data) { | ||
| let guidMap = Object.create(null); | ||
|
|
||
| // For each item, create a layout. | ||
| data.forEach(item => { | ||
| let guid = guidFor(item); | ||
| guidMap[guid] = this._generateItemLayout(item); | ||
| }); | ||
|
|
||
| return function(item) { | ||
| return guidMap[guidFor(item)]; | ||
| }; | ||
| }, | ||
|
|
||
| generateItemLayout(/*data*/) {} | ||
| }); | ||
|
|
||
| e3Layout.reopenClass({ | ||
| positionalParams: ['_e3Context', 'name'] | ||
| }); | ||
|
|
||
| export default e3Layout; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import layout from '../e3-layout'; | ||
|
|
||
| /* | ||
| This is more or less a utility layout that will take x & y scales and | ||
| create a layout for objects based on that layout. | ||
| */ | ||
| export default layout.extend({ | ||
| name: 'identity', | ||
|
|
||
| attrs: { | ||
| x: null, | ||
| y: null | ||
| }, | ||
|
|
||
| generateItemLayout(item) { | ||
| let xScale = this.getAttr('x'); | ||
| let yScale = this.getAttr('y'); | ||
|
|
||
| if(!xScale || !yScale) { | ||
| return; | ||
| } | ||
|
|
||
| return { | ||
| x: xScale(item), | ||
| y: yScale(item) | ||
| }; | ||
| } | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import Ember from 'ember'; | ||
|
|
||
| /* | ||
| A layout is a function that takes a model as an input, and returns an object | ||
| that represents the position for that object. Most likey, the returned result | ||
| of the layout is something like | ||
| { | ||
| x: {INTEGER}, | ||
| y: {INTEGER} | ||
| } | ||
| */ | ||
| export function e3BindLayout(params/*, hash*/) { | ||
| let [layout, layoutProp] = params; | ||
|
|
||
| if(layout) { | ||
| return function(data) { | ||
| let itemLayout = layout(data); | ||
| if(itemLayout) { | ||
| return itemLayout[layoutProp]; | ||
| } | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| export default Ember.Helper.helper(e3BindLayout); |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from 'ember-e3/components/e3-layout'; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from 'ember-e3/components/e3-layout/identity'; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default, e3BindLayout } from 'ember-e3/helpers/e3-bind-layout'; |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import Ember from 'ember'; | ||
| let ID = 0; | ||
| // TODO: Use faker or something here. | ||
| function g(number) { | ||
| let res = []; | ||
| while(--number >= 0) { | ||
| res.push(o()); | ||
| } | ||
| return res; | ||
| } | ||
|
|
||
| function o() { | ||
| return { | ||
| id: ++ID, | ||
| value: Math.random() * 100, | ||
| temperature: Math.random() * 100 | ||
| }; | ||
| } | ||
|
|
||
| export default Ember.Route.extend({ | ||
| actions: { | ||
| add() { | ||
| let model = this.controller.get('model'); | ||
| model.push(o()); | ||
| this.controller.set('model', model.slice(0)); | ||
| }, | ||
| clear() { | ||
| this.controller.set('model', []); | ||
| } | ||
| }, | ||
| model() { | ||
| return g(10); | ||
| }, | ||
| setupController(controller, model) { | ||
| controller.set('model', model); | ||
| } | ||
| }); | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <h2 class="title">Force Direction (in progress)</h2> | ||
| <br><br> | ||
| {{#e3-container type='svg' height=400 width=800 as |ctx meta|}} | ||
| <metadata> | ||
| {{e3-scale/linear ctx 'x' | ||
| domain=(e3-extent model key='value' padding=0.2 min-delta=5) | ||
| range=ctx.horizontalRange | ||
| }} | ||
| {{e3-scale/linear ctx 'y' | ||
| domain=(e3-extent model key='temperature' padding=0.3 min-delta=5) | ||
| range=ctx.verticalRange | ||
| }} | ||
|
|
||
| {{e3-layout/identity ctx 'identity' | ||
| data=model | ||
| x=(e3-bind-scale meta.scales.x 'value') | ||
| y=(e3-bind-scale meta.scales.y 'temperature') | ||
| }} | ||
| </metadata> | ||
|
|
||
| {{#each model as |data|}} | ||
| {{e3-shape/circle ctx | ||
| data=data | ||
| x=(e3-bind-layout meta.layouts.identity 'x') | ||
| y=(e3-bind-layout meta.layouts.identity 'y') | ||
| }} | ||
| {{/each}} | ||
| {{/e3-container}} |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { moduleForComponent, test } from 'ember-qunit'; | ||
| import hbs from 'htmlbars-inline-precompile'; | ||
|
|
||
| moduleForComponent('e3-layout', 'Integration | Component | e3 layout', { | ||
| integration: true | ||
| }); | ||
|
|
||
| test('it renders', function(assert) { | ||
| assert.expect(2); | ||
|
|
||
| // Set any properties with this.set('myProperty', 'value'); | ||
| // Handle any actions with this.on('myAction', function(val) { ... }); | ||
|
|
||
| this.render(hbs`{{e3-layout}}`); | ||
|
|
||
| assert.equal(this.$().text().trim(), ''); | ||
|
|
||
| // Template block usage: | ||
| this.render(hbs` | ||
| {{#e3-layout}} | ||
| template block text | ||
| {{/e3-layout}} | ||
| `); | ||
|
|
||
| assert.equal(this.$().text().trim(), 'template block text'); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { moduleForComponent, test } from 'ember-qunit'; | ||
| import hbs from 'htmlbars-inline-precompile'; | ||
|
|
||
| moduleForComponent('e3-layout/identity', 'Integration | Component | e3 layout/identity', { | ||
| integration: true | ||
| }); | ||
|
|
||
| test('it renders', function(assert) { | ||
| assert.expect(2); | ||
|
|
||
| // Set any properties with this.set('myProperty', 'value'); | ||
| // Handle any actions with this.on('myAction', function(val) { ... }); | ||
|
|
||
| this.render(hbs`{{e3-layout/identity}}`); | ||
|
|
||
| assert.equal(this.$().text().trim(), ''); | ||
|
|
||
| // Template block usage: | ||
| this.render(hbs` | ||
| {{#e3-layout/identity}} | ||
| template block text | ||
| {{/e3-layout/identity}} | ||
| `); | ||
|
|
||
| assert.equal(this.$().text().trim(), 'template block text'); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { e3BindLayout } from '../../../helpers/e3-bind-layout'; | ||
| import { module, test } from 'qunit'; | ||
|
|
||
| module('Unit | Helper | e3 bind layout'); | ||
|
|
||
| // Replace this with your real tests. | ||
| test('it works', function(assert) { | ||
| let lookup = {'1234': {x: 12}}; | ||
| let layout = function(data) { | ||
| return lookup[data.id]; | ||
| }; | ||
|
|
||
| var result = e3BindLayout([layout, 'x']); | ||
| assert.ok(result); | ||
| assert.equal(result({id: '1234'}), 12, 'the correct value is returned'); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a huge fan of the function names
oandghere...very non-descript