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
114fb230
Commit
114fb230
authored
Mar 21, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add callbacks for pie and donut chart
parent
5b2c0b52
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
18 deletions
+69
-18
c3.js
c3.js
+58
-15
c3.min.js
c3.min.js
+0
-0
donut.html
htdocs/samples/donut.html
+6
-3
pie.html
htdocs/samples/pie.html
+5
-0
No files found.
c3.js
View file @
114fb230
...
@@ -130,10 +130,20 @@
...
@@ -130,10 +130,20 @@
__point_onselected
=
getConfig
([
'point'
,
'onselected'
],
function
()
{}),
__point_onselected
=
getConfig
([
'point'
,
'onselected'
],
function
()
{}),
__point_onunselected
=
getConfig
([
'point'
,
'onunselected'
],
function
()
{});
__point_onunselected
=
getConfig
([
'point'
,
'onunselected'
],
function
()
{});
// arc
// pie
var
__arc_label_show
=
getConfig
([
'arc'
,
'label'
,
'show'
],
true
),
var
__pie_label_show
=
getConfig
([
'pie'
,
'label'
,
'show'
],
true
),
__arc_label_format
=
getConfig
([
'arc'
,
'label'
,
'format'
],
null
),
__pie_label_format
=
getConfig
([
'pie'
,
'label'
,
'format'
],
null
),
__arc_title
=
getConfig
([
'arc'
,
'title'
],
""
);
__pie_onclick
=
getConfig
([
'pie'
,
'onclick'
],
function
()
{}),
__pie_onmouseover
=
getConfig
([
'pie'
,
'onmouseover'
],
function
()
{}),
__pie_onmouseout
=
getConfig
([
'pie'
,
'onmouseout'
],
function
()
{});
// donut
var
__donut_label_show
=
getConfig
([
'donut'
,
'label'
,
'show'
],
true
),
__donut_label_format
=
getConfig
([
'donut'
,
'label'
,
'format'
],
null
),
__donut_title
=
getConfig
([
'donut'
,
'title'
],
""
),
__donut_onclick
=
getConfig
([
'donut'
,
'onclick'
],
function
()
{}),
__donut_onmouseover
=
getConfig
([
'donut'
,
'onmouseover'
],
function
()
{}),
__donut_onmouseout
=
getConfig
([
'donut'
,
'onmouseout'
],
function
()
{});
// region - region to change style
// region - region to change style
var
__regions
=
getConfig
([
'regions'
],
[]);
var
__regions
=
getConfig
([
'regions'
],
[]);
...
@@ -701,11 +711,19 @@
...
@@ -701,11 +711,19 @@
function
getArcRatio
(
d
)
{
function
getArcRatio
(
d
)
{
return
(
d
.
endAngle
-
d
.
startAngle
)
/
(
Math
.
PI
*
2
);
return
(
d
.
endAngle
-
d
.
startAngle
)
/
(
Math
.
PI
*
2
);
}
}
function
convertToArcData
(
d
)
{
return
addName
({
id
:
d
.
data
.
id
,
value
:
d
.
value
,
ratio
:
getArcRatio
(
d
)
});
}
function
textForArcLabel
(
d
)
{
function
textForArcLabel
(
d
)
{
var
ratio
;
var
ratio
,
format
;
if
(
!
__arc_label_show
)
{
return
""
;
}
if
(
!
shouldShowArcLable
()
)
{
return
""
;
}
ratio
=
getArcRatio
(
d
);
ratio
=
getArcRatio
(
d
);
return
__arc_label_format
?
__arc_label_format
(
d
.
value
,
ratio
)
:
defaultArcValueFormat
(
d
.
v
,
ratio
);
format
=
getArcLabelFormat
();
return
format
?
format
(
d
.
value
,
ratio
)
:
defaultArcValueFormat
(
d
.
v
,
ratio
);
}
}
function
expandArc
(
id
,
withoutFadeOut
)
{
function
expandArc
(
id
,
withoutFadeOut
)
{
var
target
=
svg
.
selectAll
(
'.chart-arc'
+
getTargetSelector
(
id
)),
var
target
=
svg
.
selectAll
(
'.chart-arc'
+
getTargetSelector
(
id
)),
...
@@ -732,6 +750,27 @@
...
@@ -732,6 +750,27 @@
svg
.
selectAll
(
'.-arc'
)
svg
.
selectAll
(
'.-arc'
)
.
style
(
"opacity"
,
1
);
.
style
(
"opacity"
,
1
);
}
}
function
shouldShowArcLable
()
{
return
hasDonutType
(
c3
.
data
.
targets
)
?
__donut_label_show
:
__pie_label_show
;
}
function
getArcLabelFormat
()
{
return
hasDonutType
(
c3
.
data
.
targets
)
?
__donut_label_format
:
__pie_label_format
;
}
function
getArcTitle
()
{
return
hasDonutType
(
c3
.
data
.
targets
)
?
__donut_title
:
""
;
}
function
getArcOnClick
()
{
var
callback
=
hasDonutType
(
c3
.
data
.
targets
)
?
__donut_onclick
:
__pie_onclick
;
return
typeof
callback
===
'function'
?
callback
:
function
()
{};
}
function
getArcOnMouseOver
()
{
var
callback
=
hasDonutType
(
c3
.
data
.
targets
)
?
__donut_onmouseover
:
__pie_onmouseover
;
return
typeof
callback
===
'function'
?
callback
:
function
()
{};
}
function
getArcOnMouseOut
()
{
var
callback
=
hasDonutType
(
c3
.
data
.
targets
)
?
__donut_onmouseout
:
__pie_onmouseout
;
return
typeof
callback
===
'function'
?
callback
:
function
()
{};
}
//-- Domain --//
//-- Domain --//
...
@@ -2011,7 +2050,7 @@
...
@@ -2011,7 +2050,7 @@
.
append
(
'text'
)
.
append
(
'text'
)
.
attr
(
'class'
,
'chart-arcs-title'
)
.
attr
(
'class'
,
'chart-arcs-title'
)
.
style
(
"text-anchor"
,
"middle"
)
.
style
(
"text-anchor"
,
"middle"
)
.
text
(
__arc_title
);
.
text
(
getArcTitle
()
);
main
.
select
(
".chart"
).
append
(
"g"
)
main
.
select
(
".chart"
).
append
(
"g"
)
.
attr
(
"class"
,
"chart-texts"
);
.
attr
(
"class"
,
"chart-texts"
);
...
@@ -2898,22 +2937,26 @@
...
@@ -2898,22 +2937,26 @@
.
style
(
"fill"
,
function
(
d
)
{
return
color
(
d
.
data
.
id
);
})
.
style
(
"fill"
,
function
(
d
)
{
return
color
(
d
.
data
.
id
);
})
.
style
(
"cursor"
,
function
(
d
)
{
return
__data_selection_isselectable
(
d
)
?
"pointer"
:
null
;
})
.
style
(
"cursor"
,
function
(
d
)
{
return
__data_selection_isselectable
(
d
)
?
"pointer"
:
null
;
})
.
each
(
function
(
d
)
{
this
.
_current
=
d
;
})
.
each
(
function
(
d
)
{
this
.
_current
=
d
;
})
.
on
(
'mouseover'
,
function
(
d
)
{
.
on
(
'mouseover'
,
function
(
d
,
i
)
{
var
arcData
=
convertToArcData
(
d
),
callback
=
getArcOnMouseOver
();
expandArc
(
d
.
data
.
id
);
expandArc
(
d
.
data
.
id
);
focusLegend
(
d
.
data
.
id
);
focusLegend
(
d
.
data
.
id
);
callback
(
arcData
,
i
);
})
})
.
on
(
'mousemove'
,
function
(
d
)
{
.
on
(
'mousemove'
,
function
(
d
)
{
var
selectedData
=
[
addName
({
var
selectedData
=
[
convertToArcData
(
d
)];
id
:
d
.
data
.
id
,
value
:
d
.
value
,
ratio
:
getArcRatio
(
d
)
})];
showTooltip
(
selectedData
,
d3
.
mouse
(
this
));
showTooltip
(
selectedData
,
d3
.
mouse
(
this
));
})
})
.
on
(
'mouseout'
,
function
(
d
)
{
.
on
(
'mouseout'
,
function
(
d
,
i
)
{
var
arcData
=
convertToArcData
(
d
),
callback
=
getArcOnMouseOut
();
unexpandArc
(
d
.
data
.
id
);
unexpandArc
(
d
.
data
.
id
);
revertLegend
();
revertLegend
();
hideTooltip
();
hideTooltip
();
callback
(
arcData
,
i
);
})
.
on
(
'click'
,
function
(
d
,
i
)
{
var
arcData
=
convertToArcData
(
d
),
callback
=
getArcOnClick
();
callback
(
arcData
,
i
);
});
});
mainPieEnter
.
append
(
"text"
)
mainPieEnter
.
append
(
"text"
)
.
attr
(
"dy"
,
".35em"
)
.
attr
(
"dy"
,
".35em"
)
...
...
c3.min.js
View file @
114fb230
This source diff could not be displayed because it is too large. You can
view the blob
instead.
htdocs/samples/donut.html
View file @
114fb230
...
@@ -37,12 +37,15 @@
...
@@ -37,12 +37,15 @@
label
:
'Petal.Width'
label
:
'Petal.Width'
}
}
},
},
arc
:
{
donut
:
{
label
:
{
label
:
{
// format: function (d, ratio) { return ""; }
// format: function (d, ratio) { return ""; }
},
},
title
:
"Iris Petal Width"
title
:
"Iris Petal Width"
,
}
onmouseover
:
function
(
d
,
i
)
{
console
.
log
(
d
,
i
);
},
onmouseout
:
function
(
d
,
i
)
{
console
.
log
(
d
,
i
);
},
onclick
:
function
(
d
,
i
)
{
console
.
log
(
d
,
i
);
},
}
});
});
setTimeout
(
function
()
{
setTimeout
(
function
()
{
...
...
htdocs/samples/pie.html
View file @
114fb230
...
@@ -35,6 +35,11 @@
...
@@ -35,6 +35,11 @@
y
:
{
y
:
{
label
:
'Petal.Width'
label
:
'Petal.Width'
}
}
},
pie
:
{
onmouseover
:
function
(
d
,
i
)
{
console
.
log
(
d
,
i
);
},
onmouseout
:
function
(
d
,
i
)
{
console
.
log
(
d
,
i
);
},
onclick
:
function
(
d
,
i
)
{
console
.
log
(
d
,
i
);
},
}
}
});
});
...
...
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