Skip to content

Instantly share code, notes, and snippets.

@lukesargeant
Forked from wojciechb/components.ig-chart.js
Last active November 15, 2017 08:37
Show Gist options
  • Save lukesargeant/987176a7c7828d7d6f4ea5d2bba03cae to your computer and use it in GitHub Desktop.
Save lukesargeant/987176a7c7828d7d6f4ea5d2bba03cae to your computer and use it in GitHub Desktop.
measuring paradigm
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['ig-chart'],
});
import Ember from 'ember';
export default Ember.Component.extend({
opened: false,
expanded: false,
// private
widthInPx: null,
init(...args) {
this._super(...args);
Ember.run.next(this, this.calculate);
},
calculate() {
this.set('widthInPx', this.$('.ig-flyout').width());
},
classes: Ember.computed(
'opened',
'expanded',
function() {
const {
opened,
expanded
} = this.getProperties('opened', 'expanded');
let result = 'ig-flyout';
if (expanded) {
result += ' ig-flyout--expanded';
} else if (opened) {
result += ' ig-flyout--opened';
} else {
result += ' ig-flyout--closed';
}
return result;
}
),
actions: {
open() {
this.set('opened', true);
this.set('expanded', false);
Ember.run.next(this, this.calculate);
},
expand() {
this.set('opened', false);
this.set('expanded', true);
Ember.run.next(this, this.calculate);
},
hide() {
this.set('opened', false);
this.set('expanded', false);
Ember.run.next(this, this.calculate);
},
resize() {
this.set('flyoutWidth', (Math.random() * 500).toFixed(2));
}
},
});
import Ember from 'ember';
export default Ember.Component.extend({
//public
width: null,
showChart: Ember.computed.gte('width', 200),
classNames: ['ig-market-view'],
});
import Ember from 'ember';
export default Ember.Component.extend({
width: 100,
inlineStyle: Ember.computed('width', function() {
return `width: ${this.get('width')}px`;
}),
actions: {
panelResize() {
// simulates panel being resized on click
this.sendAction('resize', (Math.random() * 300).toFixed(2));
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
containerStyle: Ember.computed('workspaceWidthPx', function() {
return `width: ${this.get('workspaceWidthPx')}px`;
}),
workspaceWidthPx: 420,
panelWidthPc: 60,
panelWidthPx: Ember.computed('workspaceWidthPx', 'panelWidthPc', function() {
return this.get('workspaceWidthPx') * (this.get('panelWidthPc') / 100);
}),
actions: {
windowResize() {
// simulates window.resize on button click
this.set('workspaceWidthPx', (Math.random() * 500).toFixed(2));
},
panelResize(panelId, newWidthPx) {
let workspaceWidthPx = this.get('workspaceWidthPx');
let newWidthPc = (newWidthPx / workspaceWidthPx) * 100;
this.set('panelWidthPc', newWidthPc.toFixed(0));
}
},
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
body { font-size: 11px; color: gray; font-family: Arial; }
strong { font-size: 14px; color: black; }
* { overflow: visible; white-space: nowrap;}
.ig-workspace { border: 2px solid black; }
.ig-panel { border: 1px solid orange; }
.ig-market-view { border: 1px solid yellow; }
.ig-chart { border: 1px solid violet; background-color: violet; }
.ig-chart-hidden-message { background-color: pink; }
.ig-flyout { border: 2px solid black; }
.ig-flyout--closed { width: 5% }
.ig-flyout--opened { width: 40% }
.ig-flyout--expanded { width: 90% }
{{ig-workspace}}
{{ig-flyout}}
<button onclick={{action 'hide'}}>hide flyout</button>
<button onclick={{action 'open'}}>open flyout partially</button>
<button onclick={{action 'expand'}}>open flyout fully</button>
<div class={{classes}}>
{{#if expanded}}
<strong>extended flyout</strong>
{{else if opened}}
<strong>opened flyout</strong>
{{else}}
<strong>hidden flyout</strong>
{{/if}}
{{ig-market-view width=widthInPx}}
</div>
<strong>market-view</strong> -- width: {{width}}<br/>
{{#if showChart}}
{{ig-chart}}
{{else}}
<strong class='ig-chart-hidden-message'>hidden</strong>
{{/if}}
<div class='ig-panel' style={{inlineStyle}} {{action "panelResize"}}>
<strong>panel</strong> -- width: {{width}}px <br/>
{{ig-market-view width=width}}
</div>
<button onclick={{action 'windowResize'}}>window resize</button>
<div style={{containerStyle}}>
<div class='ig-workspace'>
<strong>workspace</strong><br/>
-- workspaceWidthPx: {{workspaceWidthPx}}px <br/>
-- panelWidthPc: {{panelWidthPc}}% <br/>
{{ig-panel
id="fake-id"
width=panelWidthPx
resize=(action "panelResize" "fake-id")
}}
</div>
</div>
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment