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
db37719f
Commit
db37719f
authored
Mar 10, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix padding for data label when rotated axis - #45
parent
908e828b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
3 deletions
+21
-3
c3.js
c3.js
+21
-3
c3.min.js
c3.min.js
+0
-0
No files found.
c3.js
View file @
db37719f
...
@@ -385,8 +385,8 @@
...
@@ -385,8 +385,8 @@
subYMax
=
__axis_rotated
?
width2
:
1
;
subYMax
=
__axis_rotated
?
width2
:
1
;
// update scales
// update scales
x
=
getX
(
xMin
,
xMax
,
x
?
x
.
domain
()
:
undefined
,
function
()
{
return
xAxis
.
tickOffset
();
});
x
=
getX
(
xMin
,
xMax
,
x
?
x
.
domain
()
:
undefined
,
function
()
{
return
xAxis
.
tickOffset
();
});
y
=
getY
(
yMin
,
yMax
,
y
?
y
.
domain
()
:
undefined
);
y
=
getY
(
yMin
,
yMax
);
y2
=
getY
(
yMin
,
yMax
,
y2
?
y2
.
domain
()
:
undefined
);
y2
=
getY
(
yMin
,
yMax
);
subX
=
getX
(
xMin
,
xMax
,
orgXDomain
,
function
(
d
)
{
return
d
%
1
?
0
:
subXAxis
.
tickOffset
();
});
subX
=
getX
(
xMin
,
xMax
,
orgXDomain
,
function
(
d
)
{
return
d
%
1
?
0
:
subXAxis
.
tickOffset
();
});
subY
=
getY
(
subYMin
,
subYMax
);
subY
=
getY
(
subYMin
,
subYMax
);
subY2
=
getY
(
subYMin
,
subYMax
);
subY2
=
getY
(
subYMin
,
subYMax
);
...
@@ -689,7 +689,8 @@
...
@@ -689,7 +689,8 @@
yMax
=
axisId
===
'y2'
?
__axis_y2_max
:
__axis_y_max
,
yMax
=
axisId
===
'y2'
?
__axis_y2_max
:
__axis_y_max
,
yDomainMin
=
isValue
(
yMin
)
?
yMin
:
getYDomainMin
(
yTargets
),
yDomainMin
=
isValue
(
yMin
)
?
yMin
:
getYDomainMin
(
yTargets
),
yDomainMax
=
isValue
(
yMax
)
?
yMax
:
getYDomainMax
(
yTargets
),
yDomainMax
=
isValue
(
yMax
)
?
yMax
:
getYDomainMax
(
yTargets
),
padding
=
Math
.
abs
(
yDomainMax
-
yDomainMin
)
*
(
hasDataLabel
()
&&
__axis_rotated
?
0.125
:
0.1
),
domainLength
=
Math
.
abs
(
yDomainMax
-
yDomainMin
),
padding
=
domainLength
*
0.1
,
// TODO: should be an option
padding_top
=
padding
,
padding_bottom
=
padding
,
padding_top
=
padding
,
padding_bottom
=
padding
,
center
=
axisId
===
'y2'
?
__axis_y2_center
:
__axis_y_center
;
center
=
axisId
===
'y2'
?
__axis_y2_center
:
__axis_y_center
;
if
(
center
)
{
if
(
center
)
{
...
@@ -705,6 +706,13 @@
...
@@ -705,6 +706,13 @@
padding_top
=
isValue
(
__axis_y2_padding
.
top
)
?
__axis_y2_padding
.
top
:
padding
;
padding_top
=
isValue
(
__axis_y2_padding
.
top
)
?
__axis_y2_padding
.
top
:
padding
;
padding_bottom
=
isValue
(
__axis_y2_padding
.
bottom
)
?
__axis_y2_padding
.
bottom
:
padding
;
padding_bottom
=
isValue
(
__axis_y2_padding
.
bottom
)
?
__axis_y2_padding
.
bottom
:
padding
;
}
}
// add padding for data label
if
(
hasDataLabel
()
&&
__axis_rotated
)
{
var
widths
=
getDataLabelWidth
(
yDomainMin
,
yDomainMax
),
diff
=
diffDomain
(
y
.
range
());
var
ratio
=
[
widths
[
0
]
/
diff
,
widths
[
1
]
/
diff
];
padding_top
+=
domainLength
*
(
ratio
[
1
]
/
(
1
-
ratio
[
0
]
-
ratio
[
1
]));
padding_bottom
+=
domainLength
*
(
ratio
[
0
]
/
(
1
-
ratio
[
0
]
-
ratio
[
1
]));
}
// Bar chart with only positive values should be 0-based
// Bar chart with only positive values should be 0-based
if
(
hasBarType
(
yTargets
)
&&
!
hasNegativeValueInTargets
(
yTargets
))
{
if
(
hasBarType
(
yTargets
)
&&
!
hasNegativeValueInTargets
(
yTargets
))
{
padding_bottom
=
yDomainMin
;
padding_bottom
=
yDomainMin
;
...
@@ -1019,6 +1027,16 @@
...
@@ -1019,6 +1027,16 @@
}
}
return
false
;
return
false
;
}
}
function
getDataLabelWidth
(
min
,
max
)
{
var
widths
=
[],
paddingCoef
=
1.3
;
d3
.
select
(
'svg'
).
selectAll
(
'.dummy'
)
.
data
([
min
,
max
])
.
enter
().
append
(
'text'
)
.
text
(
function
(
d
)
{
return
d
;
})
.
each
(
function
(
d
,
i
)
{
var
box
=
this
.
getBBox
();
widths
[
i
]
=
box
.
width
*
paddingCoef
;
})
.
remove
();
return
widths
;
}
function
xx
(
d
)
{
function
xx
(
d
)
{
return
d
?
x
(
d
.
x
)
:
null
;
return
d
?
x
(
d
.
x
)
:
null
;
...
...
c3.min.js
View file @
db37719f
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