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
b59f4a03
Commit
b59f4a03
authored
Mar 13, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show tooltip on Pie and Donut Chart - #64 #47
parent
dbfeb969
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
22 deletions
+42
-22
c3.js
c3.js
+42
-22
c3.min.js
c3.min.js
+0
-0
No files found.
c3.js
View file @
b59f4a03
...
...
@@ -131,7 +131,7 @@
__point_onunselected
=
getConfig
([
'point'
,
'onunselected'
],
function
()
{});
// arc
var
__arc_label_fo
mat
=
getConfig
([
'arc'
,
'label'
,
'format'
],
function
(
d
,
ratio
)
{
return
(
100
*
ratio
).
toFixed
(
1
)
+
"%"
;
}
),
var
__arc_label_fo
rmat
=
getConfig
([
'arc'
,
'label'
,
'format'
],
null
),
__arc_title
=
getConfig
([
'arc'
,
'title'
],
""
);
// region - region to change style
...
...
@@ -150,11 +150,11 @@
if
(
!
text
)
{
title
=
titleFormat
?
titleFormat
(
d
[
i
].
x
)
:
d
[
i
].
x
;
text
=
"<table class='-tooltip'>
<tr><th colspan='2'>"
+
title
+
"</th></tr>"
;
text
=
"<table class='-tooltip'>
"
+
(
title
?
"<tr><th colspan='2'>"
+
title
+
"</th></tr>"
:
""
)
;
}
name
=
d
[
i
].
name
;
value
=
valueFormat
(
d
[
i
].
value
);
value
=
valueFormat
(
d
[
i
].
value
,
d
[
i
].
ratio
);
text
+=
"<tr class='-tooltip-name-"
+
d
[
i
].
id
+
"'><td class='name'><span style='background-color:"
+
color
(
d
[
i
].
id
)
+
"'></span>"
+
name
+
"</td><td class='value'>"
+
value
+
"</td></tr>"
;
}
...
...
@@ -609,7 +609,8 @@
return
(
d
.
endAngle
-
d
.
startAngle
)
/
(
Math
.
PI
*
2
);
}
function
textForArcLable
(
d
)
{
return
__arc_label_fomat
(
d
,
getArcRatio
(
d
));
var
ratio
=
getArcRatio
(
d
);
return
__arc_label_format
?
__arc_label_format
(
d
.
value
,
ratio
)
:
defaultArcValueFormat
(
d
.
v
,
ratio
);
}
function
expandArc
(
id
,
withoutFadeOut
)
{
var
target
=
svg
.
selectAll
(
'.chart-arc'
+
getTargetSelector
(
id
)),
...
...
@@ -1066,6 +1067,9 @@
var
yFormat
=
__axis_y_tick_format
?
__axis_y_tick_format
:
function
(
v
)
{
return
+
v
;
};
return
yFormat
(
v
);
}
function
defaultArcValueFormat
(
v
,
ratio
)
{
return
(
ratio
*
100
).
toFixed
(
1
)
+
'%'
;
}
function
findSameXOfValues
(
values
,
index
)
{
var
i
,
targetX
=
values
[
index
].
x
,
sames
=
[];
...
...
@@ -1158,36 +1162,43 @@
function
showTooltip
(
selectedData
,
mouse
)
{
var
tWidth
,
tHeight
;
var
svgLeft
,
tooltipLeft
,
tooltipRight
,
tooltipTop
,
chartRight
;
var
forArc
=
hasArcType
(
c3
.
data
.
targets
);
var
valueFormat
=
forArc
?
defaultArcValueFormat
:
defaultValueFormat
;
var
dataToShow
=
selectedData
.
filter
(
function
(
d
)
{
return
d
&&
isValue
(
d
.
value
);
});
if
(
!
__tooltip_show
)
{
return
;
}
// don't show tooltip when no data
if
(
dataToShow
.
length
===
0
)
{
return
;
}
// Construct tooltip
tooltip
.
html
(
__tooltip_contents
(
selectedData
,
getXAxisTickFormat
(),
defaultV
alueFormat
,
color
))
tooltip
.
html
(
__tooltip_contents
(
selectedData
,
getXAxisTickFormat
(),
v
alueFormat
,
color
))
.
style
(
"visibility"
,
"hidden"
)
.
style
(
"display"
,
"block"
);
// Get tooltip dimensions
tWidth
=
tooltip
.
property
(
'offsetWidth'
);
tHeight
=
tooltip
.
property
(
'offsetHeight'
);
// Determin tooltip position
if
(
__axis_rotated
)
{
svgLeft
=
getSvgLeft
();
tooltipLeft
=
svgLeft
+
mouse
[
0
]
+
100
;
tooltipRight
=
tooltipLeft
+
tWidth
;
chartRight
=
getCurrentWidth
()
-
getCurrentPaddingRight
();
tooltipTop
=
x
(
dataToShow
[
0
].
x
)
+
20
;
if
(
forArc
)
{
tooltipLeft
=
(
width
/
2
)
+
mouse
[
0
];
tooltipTop
=
(
height
/
2
)
+
mouse
[
1
]
+
20
;
}
else
{
svgLeft
=
getSvgLeft
();
tooltipLeft
=
svgLeft
+
getCurrentPaddingLeft
()
+
x
(
dataToShow
[
0
].
x
)
+
20
;
tooltipRight
=
tooltipLeft
+
tWidth
;
chartRight
=
svgLeft
+
getCurrentWidth
()
-
getCurrentPaddingRight
();
tooltipTop
=
mouse
[
1
]
+
15
;
}
if
(
tooltipRight
>
chartRight
)
{
tooltipLeft
-=
tWidth
+
60
;
}
if
(
tooltipTop
+
tHeight
>
getCurrentHeight
())
{
tooltipTop
-=
tHeight
+
30
;
if
(
__axis_rotated
)
{
svgLeft
=
getSvgLeft
();
tooltipLeft
=
svgLeft
+
mouse
[
0
]
+
100
;
tooltipRight
=
tooltipLeft
+
tWidth
;
chartRight
=
getCurrentWidth
()
-
getCurrentPaddingRight
();
tooltipTop
=
x
(
dataToShow
[
0
].
x
)
+
20
;
}
else
{
svgLeft
=
getSvgLeft
();
tooltipLeft
=
svgLeft
+
getCurrentPaddingLeft
()
+
x
(
dataToShow
[
0
].
x
)
+
20
;
tooltipRight
=
tooltipLeft
+
tWidth
;
chartRight
=
svgLeft
+
getCurrentWidth
()
-
getCurrentPaddingRight
();
tooltipTop
=
mouse
[
1
]
+
15
;
}
if
(
tooltipRight
>
chartRight
)
{
tooltipLeft
-=
tWidth
+
60
;
}
if
(
tooltipTop
+
tHeight
>
getCurrentHeight
())
{
tooltipTop
-=
tHeight
+
30
;
}
}
// Set tooltip
// todo get rid of magic numbers
...
...
@@ -2778,9 +2789,18 @@
expandArc
(
d
.
data
.
id
);
focusLegend
(
d
.
data
.
id
);
})
.
on
(
'mousemove'
,
function
(
d
)
{
var
selectedData
=
[
addName
({
id
:
d
.
data
.
id
,
value
:
d
.
value
,
ratio
:
getArcRatio
(
d
)
})];
showTooltip
(
selectedData
,
d3
.
mouse
(
this
));
})
.
on
(
'mouseout'
,
function
(
d
)
{
unexpandArc
(
d
.
data
.
id
);
revertLegend
();
hideTooltip
();
});
mainPieEnter
.
append
(
"text"
)
.
attr
(
"dy"
,
".35em"
)
...
...
c3.min.js
View file @
b59f4a03
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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