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
da9db272
Commit
da9db272
authored
Jul 13, 2015
by
Edmundo Alvarez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spline custom interpolation
With these changes it is possible to set a custom spline interpolation by giving a valid d3 interpolation to spline.interpolation.type. Fixes #479
parent
4b34a195
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
2 deletions
+53
-2
shape.line-spec.js
spec/shape.line-spec.js
+46
-1
config.js
src/config.js
+2
-0
shape.js
src/shape.js
+2
-1
type.js
src/type.js
+3
-0
No files found.
spec/shape.line-spec.js
View file @
da9db272
...
...
@@ -30,7 +30,7 @@ describe('c3 chart shape line', function () {
});
});
it
(
'should ch
na
ge to step chart'
,
function
()
{
it
(
'should ch
an
ge to step chart'
,
function
()
{
args
.
data
.
type
=
'step'
;
expect
(
true
).
toBeTruthy
();
});
...
...
@@ -42,6 +42,15 @@ describe('c3 chart shape line', function () {
});
});
it
(
'should change to spline chart'
,
function
()
{
args
.
data
.
type
=
'spline'
;
expect
(
true
).
toBeTruthy
();
});
it
(
'should use cardinal interpolation by default'
,
function
()
{
expect
(
chart
.
internal
.
config
.
spline_interpolation_type
).
toBe
(
'cardinal'
);
});
});
describe
(
'point.show option'
,
function
()
{
...
...
@@ -96,4 +105,40 @@ describe('c3 chart shape line', function () {
});
describe
(
'spline.interpolation option'
,
function
()
{
it
(
'should update args'
,
function
()
{
args
=
{
data
:
{
columns
:
[
[
'data1'
,
30
,
200
,
100
,
400
,
-
150
,
250
],
[
'data2'
,
50
,
20
,
10
,
40
,
15
,
25
],
[
'data3'
,
-
150
,
120
,
110
,
140
,
115
,
125
]
],
type
:
'spline'
},
spline
:
{
interpolation
:
{
type
:
'monotone'
}
}
};
expect
(
true
).
toBeTruthy
();
});
it
(
'should update interpolation function'
,
function
()
{
expect
(
chart
.
internal
.
getInterpolate
(
chart
.
data
()[
0
])).
toBe
(
'monotone'
);
});
it
(
'should not use a non-valid interpolation'
,
function
()
{
args
.
spline
.
interpolation
.
type
=
'foo'
;
expect
(
true
).
toBeTruthy
();
});
it
(
'should use cardinal interpolation when given option is not valid'
,
function
()
{
expect
(
chart
.
internal
.
getInterpolate
(
chart
.
data
()[
0
])).
toBe
(
'cardinal'
);
});
});
});
src/config.js
View file @
da9db272
...
...
@@ -188,6 +188,8 @@ c3_chart_internal_fn.getDefaultConfig = function () {
donut_title
:
""
,
donut_expand
:
{},
donut_expand_duration
:
50
,
// spline
spline_interpolation_type
:
'cardinal'
,
// region - region to change style
regions
:
[],
// tooltip - show when mouseover on each data
...
...
src/shape.js
View file @
da9db272
...
...
@@ -67,5 +67,6 @@ c3_chart_internal_fn.isWithinShape = function (that, d) {
c3_chart_internal_fn
.
getInterpolate
=
function
(
d
)
{
var
$$
=
this
;
return
$$
.
isSplineType
(
d
)
?
"cardinal"
:
$$
.
isStepType
(
d
)
?
$$
.
config
.
line_step_type
:
"linear"
;
var
interpolation
=
$$
.
isInterpolationType
()
?
$$
.
config
.
spline_interpolation_type
:
'cardinal'
;
return
$$
.
isSplineType
(
d
)
?
interpolation
:
$$
.
isStepType
(
d
)
?
$$
.
config
.
line_step_type
:
"linear"
;
};
src/type.js
View file @
da9db272
...
...
@@ -89,3 +89,6 @@ c3_chart_internal_fn.lineOrScatterData = function (d) {
c3_chart_internal_fn
.
barOrLineData
=
function
(
d
)
{
return
this
.
isBarType
(
d
)
||
this
.
isLineType
(
d
)
?
d
.
values
:
[];
};
c3_chart_internal_fn
.
isInterpolationType
=
function
()
{
return
[
'linear'
,
'linear-closed'
,
'basis'
,
'basis-open'
,
'basis-closed'
,
'bundle'
,
'cardinal'
,
'cardinal-open'
,
'cardinal-closed'
,
'monotone'
].
indexOf
(
this
.
config
.
spline_interpolation_type
)
>=
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