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
eff53ab9
Commit
eff53ab9
authored
Apr 01, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add axis.labels API - #107
parent
7e89189d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
21 deletions
+55
-21
c3.js
c3.js
+55
-21
c3.min.js
c3.min.js
+0
-0
No files found.
c3.js
View file @
eff53ab9
...
...
@@ -71,7 +71,7 @@
var
d3
=
window
.
d3
?
window
.
d3
:
window
.
require
?
window
.
require
(
"d3"
)
:
undefined
;
var
c3
=
{
data
:
{}
},
var
c3
=
{
data
:
{}
,
axis
:
{}
},
cache
=
{};
/*-- Handle Config --*/
...
...
@@ -180,7 +180,7 @@
__axis_y2_max
=
getConfig
([
'axis'
,
'y2'
,
'max'
]),
__axis_y2_min
=
getConfig
([
'axis'
,
'y2'
,
'min'
]),
__axis_y2_center
=
getConfig
([
'axis'
,
'y2'
,
'center'
]),
__axis_y2_label
=
getConfig
([
'axis'
,
'y2'
,
'label'
]),
__axis_y2_label
=
getConfig
([
'axis'
,
'y2'
,
'label'
]
,
{}
),
__axis_y2_inner
=
getConfig
([
'axis'
,
'y2'
,
'inner'
],
false
),
__axis_y2_tick_format
=
getConfig
([
'axis'
,
'y2'
,
'tick'
,
'format'
]),
__axis_y2_padding
=
getConfig
([
'axis'
,
'y2'
,
'padding'
]),
...
...
@@ -634,11 +634,38 @@
return
__axis_x_tick_culling
&&
maxDataCount
>
__axis_x_tick_count
?
__axis_x_tick_count
:
maxDataCount
;
}
function
getAxisLabelText
(
option
)
{
function
getAxisLabelOptionByAxisId
(
axisId
)
{
var
option
;
if
(
axisId
===
'y'
)
{
option
=
__axis_y_label
;
}
else
if
(
axisId
===
'y2'
)
{
option
=
__axis_y2_label
;
}
else
if
(
axisId
===
'x'
)
{
option
=
__axis_x_label
;
}
return
option
;
}
function
getAxisLabelText
(
axisId
)
{
var
option
=
getAxisLabelOptionByAxisId
(
axisId
);
return
typeof
option
===
'string'
?
option
:
option
?
option
.
text
:
null
;
}
function
getAxisLabelPosition
(
option
,
defaultPosition
)
{
var
position
=
(
option
&&
typeof
option
===
'object'
&&
option
.
position
)
?
option
.
position
:
defaultPosition
;
function
setAxisLabelText
(
axisId
,
text
)
{
var
option
=
getAxisLabelOptionByAxisId
(
axisId
);
if
(
typeof
option
===
'string'
)
{
if
(
axisId
===
'y'
)
{
__axis_y_label
=
text
;
}
else
if
(
axisId
===
'y2'
)
{
__axis_y2_label
=
text
;
}
else
if
(
axisId
===
'x'
)
{
__axis_x_label
=
text
;
}
}
else
if
(
option
)
{
option
.
text
=
text
;
}
}
function
getAxisLabelPosition
(
axisId
,
defaultPosition
)
{
var
option
=
getAxisLabelOptionByAxisId
(
axisId
),
position
=
(
option
&&
typeof
option
===
'object'
&&
option
.
position
)
?
option
.
position
:
defaultPosition
;
return
{
isInner
:
position
.
indexOf
(
'inner'
)
>=
0
,
isOuter
:
position
.
indexOf
(
'outer'
)
>=
0
,
...
...
@@ -651,25 +678,25 @@
};
}
function
getXAxisLabelPosition
()
{
return
getAxisLabelPosition
(
__axis_x_label
,
__axis_rotated
?
'inner-top'
:
'inner-right'
);
return
getAxisLabelPosition
(
'x'
,
__axis_rotated
?
'inner-top'
:
'inner-right'
);
}
function
getYAxisLabelPosition
()
{
return
getAxisLabelPosition
(
__axis_y_label
,
__axis_rotated
?
'inner-right'
:
'inner-top'
);
return
getAxisLabelPosition
(
'y'
,
__axis_rotated
?
'inner-right'
:
'inner-top'
);
}
function
getY2AxisLabelPosition
()
{
return
getAxisLabelPosition
(
__axis_y2_label
,
__axis_rotated
?
'inner-right'
:
'inner-top'
);
return
getAxisLabelPosition
(
'y2'
,
__axis_rotated
?
'inner-right'
:
'inner-top'
);
}
function
getAxisLabelPositionById
(
id
)
{
return
id
===
'y2'
?
getY2AxisLabelPosition
()
:
id
===
'y'
?
getYAxisLabelPosition
()
:
getXAxisLabelPosition
();
}
function
textForXAxisLabel
()
{
return
getAxisLabelText
(
__axis_x_label
);
return
getAxisLabelText
(
'x'
);
}
function
textForYAxisLabel
()
{
return
getAxisLabelText
(
__axis_y_label
);
return
getAxisLabelText
(
'y'
);
}
function
textForY2AxisLabel
()
{
return
getAxisLabelText
(
__axis_y2_label
);
return
getAxisLabelText
(
'y2'
);
}
function
xForAxisLabel
(
forHorizontal
,
position
)
{
if
(
forHorizontal
)
{
...
...
@@ -2321,8 +2348,7 @@
.
attr
(
"transform"
,
__axis_rotated
?
"rotate(-90)"
:
""
)
.
attr
(
"dx"
,
dxForXAxisLabel
)
.
attr
(
"dy"
,
dyForXAxisLabel
)
.
style
(
"text-anchor"
,
textAnchorForXAxisLabel
)
.
text
(
textForXAxisLabel
);
.
style
(
"text-anchor"
,
textAnchorForXAxisLabel
);
if
(
__axis_y_show
)
{
main
.
append
(
"g"
)
...
...
@@ -2333,8 +2359,7 @@
.
attr
(
"transform"
,
__axis_rotated
?
""
:
"rotate(-90)"
)
.
attr
(
"dx"
,
dxForYAxisLabel
)
.
attr
(
"dy"
,
dyForYAxisLabel
)
.
style
(
"text-anchor"
,
textAnchorForYAxisLabel
)
.
text
(
textForYAxisLabel
);
.
style
(
"text-anchor"
,
textAnchorForYAxisLabel
);
}
if
(
__axis_y2_show
)
{
...
...
@@ -2346,8 +2371,7 @@
.
attr
(
"class"
,
CLASS
.
axisY2Label
)
.
attr
(
"transform"
,
__axis_rotated
?
""
:
"rotate(-90)"
)
.
attr
(
"dx"
,
dxForY2AxisLabel
)
.
style
(
"text-anchor"
,
textAnchorForY2AxisLabel
)
.
text
(
textForY2AxisLabel
);
.
style
(
"text-anchor"
,
textAnchorForY2AxisLabel
);
}
// Grids
...
...
@@ -2850,10 +2874,10 @@
xForText
=
generateXYForText
(
barIndices
,
true
);
yForText
=
generateXYForText
(
barIndices
,
false
);
// Update
label position
main
.
select
(
'.'
+
CLASS
.
axisX
+
' .'
+
CLASS
.
axisXLabel
).
attr
(
"x"
,
xForXAxisLabel
);
main
.
select
(
'.'
+
CLASS
.
axisY
+
' .'
+
CLASS
.
axisYLabel
).
attr
(
"x"
,
xForYAxisLabel
).
attr
(
"dy"
,
dyForYAxisLabel
);
main
.
select
(
'.'
+
CLASS
.
axisY2
+
' .'
+
CLASS
.
axisY2Label
).
attr
(
"x"
,
xForY2AxisLabel
).
attr
(
"dy"
,
dyForY2AxisLabel
);
// Update
axis label
main
.
select
(
'.'
+
CLASS
.
axisX
+
' .'
+
CLASS
.
axisXLabel
).
attr
(
"x"
,
xForXAxisLabel
)
.
text
(
textForXAxisLabel
)
;
main
.
select
(
'.'
+
CLASS
.
axisY
+
' .'
+
CLASS
.
axisYLabel
).
attr
(
"x"
,
xForYAxisLabel
).
attr
(
"dy"
,
dyForYAxisLabel
)
.
text
(
textForYAxisLabel
)
;
main
.
select
(
'.'
+
CLASS
.
axisY2
+
' .'
+
CLASS
.
axisY2Label
).
attr
(
"x"
,
xForY2AxisLabel
).
attr
(
"dy"
,
dyForY2AxisLabel
)
.
text
(
textForY2AxisLabel
)
;
// Update sub domain
subY
.
domain
(
y
.
domain
());
...
...
@@ -3931,6 +3955,16 @@
return
c3
.
data
.
x
;
};
c3
.
axis
.
labels
=
function
(
labels
)
{
if
(
arguments
.
length
)
{
Object
.
keys
(
labels
).
forEach
(
function
(
axisId
)
{
setAxisLabelText
(
axisId
,
labels
[
axisId
]);
});
redraw
({
withY
:
false
,
withSubchart
:
false
,
withTransition
:
false
});
}
// TODO: return some values?
};
c3
.
resize
=
function
(
size
)
{
__size_width
=
size
?
size
.
width
:
null
;
__size_height
=
size
?
size
.
height
:
null
;
...
...
c3.min.js
View file @
eff53ab9
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