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
531f2a2e
Commit
531f2a2e
authored
Mar 26, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AMD compatible - #92 #83
parent
364b34b6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
181 additions
and
174 deletions
+181
-174
c3.js
c3.js
+181
-174
c3.min.js
c3.min.js
+0
-0
No files found.
c3.js
View file @
531f2a2e
(
function
(
window
)
{
(
function
(
window
)
{
'use strict'
;
'use strict'
;
var
c3
=
window
.
c3
=
{};
var
c3
=
{};
var
d3
=
window
.
d3
;
/*
/*
* Generate chart according to config
* Generate chart according to config
*/
*/
c3
.
generate
=
function
(
config
)
{
c3
.
generate
=
function
(
config
)
{
var
d3
=
window
.
d3
?
window
.
d3
:
window
.
require
?
window
.
require
(
"d3"
)
:
undefined
;
var
c3
=
{
data
:
{}
},
var
c3
=
{
data
:
{}
},
cache
=
{};
cache
=
{};
...
@@ -668,6 +669,177 @@
...
@@ -668,6 +669,177 @@
return
maxWidth
;
return
maxWidth
;
}
}
function
categoryAxis
()
{
var
scale
=
d3
.
scale
.
linear
(),
orient
=
"bottom"
;
var
tickMajorSize
=
6
,
/*tickMinorSize = 6,*/
tickEndSize
=
6
,
tickPadding
=
3
,
tickCentered
=
false
,
tickTextNum
=
10
,
tickOffset
=
0
,
tickFormat
=
null
,
tickCulling
=
true
;
var
categories
=
[];
function
axisX
(
selection
,
x
)
{
selection
.
attr
(
"transform"
,
function
(
d
)
{
return
"translate("
+
(
x
(
d
)
+
tickOffset
)
+
", 0)"
;
});
}
function
axisY
(
selection
,
y
)
{
selection
.
attr
(
"transform"
,
function
(
d
)
{
return
"translate(0,"
+
y
(
d
)
+
")"
;
});
}
function
scaleExtent
(
domain
)
{
var
start
=
domain
[
0
],
stop
=
domain
[
domain
.
length
-
1
];
return
start
<
stop
?
[
start
,
stop
]
:
[
stop
,
start
];
}
function
generateTicks
(
domain
)
{
var
ticks
=
[];
for
(
var
i
=
Math
.
ceil
(
domain
[
0
]);
i
<
domain
[
1
];
i
++
)
{
ticks
.
push
(
i
);
}
if
(
ticks
.
length
>
0
&&
ticks
[
0
]
>
0
)
{
ticks
.
unshift
(
ticks
[
0
]
-
(
ticks
[
1
]
-
ticks
[
0
]));
}
return
ticks
;
}
function
shouldShowTickText
(
ticks
,
i
)
{
var
length
=
ticks
.
length
-
1
;
return
length
<=
tickTextNum
||
i
%
Math
.
ceil
(
length
/
tickTextNum
)
===
0
;
}
function
category
(
i
)
{
return
i
<
categories
.
length
?
categories
[
i
]
:
i
;
}
function
formattedCategory
(
i
)
{
var
c
=
category
(
i
);
return
tickFormat
?
tickFormat
(
c
)
:
c
;
}
function
axis
(
g
)
{
g
.
each
(
function
()
{
var
g
=
d3
.
select
(
this
);
var
ticks
=
generateTicks
(
scale
.
domain
());
var
tick
=
g
.
selectAll
(
".tick.major"
).
data
(
ticks
,
String
),
tickEnter
=
tick
.
enter
().
insert
(
"g"
,
"path"
).
attr
(
"class"
,
"tick major"
).
style
(
"opacity"
,
1
e
-
6
),
tickExit
=
d3
.
transition
(
tick
.
exit
()).
style
(
"opacity"
,
1
e
-
6
).
remove
(),
tickUpdate
=
d3
.
transition
(
tick
).
style
(
"opacity"
,
1
),
tickTransform
,
tickX
;
var
range
=
scale
.
rangeExtent
?
scale
.
rangeExtent
()
:
scaleExtent
(
scale
.
range
()),
path
=
g
.
selectAll
(
".domain"
).
data
([
0
]);
path
.
enter
().
append
(
"path"
).
attr
(
"class"
,
"domain"
);
var
pathUpdate
=
d3
.
transition
(
path
);
var
scale1
=
scale
.
copy
(),
scale0
=
this
.
__chart__
||
scale1
;
this
.
__chart__
=
scale1
;
tickEnter
.
append
(
"line"
);
tickEnter
.
append
(
"text"
);
var
lineEnter
=
tickEnter
.
select
(
"line"
),
lineUpdate
=
tickUpdate
.
select
(
"line"
),
text
=
tick
.
select
(
"text"
),
textEnter
=
tickEnter
.
select
(
"text"
),
textUpdate
=
tickUpdate
.
select
(
"text"
);
tickOffset
=
(
scale1
(
1
)
-
scale1
(
0
))
/
2
;
tickX
=
tickCentered
?
0
:
tickOffset
;
switch
(
orient
)
{
case
"bottom"
:
{
tickTransform
=
axisX
;
lineEnter
.
attr
(
"y2"
,
tickMajorSize
);
textEnter
.
attr
(
"y"
,
Math
.
max
(
tickMajorSize
,
0
)
+
tickPadding
);
lineUpdate
.
attr
(
"x1"
,
tickX
).
attr
(
"x2"
,
tickX
).
attr
(
"y2"
,
tickMajorSize
);
textUpdate
.
attr
(
"x"
,
0
).
attr
(
"y"
,
Math
.
max
(
tickMajorSize
,
0
)
+
tickPadding
);
text
.
attr
(
"dy"
,
".71em"
).
style
(
"text-anchor"
,
"middle"
);
text
.
text
(
function
(
i
)
{
return
shouldShowTickText
(
ticks
,
i
)
?
formattedCategory
(
i
)
:
""
;
});
pathUpdate
.
attr
(
"d"
,
"M"
+
range
[
0
]
+
","
+
tickEndSize
+
"V0H"
+
range
[
1
]
+
"V"
+
tickEndSize
);
break
;
}
/* TODO: implement
case "top":
{
tickTransform = axisX
lineEnter.attr("y2", -tickMajorSize)
textEnter.attr("y", -(Math.max(tickMajorSize, 0) + tickPadding))
lineUpdate.attr("x2", 0).attr("y2", -tickMajorSize)
textUpdate.attr("x", 0).attr("y", -(Math.max(tickMajorSize, 0) + tickPadding))
text.attr("dy", "0em").style("text-anchor", "middle")
pathUpdate.attr("d", "M" + range[0] + "," + -tickEndSize + "V0H" + range[1] + "V" + -tickEndSize)
break
}
*/
case
"left"
:
{
tickTransform
=
axisY
;
lineEnter
.
attr
(
"x2"
,
-
tickMajorSize
);
textEnter
.
attr
(
"x"
,
-
(
Math
.
max
(
tickMajorSize
,
0
)
+
tickPadding
));
lineUpdate
.
attr
(
"x2"
,
-
tickMajorSize
).
attr
(
"y2"
,
0
);
textUpdate
.
attr
(
"x"
,
-
(
Math
.
max
(
tickMajorSize
,
0
)
+
tickPadding
)).
attr
(
"y"
,
tickOffset
);
text
.
attr
(
"dy"
,
".32em"
).
style
(
"text-anchor"
,
"end"
);
text
.
text
(
function
(
i
)
{
return
shouldShowTickText
(
ticks
,
i
)
?
formattedCategory
(
i
)
:
""
;
});
pathUpdate
.
attr
(
"d"
,
"M"
+
-
tickEndSize
+
","
+
range
[
0
]
+
"H0V"
+
range
[
1
]
+
"H"
+
-
tickEndSize
);
break
;
}
/*
case "right":
{
tickTransform = axisY
lineEnter.attr("x2", tickMajorSize)
textEnter.attr("x", Math.max(tickMajorSize, 0) + tickPadding)
lineUpdate.attr("x2", tickMajorSize).attr("y2", 0)
textUpdate.attr("x", Math.max(tickMajorSize, 0) + tickPadding).attr("y", 0)
text.attr("dy", ".32em").style("text-anchor", "start")
pathUpdate.attr("d", "M" + tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + tickEndSize)
break
}
*/
}
if
(
scale
.
ticks
)
{
tickEnter
.
call
(
tickTransform
,
scale0
);
tickUpdate
.
call
(
tickTransform
,
scale1
);
tickExit
.
call
(
tickTransform
,
scale1
);
}
else
{
var
dx
=
scale1
.
rangeBand
()
/
2
,
x
=
function
(
d
)
{
return
scale1
(
d
)
+
dx
;
};
tickEnter
.
call
(
tickTransform
,
x
);
tickUpdate
.
call
(
tickTransform
,
x
);
}
});
}
axis
.
scale
=
function
(
x
)
{
if
(
!
arguments
.
length
)
{
return
scale
;
}
scale
=
x
;
return
axis
;
};
axis
.
orient
=
function
(
x
)
{
if
(
!
arguments
.
length
)
{
return
orient
;
}
orient
=
x
in
{
top
:
1
,
right
:
1
,
bottom
:
1
,
left
:
1
}
?
x
+
""
:
"bottom"
;
return
axis
;
};
axis
.
categories
=
function
(
x
)
{
if
(
!
arguments
.
length
)
{
return
categories
;
}
categories
=
x
;
return
axis
;
};
axis
.
tickCentered
=
function
(
x
)
{
if
(
!
arguments
.
length
)
{
return
tickCentered
;
}
tickCentered
=
x
;
return
axis
;
};
axis
.
tickFormat
=
function
(
format
)
{
if
(
!
arguments
.
length
)
{
return
tickFormat
;
}
tickFormat
=
format
;
return
axis
;
};
axis
.
tickOffset
=
function
()
{
return
tickOffset
;
};
axis
.
ticks
=
function
(
n
)
{
if
(
!
arguments
.
length
)
{
return
tickTextNum
;
}
tickTextNum
=
n
;
return
axis
;
};
axis
.
tickCulling
=
function
(
culling
)
{
if
(
!
arguments
.
length
)
{
return
tickCulling
;
}
tickCulling
=
culling
;
return
axis
;
};
return
axis
;
}
//-- Arc --//
//-- Arc --//
pie
=
d3
.
layout
.
pie
().
value
(
function
(
d
)
{
pie
=
d3
.
layout
.
pie
().
value
(
function
(
d
)
{
...
@@ -3538,178 +3710,6 @@
...
@@ -3538,178 +3710,6 @@
return
c3
;
return
c3
;
};
};
function
categoryAxis
()
{
var
scale
=
d3
.
scale
.
linear
(),
orient
=
"bottom"
;
var
tickMajorSize
=
6
,
/*tickMinorSize = 6,*/
tickEndSize
=
6
,
tickPadding
=
3
,
tickCentered
=
false
,
tickTextNum
=
10
,
tickOffset
=
0
,
tickFormat
=
null
,
tickCulling
=
true
;
var
categories
=
[];
function
axisX
(
selection
,
x
)
{
selection
.
attr
(
"transform"
,
function
(
d
)
{
return
"translate("
+
(
x
(
d
)
+
tickOffset
)
+
", 0)"
;
});
}
function
axisY
(
selection
,
y
)
{
selection
.
attr
(
"transform"
,
function
(
d
)
{
return
"translate(0,"
+
y
(
d
)
+
")"
;
});
}
function
scaleExtent
(
domain
)
{
var
start
=
domain
[
0
],
stop
=
domain
[
domain
.
length
-
1
];
return
start
<
stop
?
[
start
,
stop
]
:
[
stop
,
start
];
}
function
generateTicks
(
domain
)
{
var
ticks
=
[];
for
(
var
i
=
Math
.
ceil
(
domain
[
0
]);
i
<
domain
[
1
];
i
++
)
{
ticks
.
push
(
i
);
}
if
(
ticks
.
length
>
0
&&
ticks
[
0
]
>
0
)
{
ticks
.
unshift
(
ticks
[
0
]
-
(
ticks
[
1
]
-
ticks
[
0
]));
}
return
ticks
;
}
function
shouldShowTickText
(
ticks
,
i
)
{
var
length
=
ticks
.
length
-
1
;
return
length
<=
tickTextNum
||
i
%
Math
.
ceil
(
length
/
tickTextNum
)
===
0
;
}
function
category
(
i
)
{
return
i
<
categories
.
length
?
categories
[
i
]
:
i
;
}
function
formattedCategory
(
i
)
{
var
c
=
category
(
i
);
return
tickFormat
?
tickFormat
(
c
)
:
c
;
}
function
axis
(
g
)
{
g
.
each
(
function
()
{
var
g
=
d3
.
select
(
this
);
var
ticks
=
generateTicks
(
scale
.
domain
());
var
tick
=
g
.
selectAll
(
".tick.major"
).
data
(
ticks
,
String
),
tickEnter
=
tick
.
enter
().
insert
(
"g"
,
"path"
).
attr
(
"class"
,
"tick major"
).
style
(
"opacity"
,
1
e
-
6
),
tickExit
=
d3
.
transition
(
tick
.
exit
()).
style
(
"opacity"
,
1
e
-
6
).
remove
(),
tickUpdate
=
d3
.
transition
(
tick
).
style
(
"opacity"
,
1
),
tickTransform
,
tickX
;
var
range
=
scale
.
rangeExtent
?
scale
.
rangeExtent
()
:
scaleExtent
(
scale
.
range
()),
path
=
g
.
selectAll
(
".domain"
).
data
([
0
]);
path
.
enter
().
append
(
"path"
).
attr
(
"class"
,
"domain"
);
var
pathUpdate
=
d3
.
transition
(
path
);
var
scale1
=
scale
.
copy
(),
scale0
=
this
.
__chart__
||
scale1
;
this
.
__chart__
=
scale1
;
tickEnter
.
append
(
"line"
);
tickEnter
.
append
(
"text"
);
var
lineEnter
=
tickEnter
.
select
(
"line"
),
lineUpdate
=
tickUpdate
.
select
(
"line"
),
text
=
tick
.
select
(
"text"
),
textEnter
=
tickEnter
.
select
(
"text"
),
textUpdate
=
tickUpdate
.
select
(
"text"
);
tickOffset
=
(
scale1
(
1
)
-
scale1
(
0
))
/
2
;
tickX
=
tickCentered
?
0
:
tickOffset
;
switch
(
orient
)
{
case
"bottom"
:
{
tickTransform
=
axisX
;
lineEnter
.
attr
(
"y2"
,
tickMajorSize
);
textEnter
.
attr
(
"y"
,
Math
.
max
(
tickMajorSize
,
0
)
+
tickPadding
);
lineUpdate
.
attr
(
"x1"
,
tickX
).
attr
(
"x2"
,
tickX
).
attr
(
"y2"
,
tickMajorSize
);
textUpdate
.
attr
(
"x"
,
0
).
attr
(
"y"
,
Math
.
max
(
tickMajorSize
,
0
)
+
tickPadding
);
text
.
attr
(
"dy"
,
".71em"
).
style
(
"text-anchor"
,
"middle"
);
text
.
text
(
function
(
i
)
{
return
shouldShowTickText
(
ticks
,
i
)
?
formattedCategory
(
i
)
:
""
;
});
pathUpdate
.
attr
(
"d"
,
"M"
+
range
[
0
]
+
","
+
tickEndSize
+
"V0H"
+
range
[
1
]
+
"V"
+
tickEndSize
);
}
break
;
/* TODO: implement
case "top":
{
tickTransform = axisX
lineEnter.attr("y2", -tickMajorSize)
textEnter.attr("y", -(Math.max(tickMajorSize, 0) + tickPadding))
lineUpdate.attr("x2", 0).attr("y2", -tickMajorSize)
textUpdate.attr("x", 0).attr("y", -(Math.max(tickMajorSize, 0) + tickPadding))
text.attr("dy", "0em").style("text-anchor", "middle")
pathUpdate.attr("d", "M" + range[0] + "," + -tickEndSize + "V0H" + range[1] + "V" + -tickEndSize)
break
}
*/
case
"left"
:
{
tickTransform
=
axisY
;
lineEnter
.
attr
(
"x2"
,
-
tickMajorSize
);
textEnter
.
attr
(
"x"
,
-
(
Math
.
max
(
tickMajorSize
,
0
)
+
tickPadding
));
lineUpdate
.
attr
(
"x2"
,
-
tickMajorSize
).
attr
(
"y2"
,
0
);
textUpdate
.
attr
(
"x"
,
-
(
Math
.
max
(
tickMajorSize
,
0
)
+
tickPadding
)).
attr
(
"y"
,
tickOffset
);
text
.
attr
(
"dy"
,
".32em"
).
style
(
"text-anchor"
,
"end"
);
text
.
text
(
function
(
i
)
{
return
shouldShowTickText
(
ticks
,
i
)
?
formattedCategory
(
i
)
:
""
;
});
pathUpdate
.
attr
(
"d"
,
"M"
+
-
tickEndSize
+
","
+
range
[
0
]
+
"H0V"
+
range
[
1
]
+
"H"
+
-
tickEndSize
);
break
;
}
/*
case "right":
{
tickTransform = axisY
lineEnter.attr("x2", tickMajorSize)
textEnter.attr("x", Math.max(tickMajorSize, 0) + tickPadding)
lineUpdate.attr("x2", tickMajorSize).attr("y2", 0)
textUpdate.attr("x", Math.max(tickMajorSize, 0) + tickPadding).attr("y", 0)
text.attr("dy", ".32em").style("text-anchor", "start")
pathUpdate.attr("d", "M" + tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + tickEndSize)
break
}
*/
}
if
(
scale
.
ticks
)
{
tickEnter
.
call
(
tickTransform
,
scale0
);
tickUpdate
.
call
(
tickTransform
,
scale1
);
tickExit
.
call
(
tickTransform
,
scale1
);
}
else
{
var
dx
=
scale1
.
rangeBand
()
/
2
,
x
=
function
(
d
)
{
return
scale1
(
d
)
+
dx
;
};
tickEnter
.
call
(
tickTransform
,
x
);
tickUpdate
.
call
(
tickTransform
,
x
);
}
});
}
axis
.
scale
=
function
(
x
)
{
if
(
!
arguments
.
length
)
{
return
scale
;
}
scale
=
x
;
return
axis
;
};
axis
.
orient
=
function
(
x
)
{
if
(
!
arguments
.
length
)
{
return
orient
;
}
orient
=
x
in
{
top
:
1
,
right
:
1
,
bottom
:
1
,
left
:
1
}
?
x
+
""
:
"bottom"
;
return
axis
;
};
axis
.
categories
=
function
(
x
)
{
if
(
!
arguments
.
length
)
{
return
categories
;
}
categories
=
x
;
return
axis
;
};
axis
.
tickCentered
=
function
(
x
)
{
if
(
!
arguments
.
length
)
{
return
tickCentered
;
}
tickCentered
=
x
;
return
axis
;
};
axis
.
tickFormat
=
function
(
format
)
{
if
(
!
arguments
.
length
)
{
return
tickFormat
;
}
tickFormat
=
format
;
return
axis
;
};
axis
.
tickOffset
=
function
()
{
return
tickOffset
;
};
axis
.
ticks
=
function
(
n
)
{
if
(
!
arguments
.
length
)
{
return
tickTextNum
;
}
tickTextNum
=
n
;
return
axis
;
};
axis
.
tickCulling
=
function
(
culling
)
{
if
(
!
arguments
.
length
)
{
return
tickCulling
;
}
tickCulling
=
culling
;
return
axis
;
};
return
axis
;
}
function
isValue
(
v
)
{
function
isValue
(
v
)
{
return
v
||
v
===
0
;
return
v
||
v
===
0
;
}
}
...
@@ -3720,4 +3720,11 @@
...
@@ -3720,4 +3720,11 @@
return
typeof
v
!==
'undefined'
;
return
typeof
v
!==
'undefined'
;
}
}
if
(
typeof
window
.
define
===
"function"
&&
window
.
define
.
amd
)
{
window
.
define
(
c3
);
}
else
{
window
.
c3
=
c3
;
}
// TODO: module.exports
})(
window
);
})(
window
);
c3.min.js
View file @
531f2a2e
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