Skip to content

Commit

Permalink
additional perf
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh committed May 6, 2015
1 parent 4169134 commit 2ecd7d8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 40 deletions.
50 changes: 17 additions & 33 deletions app/components/nf-x-axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,34 +190,21 @@ export default Ember.Component.extend(HasGraphParent, RequireScaleSource, {
*/
width: Ember.computed.alias('graph.graphWidth'),

/**
Function to create the tick values. Can be overriden to provide specific values.
@method tickFactory
@param xScale {Function} a d3 scale function
@param tickCount {Number} the number of ticks desired
@param uniqueXData {Array} all x data represented, filted to be unique (used for ordinal cases)
@param xScaleType {String} the scale type of the containing graph.
@return {Array} an array of domain values at which ticks should be placed.
*/
tickFactory: function(xScale, tickCount, uniqueXData, xScaleType) {
return (xScaleType === 'ordinal') ? uniqueXData : xScale.ticks(tickCount);
},
tickData: Ember.computed('xScale', 'graph.xScaleType', 'uniqueXData', 'tickCount', function(){
if(this.get('graph.xScaleType') === 'ordinal') {
return this.get('uniqueXData');
} else {
return this.get('xScale').ticks(this.get('tickCount'));
}
}),

/**
A unique set of all x data on the graph
@property uniqueXData
@type Array
@readonly
*/
uniqueXData: Ember.computed('graph.xData.@each', function(){
var xData = this.get('graph.xData');
return xData.reduce(function(unique, d) {
if(unique.indexOf(d) === -1) {
unique.push(d);
}
return unique;
}, []);
}),
uniqueXData: Ember.computed.uniq('graph.xData'),

/**
The models for the ticks to display on the axis.
Expand All @@ -226,26 +213,23 @@ export default Ember.Component.extend(HasGraphParent, RequireScaleSource, {
@readonly
*/
ticks: Ember.computed(
'tickCount',
'xScale',
'tickPadding',
'tickLength',
'height',
'orient',
'tickFilter',
'tickData',
'graph.xScaleType',
'uniqueXData',
function(){
var tickCount = this.get("tickCount");
var xScale = this.get("xScale");
var tickPadding = this.get("tickPadding");
var tickLength = this.get("tickLength");
var height = this.get("height");
var orient = this.get("orient");
var tickFilter = this.get("tickFilter");
var xScaleType = this.get("graph.xScaleType");
var uniqueXData = this.get("uniqueXData");
var ticks = this.tickFactory(xScale, tickCount, uniqueXData, xScaleType);
var xScale = this.get('xScale');
var xScaleType = this.get('graph.xScaleType');
var tickPadding = this.get('tickPadding');
var tickLength = this.get('tickLength');
var height = this.get('height');
var orient = this.get('orient');
var tickFilter = this.get('tickFilter');
var ticks = this.get('tickData');
var y1 = orient === 'top' ? height : 0;
var y2 = y1 + tickLength;
var labely = orient === 'top' ? (y1 - tickPadding) : (y1 + tickPadding);
Expand Down
25 changes: 18 additions & 7 deletions app/components/nf-y-axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,23 @@ export default Ember.Component.extend(HasGraphParent, RequireScaleSource, {
return ticks;
},

tickData: Ember.computed('graph.yScaleType', 'uniqueYData', 'yScale', 'tickCount', function(){
var yScaleType = this.get('graph.yScaleType');
if(yScaleType === 'ordinal') {
return this.get('uniqueYData');
} else {
var tickCount = this.get('tickCount');
var ticks = this.get('yScale').ticks(tickCount);
if (yScaleType === 'log') {
var step = Math.round(ticks.length / tickCount);
ticks = ticks.filter(function (tick, i) {
return i % step === 0;
});
}
return ticks;
}
}),

/**
All y data from the graph, filtered to unique values.
@property uniqueYData
Expand All @@ -217,25 +234,19 @@ export default Ember.Component.extend(HasGraphParent, RequireScaleSource, {
*/
ticks: Ember.computed(
'yScale',
'tickCount',
'graph.yScaleType',
'tickPadding',
'axisLineX',
'tickLength',
'isOrientRight',
'tickFilter',
'uniqueYData',
function(){
var yScale = this.get('yScale');
var tickCount = this.get('tickCount');
var yScaleType = this.get('graph.yScaleType');
var tickPadding = this.get('tickPadding');
var axisLineX = this.get('axisLineX');
var tickLength = this.get('tickLength');
var isOrientRight = this.get('isOrientRight');
var tickFilter = this.get('tickFilter');
var uniqueYData = this.get('uniqueYData');
var ticks = this.tickFactory(yScale, tickCount, uniqueYData, yScaleType);
var ticks = this.get('tickData');
var x1 = isOrientRight ? axisLineX + tickLength : axisLineX - tickLength;
var x2 = axisLineX;
var labelx = isOrientRight ? (tickLength + tickPadding) : (axisLineX - tickLength - tickPadding);
Expand Down

0 comments on commit 2ecd7d8

Please sign in to comment.