Skip to content
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

Cr/issue 138 #139

Merged
merged 3 commits into from
Aug 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions src/plot/axisannotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,31 +138,19 @@ function backgroundPath(accessor, axis, height, width, point, neg) {
if(height/2 < point) pt = height/2;
else h = height/2-point;

return [
'M', 0, value,
'l', neg*Math.max(axis.innerTickSize(), 1), -pt,
'l', 0, -h,
'l', neg*width, 0,
'l', 0, height,
'l', neg*-width, 0,
'l', 0, -h
].join(' ');
return 'M 0 ' + value + ' l ' + String(neg*Math.max(axis.innerTickSize(), 1)) + ' ' + String(-pt) +
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another great catch. Those joins in chrome are a killer.
Any reason for String constructor rather than implicit conversion? For my profiling in chrome implicit conversion is much faster. Will post cases for review.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test: https://gist.github.com/andredumas/7a3277e3cb06c35f4ba34562a873cf35#file-number-tostring-html-L25

Pls flick through the tests make sure I'm not doing anything crazy for these suggestions. These area's are key to responsiveness feel for the chart. This is a really good step forward.

' l 0 ' + String(-h) + ' l ' + (neg*width) + ' 0 l 0 ' + height +
' l ' + (neg*-width) + ' 0 l 0 ' + String(-h);
case 'top':
case 'bottom':
var w = 0;

if(width/2 < point) pt = width/2;
else w = width/2-point;

return [
'M', value, 0,
'l', -pt, neg*Math.max(axis.innerTickSize(), 1),
'l', -w, 0,
'l', 0, neg*height,
'l', width, 0,
'l', 0, neg*-height,
'l', -w, 0
].join(' ');
return 'M ' + value + ' 0 l ' + String(-pt) + ' ' + (neg*Math.max(axis.innerTickSize(), 1)) +
' l ' + String(-w) + ' 0 l 0 ' + String(neg*height) + ' l ' + width + ' 0 l 0 ' + (neg*-height) +
' l ' + String(-w) + ' 0';
default: throw "Unsupported axis.orient() = " + axis.orient();
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/plot/crosshair.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function horizontalPathLine(y, range) {
return function(d) {
if(d === null) return null;
var value = y(d);
return ['M', range[0], value, 'L', range[range.length-1], value].join(' ');
return 'M ' + range[0] + ' ' + value + ' L ' + range[range.length-1] + ' ' + value;
};
}

Expand All @@ -140,6 +140,6 @@ function verticalPathLine(x, range) {
var value = x(d),
sr = x.range();
if(value < Math.min(sr[0], sr[sr.length-1]) || value > Math.max(sr[0], sr[sr.length-1])) return null;
return ['M', value, range[0], 'L', value, range[range.length-1]].join(' ');
return 'M ' + value + ' ' + range[0] + ' L ' + value + ' ' + range[range.length-1];
};
}
8 changes: 2 additions & 6 deletions src/plot/macd.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ module.exports = function(accessor_macd, plot, plotMixin) { // Injected depende
height = y(accessor.dif(d)) - zero,
xValue = x(accessor.d(d)) - width/2;

return [
'M', xValue, zero,
'l', 0, height,
'l', width, 0,
'l', 0, -height
].join(' ');
return 'M ' + xValue + ' ' + zero + ' l 0 ' + height + ' l ' + width +
' 0 l 0 ' + String(-height);
};
}

Expand Down
11 changes: 3 additions & 8 deletions src/plot/ohlc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@ module.exports = function(d3_scale_linear, d3_extent, accessor_ohlc, plot, plotM
xPoint = x(accessor.d(d)),
xValue = xPoint - width/2;

return [
'M', xValue, open,
'l', width/2, 0,
'M', xPoint, y(accessor.h(d)),
'L', xPoint, y(accessor.l(d)),
'M', xPoint, close,
'l', width/2, 0
].join(' ');
return 'M ' + xValue + ' ' +
open + ' l ' + (width/2) + ' 0 M ' + xPoint + ' ' + y(accessor.h(d)) + ' L ' +
xPoint + ' ' + y(accessor.l(d)) + ' M ' + xPoint + ' ' + close + ' l ' + (width/2) + ' 0';
};
}

Expand Down
6 changes: 2 additions & 4 deletions src/plot/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ module.exports = function(d3_svg_line, d3_select) {
var firstDatum = d[0],
lastDatum = d[d.length-1];

return [
'M', x(accessor_date(firstDatum)), y(accessor_value(firstDatum)),
'L', x(accessor_date(lastDatum)), y(accessor_value(lastDatum))
].join(' ');
return 'M ' + x(accessor_date(firstDatum)) + ' ' + y(accessor_value(firstDatum)) +
' L ' + x(accessor_date(lastDatum)) + ' ' + y(accessor_value(lastDatum));
};
},

Expand Down
10 changes: 2 additions & 8 deletions src/plot/tick.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,8 @@ module.exports = function(d3_scale_linear, d3_extent, accessor_tick, plot, plotM
xPoint = x(accessor.d(d)),
xValue = xPoint - width/2;

return [
'M', xValue, high,
'l', width, 0,
'M', xPoint, high,
'L', xPoint, low,
'M', xValue, low,
'l', width, 0
].join(' ');
return 'M ' + xValue + ' ' + high + ' l ' + width + ' 0 M ' + xPoint + ' ' + high +
' L ' + xPoint + ' ' + low + ' M ' + xValue + ' ' + low + ' l ' + width + ' 0';
};
}

Expand Down
8 changes: 2 additions & 6 deletions src/plot/volume.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ module.exports = function(accessor_volume, plot, plotMixin) { // Injected depen
height = y(vol) - zero,
xValue = x(accessor.d(d)) - width/2;

return [
'M', xValue, zero,
'l', 0, height,
'l', width, 0,
'l', 0, -height
].join(' ');
return 'M ' + xValue + ' ' + zero + ' l 0 ' + height + ' l ' + width +
' 0 l 0 ' + String(-height);
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/scale/financetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = function(d3_scale_linear, d3_time, d3_bisect, techan_util_rebin
* @returns {*}
*/
function scale(x, offset) {
var mappedIndex = dateIndexMap[+x];
var mappedIndex = dateIndexMap[x.getTime ? x.getTime() : +x];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch here, but after profiling I would prefer:

x instanceof Date ? x.getTime() : +x

Faster still (for me, linux chrome) and handles undefined and nulls gracefully (without error). I'll add some test cases around the nulls and undefines.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offset = offset || 0;

// Make sure the value has been mapped, if not, determine if it's just before, round in, or just after domain
Expand Down