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
Evgeny
c3-closed
Commits
dd3f6715
Commit
dd3f6715
authored
Mar 03, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor draw bar and text
parent
53a5b08d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
51 deletions
+62
-51
c3.js
c3.js
+62
-51
No files found.
c3.js
View file @
dd3f6715
...
@@ -877,10 +877,17 @@
...
@@ -877,10 +877,17 @@
function
classRegion
(
d
,
i
)
{
return
'region region-'
+
i
+
' '
+
(
'classes'
in
d
?
[].
concat
(
d
.
classes
).
join
(
' '
)
:
''
);
}
function
classRegion
(
d
,
i
)
{
return
'region region-'
+
i
+
' '
+
(
'classes'
in
d
?
[].
concat
(
d
.
classes
).
join
(
' '
)
:
''
);
}
function
classEvent
(
d
,
i
)
{
return
"event-rect event-rect-"
+
i
;
}
function
classEvent
(
d
,
i
)
{
return
"event-rect event-rect-"
+
i
;
}
function
opacityCircle
(
d
)
{
function
initialOpacity
(
d
)
{
return
withoutFadeIn
[
d
.
id
]
?
1
:
0
;
}
function
initialOpacityForText
(
d
)
{
var
targetOpacity
=
opacityForText
(
d
);
return
initialOpacity
(
d
)
*
targetOpacity
;
}
function
opacityForCircle
(
d
)
{
return
isValue
(
d
.
value
)
?
isScatterType
(
d
)
?
0.5
:
1
:
0
;
return
isValue
(
d
.
value
)
?
isScatterType
(
d
)
?
0.5
:
1
:
0
;
}
}
function
opacityText
(
d
)
{
function
opacity
For
Text
(
d
)
{
if
(
typeof
__data_labels
===
'boolean'
&&
__data_labels
)
{
if
(
typeof
__data_labels
===
'boolean'
&&
__data_labels
)
{
return
1
;
return
1
;
}
else
if
(
__data_labels
[
d
.
id
]
===
'boolean'
&&
__data_labels
[
d
.
id
])
{
}
else
if
(
__data_labels
[
d
.
id
]
===
'boolean'
&&
__data_labels
[
d
.
id
])
{
...
@@ -1127,9 +1134,6 @@
...
@@ -1127,9 +1134,6 @@
});
});
return
has
;
return
has
;
}
}
function
initialOpacity
(
d
)
{
return
withoutFadeIn
[
d
.
id
]
?
1
:
0
;
}
/* not used
/* not used
function hasLineType(targets) {
function hasLineType(targets) {
...
@@ -1370,27 +1374,7 @@
...
@@ -1370,27 +1374,7 @@
};
};
})();
})();
function
generateGetBarPoints
(
barIndices
,
isSub
)
{
function
generateDrawBar
(
barIndices
,
isSub
)
{
var
barTargetsNum
=
barIndices
.
__max__
+
1
,
barW
=
getBarW
(
xAxis
,
barTargetsNum
),
x
=
getBarX
(
barW
,
barTargetsNum
,
barIndices
,
!!
isSub
),
y
=
getBarY
(
!!
isSub
),
barOffset
=
getBarOffset
(
barIndices
,
!!
isSub
),
yScale
=
isSub
?
getSubYScale
:
getYScale
;
return
function
(
d
,
i
)
{
var
y0
=
yScale
(
d
.
id
)(
0
),
offset
=
barOffset
(
d
,
i
)
||
y0
;
// offset is for stacked bar chart
// 4 points that make a bar
return
[
[
x
(
d
),
offset
],
[
x
(
d
),
y
(
d
)
-
(
y0
-
offset
)],
[
x
(
d
)
+
barW
,
y
(
d
)
-
(
y0
-
offset
)],
[
x
(
d
)
+
barW
,
offset
]
];
};
}
var
drawBar
=
function
(
barIndices
,
isSub
)
{
var
getPoints
=
generateGetBarPoints
(
barIndices
,
isSub
);
var
getPoints
=
generateGetBarPoints
(
barIndices
,
isSub
);
return
function
(
d
,
i
)
{
return
function
(
d
,
i
)
{
// 4 points that make a bar
// 4 points that make a bar
...
@@ -1408,24 +1392,49 @@
...
@@ -1408,24 +1392,49 @@
return
path
;
return
path
;
};
};
}
;
}
function
generateXYForText
(
barIndices
,
forX
)
{
var
getXYForText
=
function
(
barIndices
,
isSub
,
forX
)
{
var
getPoints
=
generateGetBarPoints
(
barIndices
,
false
),
var
getPoints
=
generateGetBarPoints
(
barIndices
,
isSub
)
;
getter
=
forX
?
getXForText
:
getYForText
;
return
function
(
d
,
i
)
{
return
function
(
d
,
i
)
{
var
points
=
getPoints
(
d
,
i
);
return
getter
(
getPoints
(
d
,
i
),
d
,
this
);
if
(
forX
)
{
};
return
__axis_rotated
?
points
[
2
][
1
]
+
(
d
.
value
<
0
?
-
4
:
4
)
:
points
[
0
][
0
]
+
(
points
[
2
][
0
]
-
points
[
0
][
0
])
/
2
;
}
function
getXForText
(
points
,
d
)
{
var
padding
;
if
(
__axis_rotated
)
{
padding
=
isBarType
(
d
)
?
4
:
6
;
return
points
[
2
][
1
]
+
padding
*
(
d
.
value
<
0
?
-
1
:
1
);
}
else
{
}
else
{
return
__axis_rotated
?
(
points
[
0
][
0
]
+
points
[
2
][
0
]
+
this
.
offsetHeight
*
0.6
)
/
2
:
points
[
2
][
1
]
+
(
d
.
value
<
0
?
this
.
offsetHeight
:
-
3
);
return
points
[
0
][
0
]
+
(
points
[
2
][
0
]
-
points
[
0
][
0
])
/
2
;
}
}
function
getYForText
(
points
,
d
,
that
)
{
if
(
__axis_rotated
)
{
return
(
points
[
0
][
0
]
+
points
[
2
][
0
]
+
that
.
offsetHeight
*
0.6
)
/
2
;
}
else
{
return
points
[
2
][
1
]
+
(
d
.
value
<
0
?
that
.
offsetHeight
:
isBarType
(
d
)
?
-
3
:
-
6
);
}
}
};
};
function
getXForText
(
barIndices
,
isSub
)
{
return
getXYForText
(
barIndices
,
isSub
,
true
);
}
}
function
getYForText
(
barIndices
,
isSub
)
{
return
getXYForText
(
barIndices
,
isSub
,
false
);
function
generateGetBarPoints
(
barIndices
,
isSub
)
{
var
barTargetsNum
=
barIndices
.
__max__
+
1
,
barW
=
getBarW
(
xAxis
,
barTargetsNum
),
x
=
getBarX
(
barW
,
barTargetsNum
,
barIndices
,
!!
isSub
),
y
=
getBarY
(
!!
isSub
),
barOffset
=
getBarOffset
(
barIndices
,
!!
isSub
),
yScale
=
isSub
?
getSubYScale
:
getYScale
;
return
function
(
d
,
i
)
{
var
y0
=
yScale
(
d
.
id
)(
0
),
offset
=
barOffset
(
d
,
i
)
||
y0
;
// offset is for stacked bar chart
// 4 points that make a bar
return
[
[
x
(
d
),
offset
],
[
x
(
d
),
y
(
d
)
-
(
y0
-
offset
)],
[
x
(
d
)
+
barW
,
y
(
d
)
-
(
y0
-
offset
)],
[
x
(
d
)
+
barW
,
offset
]
];
};
}
}
// For brush region
// For brush region
...
@@ -2108,6 +2117,8 @@
...
@@ -2108,6 +2117,8 @@
var
rectX
,
rectW
;
var
rectX
,
rectW
;
var
withY
,
withSubchart
,
withTransition
,
withTransform
,
withUpdateXDomain
,
withUpdateOrgXDomain
;
var
withY
,
withSubchart
,
withTransition
,
withTransform
,
withUpdateXDomain
,
withUpdateOrgXDomain
;
var
hideAxis
=
hasArcType
(
c3
.
data
.
targets
);
var
hideAxis
=
hasArcType
(
c3
.
data
.
targets
);
var
drawBar
=
generateDrawBar
(
barIndices
),
drawBarOnSub
=
generateDrawBar
(
barIndices
,
true
);
var
xForText
=
generateXYForText
(
barIndices
,
true
),
yForText
=
generateXYForText
(
barIndices
,
false
);
var
duration
;
var
duration
;
options
=
isDefined
(
options
)
?
options
:
{};
options
=
isDefined
(
options
)
?
options
:
{};
...
@@ -2219,7 +2230,7 @@
...
@@ -2219,7 +2230,7 @@
mainBar
=
main
.
selectAll
(
'.-bars'
).
selectAll
(
'.-bar'
)
mainBar
=
main
.
selectAll
(
'.-bars'
).
selectAll
(
'.-bar'
)
.
data
(
barData
);
.
data
(
barData
);
mainBar
.
enter
().
append
(
'path'
)
mainBar
.
enter
().
append
(
'path'
)
.
attr
(
'd'
,
drawBar
(
barIndices
)
)
.
attr
(
'd'
,
drawBar
)
.
style
(
"stroke"
,
'none'
)
.
style
(
"stroke"
,
'none'
)
.
style
(
"opacity"
,
0
)
.
style
(
"opacity"
,
0
)
.
style
(
"fill"
,
function
(
d
)
{
return
color
(
d
.
id
);
})
.
style
(
"fill"
,
function
(
d
)
{
return
color
(
d
.
id
);
})
...
@@ -2227,7 +2238,7 @@
...
@@ -2227,7 +2238,7 @@
mainBar
mainBar
.
style
(
"opacity"
,
initialOpacity
)
.
style
(
"opacity"
,
initialOpacity
)
.
transition
().
duration
(
duration
)
.
transition
().
duration
(
duration
)
.
attr
(
'd'
,
drawBar
(
barIndices
)
)
.
attr
(
'd'
,
drawBar
)
.
style
(
"opacity"
,
1
);
.
style
(
"opacity"
,
1
);
mainBar
.
exit
().
transition
().
duration
(
duration
)
mainBar
.
exit
().
transition
().
duration
(
duration
)
.
style
(
'opacity'
,
0
)
.
style
(
'opacity'
,
0
)
...
@@ -2239,17 +2250,17 @@
...
@@ -2239,17 +2250,17 @@
.
attr
(
"class"
,
classText
)
.
attr
(
"class"
,
classText
)
.
attr
(
'text-anchor'
,
function
(
d
)
{
return
__axis_rotated
?
(
d
.
value
<
0
?
'end'
:
'start'
)
:
'middle'
;
})
.
attr
(
'text-anchor'
,
function
(
d
)
{
return
__axis_rotated
?
(
d
.
value
<
0
?
'end'
:
'start'
)
:
'middle'
;
})
.
style
(
"stroke"
,
'none'
)
.
style
(
"stroke"
,
'none'
)
.
style
(
"opacity"
,
0
)
.
style
(
"
fill-
opacity"
,
0
)
.
text
(
function
(
d
)
{
return
formattedValue
(
d
.
value
);
});
.
text
(
function
(
d
)
{
return
formattedValue
(
d
.
value
);
});
mainText
mainText
.
style
(
"
opacity"
,
initialOpacity
)
.
style
(
"
fill-opacity"
,
initialOpacityForText
)
.
transition
().
duration
(
duration
)
.
transition
().
duration
(
duration
)
.
attr
(
'x'
,
getXForText
(
barIndices
)
)
.
attr
(
'x'
,
xForText
)
.
attr
(
'y'
,
getYForText
(
barIndices
)
)
.
attr
(
'y'
,
yForText
)
.
style
(
"
opacity"
,
opacity
Text
);
.
style
(
"
fill-opacity"
,
opacityFor
Text
);
mainText
.
exit
()
mainText
.
exit
()
.
transition
().
duration
(
duration
)
.
transition
().
duration
(
duration
)
.
style
(
'opacity'
,
0
)
.
style
(
'
fill-
opacity'
,
0
)
.
remove
();
.
remove
();
// lines and cricles
// lines and cricles
...
@@ -2272,7 +2283,7 @@
...
@@ -2272,7 +2283,7 @@
mainCircle
mainCircle
.
style
(
"opacity"
,
initialOpacity
)
.
style
(
"opacity"
,
initialOpacity
)
.
transition
().
duration
(
duration
)
.
transition
().
duration
(
duration
)
.
style
(
'opacity'
,
opacityCircle
)
.
style
(
'opacity'
,
opacity
For
Circle
)
.
attr
(
"cx"
,
__axis_rotated
?
circleY
:
circleX
)
.
attr
(
"cx"
,
__axis_rotated
?
circleY
:
circleX
)
.
attr
(
"cy"
,
__axis_rotated
?
circleX
:
circleY
);
.
attr
(
"cy"
,
__axis_rotated
?
circleX
:
circleY
);
mainCircle
.
exit
().
remove
();
mainCircle
.
exit
().
remove
();
...
@@ -2328,14 +2339,14 @@
...
@@ -2328,14 +2339,14 @@
contextBar
=
context
.
selectAll
(
'.-bars'
).
selectAll
(
'.-bar'
)
contextBar
=
context
.
selectAll
(
'.-bars'
).
selectAll
(
'.-bar'
)
.
data
(
barData
);
.
data
(
barData
);
contextBar
.
enter
().
append
(
'path'
)
contextBar
.
enter
().
append
(
'path'
)
.
attr
(
'd'
,
drawBar
(
barIndices
,
true
)
)
.
attr
(
'd'
,
drawBar
OnSub
)
.
style
(
"stroke"
,
'none'
)
.
style
(
"stroke"
,
'none'
)
.
style
(
"fill"
,
function
(
d
)
{
return
color
(
d
.
id
);
})
.
style
(
"fill"
,
function
(
d
)
{
return
color
(
d
.
id
);
})
.
attr
(
"class"
,
classBar
);
.
attr
(
"class"
,
classBar
);
contextBar
contextBar
.
style
(
"opacity"
,
initialOpacity
)
.
style
(
"opacity"
,
initialOpacity
)
.
transition
().
duration
(
duration
)
.
transition
().
duration
(
duration
)
.
attr
(
'd'
,
drawBar
(
barIndices
,
true
)
)
.
attr
(
'd'
,
drawBar
OnSub
)
.
style
(
'opacity'
,
1
);
.
style
(
'opacity'
,
1
);
contextBar
.
exit
().
transition
().
duration
(
duration
)
contextBar
.
exit
().
transition
().
duration
(
duration
)
.
style
(
'opacity'
,
0
)
.
style
(
'opacity'
,
0
)
...
...
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