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
2f3366ad
Commit
2f3366ad
authored
May 09, 2013
by
Masayuki Tanaka
Committed by
masayuki
May 09, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bar x position
parent
7d91a306
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
11 deletions
+36
-11
c3.js
c3.js
+36
-11
No files found.
c3.js
View file @
2f3366ad
...
...
@@ -376,6 +376,23 @@
}
return
false
}
function
getTargetsNum
(
filter
)
{
return
typeof
filter
!==
'undefined'
?
c3
.
data
.
targets
.
filter
(
isBarType
).
length
:
c3
.
data
.
targets
.
length
;
}
function
getBarTargetIndices
()
{
var
indices
=
[]
c3
.
data
.
targets
.
forEach
(
function
(
d
,
i
)
{
if
(
isBarType
(
d
))
{
indices
.
push
(
i
)
}
})
return
indices
}
function
getBarX
(
barWidth
,
barTargetsNum
,
barIndices
)
{
return
function
(
d
)
{
return
x
(
d
.
x
)
-
barWidth
*
(
barTargetsNum
/
2
-
barIndices
.
indexOf
(
d
.
i
))
}
}
function
isLineType
(
d
)
{
var
id
=
(
typeof
d
===
'string'
)
?
d
:
d
.
id
return
!
(
id
in
__data_types
)
||
__data_types
[
id
]
===
'line'
...
...
@@ -610,8 +627,8 @@
.
enter
().
append
(
"rect"
)
.
attr
(
"class"
,
function
(
d
,
i
){
return
"event-rect event-rect-"
+
i
})
.
style
(
"cursor"
,
function
(
d
){
return
__data_selection_enabled
&&
__data_selection_grouped
?
"pointer"
:
null
})
.
attr
(
"x"
,
function
(
d
)
{
return
x
(
d
.
x
)
-
(
rectWidth
/
2
)
})
.
attr
(
"y"
,
function
(
d
)
{
return
0
})
.
attr
(
"x"
,
function
(
d
){
return
x
(
d
.
x
)
-
(
rectWidth
/
2
)
})
.
attr
(
"y"
,
function
(
d
){
return
0
})
.
attr
(
"width"
,
rectWidth
)
.
attr
(
"height"
,
height
)
.
on
(
'mouseover'
,
function
(
d
,
i
)
{
...
...
@@ -817,7 +834,8 @@
function
update
(
withTransition
)
{
var
xgrid
,
xgridData
,
xgridLine
var
mainPath
,
mainCircle
,
mainBar
,
contextPath
var
targetsNum
=
Object
.
keys
(
c3
.
data
.
targets
).
length
,
rectWidth
,
barWidth
var
barTargetsNum
=
getTargetsNum
(
isBarType
),
barWidth
,
barIndices
,
barX
var
rectWidth
x
.
domain
(
brush
.
empty
()
?
x2
.
domain
()
:
brush
.
extent
())
...
...
@@ -871,11 +889,14 @@
.
attr
(
"cy"
,
function
(
d
)
{
return
y
(
d
.
value
)
})
// bars
barWidth
=
(
xAxis
.
tickOffset
()
*
2
*
0.6
)
/
targetsNum
barWidth
=
(
xAxis
.
tickOffset
()
*
2
*
0.6
)
/
barTargetsNum
barIndices
=
getBarTargetIndices
()
barX
=
getBarX
(
barWidth
,
barTargetsNum
,
barIndices
)
mainBar
=
main
.
selectAll
(
'.target'
).
selectAll
(
'.target-bar'
).
filter
(
isBarType
)
if
(
withTransition
)
mainBar
=
mainBar
.
transition
()
mainBar
.
attr
(
"width"
,
barWidth
)
.
attr
(
"x"
,
function
(
d
){
return
x
(
d
.
x
)
-
barWidth
*
(
targetsNum
/
2
-
d
.
i
)
}
)
.
attr
(
"x"
,
barX
)
// subchart
if
(
__subchart_show
)
{
...
...
@@ -900,8 +921,7 @@
}
function
draw
(
targets
)
{
var
targetsNum
=
Object
.
keys
(
c3
.
data
.
targets
).
length
var
barWidth
=
0
,
bar2Width
=
0
var
barTargetsNum
=
getTargetsNum
(
isBarType
),
barWidth
=
0
,
bar2Width
=
0
,
barIndices
,
barX
var
f
,
c
/*-- Main --*/
...
...
@@ -947,7 +967,10 @@
})
// Rects for each data
barWidth
=
(
xAxis
.
tickOffset
()
*
2
*
0.6
)
/
targetsNum
barWidth
=
(
xAxis
.
tickOffset
()
*
2
*
0.6
)
/
barTargetsNum
barIndices
=
getBarTargetIndices
()
barX
=
getBarX
(
barWidth
,
barTargetsNum
,
barIndices
)
f
.
append
(
'g'
)
.
attr
(
"class"
,
function
(
d
){
return
"target-bars target-bars-"
+
d
.
id
})
.
style
(
"fill"
,
function
(
d
){
return
color
(
d
.
id
)
})
...
...
@@ -956,7 +979,7 @@
.
data
(
function
(
d
){
return
d
.
values
})
.
enter
().
append
(
"rect"
)
.
attr
(
"class"
,
function
(
d
,
i
){
return
"target-bar target-bar-"
+
i
})
.
attr
(
"x"
,
function
(
d
){
return
x
(
d
.
x
)
-
barWidth
*
(
targetsNum
/
2
-
d
.
i
)
}
)
.
attr
(
"x"
,
barX
)
.
attr
(
"y"
,
function
(
d
){
return
y
(
d
.
value
)
})
.
attr
(
"width"
,
barWidth
)
.
attr
(
"height"
,
function
(
d
){
return
height
-
y
(
d
.
value
)
})
...
...
@@ -996,7 +1019,9 @@
.
attr
(
"d"
,
function
(
d
)
{
return
line2
(
d
.
values
)
})
// Rects for each data
bar2Width
=
(
xAxis2
.
tickOffset
()
*
2
*
0.6
)
/
targetsNum
bar2Width
=
(
xAxis2
.
tickOffset
()
*
2
*
0.6
)
/
barTargetsNum
barX
=
getBarX
(
bar2Width
,
barTargetsNum
,
barIndices
)
c
.
append
(
'g'
)
.
attr
(
"class"
,
function
(
d
){
return
"target-bars target-bars-"
+
d
.
id
})
.
style
(
"fill"
,
function
(
d
){
return
color
(
d
.
id
)
})
...
...
@@ -1005,7 +1030,7 @@
.
data
(
function
(
d
){
return
d
.
values
})
.
enter
().
append
(
"rect"
)
.
attr
(
"class"
,
function
(
d
,
i
){
return
"target-bar target-bar-"
+
i
})
.
attr
(
"x"
,
function
(
d
){
return
x2
(
d
.
x
)
-
bar2Width
*
(
targetsNum
/
2
-
d
.
i
)
}
)
.
attr
(
"x"
,
barX
)
.
attr
(
"y"
,
function
(
d
){
return
y2
(
d
.
value
)
})
.
attr
(
"width"
,
bar2Width
)
.
attr
(
"height"
,
function
(
d
){
return
height2
-
y2
(
d
.
value
)
})
...
...
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