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

Timeline hit testing #222

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions js/plugins/hit.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ Flotr.addPlugin('hit', {
drawMouseTrack : function (n) {

var
pos = '',
pos = '',
s = n.series,
p = n.mouse.position,
p = n.mouse.position,
m = n.mouse.margin,
x = n.x,
y = n.y,
Expand Down Expand Up @@ -334,7 +334,7 @@ Flotr.addPlugin('hit', {
}

if (!n.mouse.relative) { // absolute to the canvas
pos += 'top:'
pos += 'top:';
if (p.charAt(0) == 'n') pos += (oTop + m + top);
else if (p.charAt(0) == 's') pos += (oTop - m + top + this.plotHeight - size.height);
pos += 'px;bottom:auto;left:';
Expand All @@ -350,13 +350,13 @@ Flotr.addPlugin('hit', {
},
radius = (Math.min(this.canvasWidth, this.canvasHeight) * s.pie.sizeRatio) / 2,
bisection = n.sAngle<n.eAngle ? (n.sAngle + n.eAngle) / 2: (n.sAngle + n.eAngle + 2* Math.PI) / 2;

pos += 'bottom:' + (m - top - center.y - Math.sin(bisection) * radius/2 + this.canvasHeight) + 'px;top:auto;';
pos += 'left:' + (m + left + center.x + Math.cos(bisection) * radius/2) + 'px;right:auto;';

// Default
} else {
pos += 'top:'
pos += 'top:';
if (/n/.test(p)) pos += (oTop - m + top + n.yaxis.d2p(n.y) - size.height);
else pos += (oTop + m + top + n.yaxis.d2p(n.y));
pos += 'px;bottom:auto;left:';
Expand Down
36 changes: 35 additions & 1 deletion js/types/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Flotr.addType('timeline', {

Flotr._.each(data, function (timeline) {

var
var
x = timeline[0],
y = timeline[1],
w = timeline[2],
Expand All @@ -58,6 +58,40 @@ Flotr.addType('timeline', {
});
},

hit : function (options) {
var
data = options.data,
args = options.args,
n = args[1],
mouse = args[0],
x = options.xInverse(mouse.relX),
y = options.yInverse(mouse.relY),
h = options.barWidth,
x0, x1, y0, y1, i;

for (i = data.length; i--;) {
w = data[i][2];
x0 = data[i][0];
x1 = x0 + w;

y0 = data[i][1] + h;
y1 = data[i][1] - h;

if ((x >= x0) && (x <= x1) && (y <= y0) && (y >= y1)) {
n.x = x0;
n.y = y0 - h;
n.index = i;
n.seriesIndex = options.index;
}
}
},

drawHit : function(options) {
},

clearHit : function(options) {
},

extendRange : function (series) {

var
Expand Down