Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
c3-closed
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
charts
c3-closed
Commits
31a2a130
Commit
31a2a130
authored
Feb 06, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix sacatter plot tooltip when same x data exists
parent
0099bf28
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
24 deletions
+46
-24
c3.js
c3.js
+46
-24
c3.min.js
c3.min.js
+0
-0
No files found.
c3.js
View file @
31a2a130
...
...
@@ -628,50 +628,72 @@
return
y
(
d
.
value
);
}
function
findSameXOfValues
(
values
,
index
)
{
var
i
,
targetX
=
values
[
index
].
x
,
sames
=
[];
for
(
i
=
index
-
1
;
i
>=
0
;
i
--
)
{
if
(
targetX
!==
values
[
i
].
x
)
{
break
;
}
sames
.
push
(
values
[
i
]);
}
for
(
i
=
index
;
i
<
values
.
length
;
i
++
)
{
if
(
targetX
!==
values
[
i
].
x
)
{
break
;
}
sames
.
push
(
values
[
i
]);
}
return
sames
;
}
function
findClosestOfValues
(
values
,
pos
,
_min
,
_max
)
{
// MEMO: values must be sorted by x
var
min
=
_min
?
_min
:
0
,
max
=
_max
?
_max
:
values
.
length
-
1
,
med
=
Math
.
floor
((
max
-
min
)
/
2
)
+
min
,
value
=
values
[
med
],
diff
=
x
(
value
.
x
)
-
pos
[
0
],
minDist
,
maxDist
;
candidates
;
// Update rage for search
// Update ra
n
ge for search
diff
>
0
?
max
=
med
:
min
=
med
;
// if candidates are two closest min and max, stop recursive call
if
((
max
-
min
)
===
1
)
{
if
(
!
values
[
min
].
x
)
{
return
values
[
max
];
}
if
(
!
values
[
max
].
x
)
{
return
values
[
min
];
}
minDist
=
Math
.
pow
(
pos
[
0
]
-
x
(
values
[
min
].
x
),
2
)
+
Math
.
pow
(
pos
[
1
]
-
y
(
values
[
min
].
value
),
2
);
maxDist
=
Math
.
pow
(
pos
[
0
]
-
x
(
values
[
max
].
x
),
2
)
+
Math
.
pow
(
pos
[
1
]
-
y
(
values
[
max
].
value
),
2
);
return
minDist
<
maxDist
?
values
[
min
]
:
values
[
max
];
// Get candidates that has same min and max index
candidates
=
[];
if
(
values
[
min
].
x
)
{
candidates
=
candidates
.
concat
(
findSameXOfValues
(
values
,
min
));
}
if
(
values
[
max
].
x
)
{
candidates
=
candidates
.
concat
(
findSameXOfValues
(
values
,
max
));
}
// Determine the closest and return
return
findClosest
(
candidates
,
pos
);
}
return
findClosestOfValues
(
values
,
pos
,
min
,
max
);
}
function
findClosest
(
targets
,
mouse
)
{
var
c
losest
,
closests
,
minDist
;
function
findClosest
FromTargets
(
targets
,
pos
)
{
var
c
andidates
;
// map to array of closest points of each target
c
losest
s
=
targets
.
map
(
function
(
target
)
{
return
findClosestOfValues
(
target
.
values
,
mouse
);
c
andidate
s
=
targets
.
map
(
function
(
target
)
{
return
findClosestOfValues
(
target
.
values
,
pos
);
});
// decide closest point
closests
.
forEach
(
function
(
c
)
{
var
dist
=
Math
.
pow
(
x
(
c
.
x
)
-
mouse
[
0
],
2
)
+
Math
.
pow
(
y
(
c
.
value
)
-
mouse
[
1
],
2
);
if
(
dist
<
minDist
||
!
minDist
)
{
minDist
=
dist
;
closest
=
c
;
// decide closest point and return
return
findClosest
(
candidates
,
pos
);
}
function
findClosest
(
values
,
pos
)
{
var
minDist
,
closest
;
values
.
forEach
(
function
(
v
)
{
var
d
=
dist
(
v
,
pos
);
if
(
d
<
minDist
||
!
minDist
)
{
minDist
=
d
;
closest
=
v
;
}
});
// TODO: multiple closests when each is very close
return
closest
;
}
//-- Tooltip --//
function
showTooltip
(
selectedData
,
mouse
)
{
...
...
@@ -894,8 +916,8 @@
return
found
;
}
function
dist
(
data
,
mouse
)
{
return
Math
.
pow
(
x
(
data
.
x
)
-
mouse
[
0
],
2
)
+
Math
.
pow
(
y
(
data
.
value
)
-
mouse
[
1
],
2
);
function
dist
(
data
,
pos
)
{
return
Math
.
pow
(
x
(
data
.
x
)
-
pos
[
0
],
2
)
+
Math
.
pow
(
y
(
data
.
value
)
-
pos
[
1
],
2
);
}
//-- Selection --//
...
...
@@ -1480,7 +1502,7 @@
if
(
dragging
)
{
return
;
}
// do nothing when dragging
mouse
=
d3
.
mouse
(
this
);
closest
=
findClosest
(
c3
.
data
.
targets
,
mouse
);
closest
=
findClosest
FromTargets
(
c3
.
data
.
targets
,
mouse
);
// show tooltip when cursor is close to some point
selectedData
=
[
addName
(
closest
)];
...
...
@@ -1504,7 +1526,7 @@
})
.
on
(
'click'
,
function
()
{
var
mouse
=
d3
.
mouse
(
this
),
closest
=
findClosest
(
c3
.
data
.
targets
,
mouse
);
closest
=
findClosest
FromTargets
(
c3
.
data
.
targets
,
mouse
);
// select if selection enabled
if
(
dist
(
closest
,
mouse
)
<
100
)
{
...
...
c3.min.js
View file @
31a2a130
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment