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
9a67dce2
Commit
9a67dce2
authored
May 31, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix y padding for data label - #295
parent
ed534fc5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
7 deletions
+68
-7
c3.js
c3.js
+11
-7
c3.min.js
c3.min.js
+0
-0
data_label.html
htdocs/samples/data_label.html
+57
-0
No files found.
c3.js
View file @
9a67dce2
...
...
@@ -1217,7 +1217,7 @@
yDomainMax
=
isValue
(
yMax
)
?
yMax
:
getYDomainMax
(
yTargets
),
domainLength
,
padding
,
padding_top
,
padding_bottom
,
center
=
axisId
===
'y2'
?
__axis_y2_center
:
__axis_y_center
,
yDomainAbs
,
wid
ths
,
diff
,
ratio
,
yDomainAbs
,
leng
ths
,
diff
,
ratio
,
showHorizontalDataLabel
=
hasDataLabel
()
&&
__axis_rotated
;
if
(
yTargets
.
length
===
0
)
{
// use current domain if target of axisId is none
return
axisId
===
'y2'
?
y2
.
domain
()
:
y
.
domain
();
...
...
@@ -1234,11 +1234,15 @@
}
// add padding for data label
if
(
showHorizontalDataLabel
)
{
widths
=
getDataLabelWidth
(
yDomainMin
,
yDomainMax
,
axisId
);
lengths
=
getDataLabelLength
(
yDomainMin
,
yDomainMax
,
axisId
,
'width'
);
diff
=
diffDomain
(
y
.
range
());
ratio
=
[
widths
[
0
]
/
diff
,
wid
ths
[
1
]
/
diff
];
ratio
=
[
lengths
[
0
]
/
diff
,
leng
ths
[
1
]
/
diff
];
padding_top
+=
domainLength
*
(
ratio
[
1
]
/
(
1
-
ratio
[
0
]
-
ratio
[
1
]));
padding_bottom
+=
domainLength
*
(
ratio
[
0
]
/
(
1
-
ratio
[
0
]
-
ratio
[
1
]));
}
else
{
lengths
=
getDataLabelLength
(
yDomainMin
,
yDomainMax
,
axisId
,
'height'
);
padding_top
+=
lengths
[
1
];
padding_bottom
+=
lengths
[
0
];
}
if
(
axisId
===
'y'
&&
__axis_y_padding
)
{
padding_top
=
getAxisPadding
(
__axis_y_padding
,
'top'
,
padding
,
domainLength
);
...
...
@@ -1806,17 +1810,17 @@
}
return
false
;
}
function
getDataLabel
Width
(
min
,
max
,
axisId
)
{
var
widths
=
[
],
paddingCoef
=
1.3
;
function
getDataLabel
Length
(
min
,
max
,
axisId
,
key
)
{
var
lengths
=
[
0
,
0
],
paddingCoef
=
1.3
;
selectChart
.
select
(
'svg'
).
selectAll
(
'.dummy'
)
.
data
([
min
,
max
])
.
enter
().
append
(
'text'
)
.
text
(
function
(
d
)
{
return
formatByAxisId
(
axisId
)(
d
);
})
.
each
(
function
(
d
,
i
)
{
widths
[
i
]
=
this
.
getBoundingClientRect
().
width
*
paddingCoef
;
lengths
[
i
]
=
this
.
getBoundingClientRect
()[
key
]
*
paddingCoef
;
})
.
remove
();
return
wid
ths
;
return
leng
ths
;
}
function
getYFormat
(
forArc
)
{
var
formatForY
=
forArc
&&
!
hasGaugeType
(
c3
.
data
.
targets
)
?
defaultArcValueFormat
:
yFormat
,
...
...
c3.min.js
View file @
9a67dce2
This source diff could not be displayed because it is too large. You can
view the blob
instead.
htdocs/samples/data_label.html
0 → 100644
View file @
9a67dce2
<html>
<head>
<link
href=
"/css/c3.css"
rel=
"stylesheet"
type=
"text/css"
>
</head>
<body>
<div
id=
"chart1"
></div>
<div
id=
"chart2"
></div>
<script
src=
"/js/d3.min.js"
charset=
"utf-8"
></script>
<script
src=
"/js/c3.js"
></script>
<script>
var
chart1
=
c3
.
generate
({
bindto
:
'#chart1'
,
data
:
{
columns
:
[
[
'data1'
,
30
,
200
,
100
,
500
,
150
,
250
],
[
'data2'
,
50
,
20
,
10
,
40
,
15
,
25
],
[
'data3'
,
250
,
220
,
210
,
240
,
215
,
225
]
],
groups
:
[[
'data1'
,
'data2'
,
'data3'
]],
labels
:
true
,
type
:
'bar'
,
},
axis
:
{
rotated
:
true
}
});
var
chart2
=
c3
.
generate
({
bindto
:
'#chart2'
,
data
:
{
x
:
'x'
,
columns
:
[
[
'x'
,
'2014-01-01'
,
'2014-02-01'
,
'2014-03-01'
,
'2014-04-01'
],
[
'data1'
,
-
190
,
200
,
190
,
null
],
],
type
:
'bar'
,
labels
:
{
format
:
function
(
v
,
id
)
{
if
(
v
===
null
)
{
return
'Not Applicable'
;
}
return
d3
.
format
(
'$'
)(
v
);
}
}
},
axis
:
{
x
:
{
type
:
'categorized'
}
},
});
</script>
</body>
</html>
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