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
d040c81d
Commit
d040c81d
authored
Sep 09, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add data.xSort option and fix the logic to closest data point - #525
parent
93c6a1eb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
76 deletions
+20
-76
c3.js
c3.js
+10
-38
c3.min.js
c3.min.js
+0
-0
config.js
src/config.js
+1
-0
data.convert.js
src/data.convert.js
+7
-5
data.js
src/data.js
+2
-33
No files found.
c3.js
View file @
d040c81d
...
...
@@ -888,6 +888,7 @@
data_xs
:
{},
data_xFormat
:
'%Y-%m-%d'
,
data_xLocaltime
:
true
,
data_xSort
:
true
,
data_idConverter
:
function
(
id
)
{
return
id
;
},
data_names
:
{},
data_classes
:
{},
...
...
@@ -1435,8 +1436,7 @@
return
this
.
d3
.
set
(
Object
.
keys
(
xs
).
map
(
function
(
id
)
{
return
xs
[
id
];
})).
size
()
>
1
;
};
c3_chart_internal_fn
.
isMultipleX
=
function
()
{
var
$$
=
this
,
config
=
$$
.
config
;
return
notEmpty
(
config
.
data_xs
);
return
notEmpty
(
this
.
config
.
data_xs
)
||
!
this
.
config
.
data_xSort
;
};
c3_chart_internal_fn
.
addName
=
function
(
data
)
{
var
$$
=
this
,
name
;
...
...
@@ -1662,42 +1662,12 @@
return
sames
;
};
c3_chart_internal_fn
.
findClosestOfValues
=
function
(
values
,
pos
,
_min
,
_max
)
{
// MEMO: values must be sorted by x
var
$$
=
this
,
min
=
_min
?
_min
:
0
,
max
=
_max
?
_max
:
values
.
length
-
1
,
med
=
Math
.
floor
((
max
-
min
)
/
2
)
+
min
,
value
=
values
[
med
],
diff
=
$$
.
x
(
value
.
x
)
-
pos
[
$$
.
config
.
axis_rotated
?
1
:
0
],
candidates
;
// Update range for search
diff
>
0
?
max
=
med
:
min
=
med
;
// if candidates are two closest min and max, stop recursive call
if
((
max
-
min
)
===
1
||
(
min
===
0
&&
max
===
0
))
{
// Get candidates that has same min and max index
candidates
=
[];
if
(
values
[
min
].
x
||
values
[
min
].
x
===
0
)
{
candidates
=
candidates
.
concat
(
$$
.
findSameXOfValues
(
values
,
min
));
}
if
(
values
[
max
].
x
||
values
[
max
].
x
===
0
)
{
candidates
=
candidates
.
concat
(
$$
.
findSameXOfValues
(
values
,
max
));
}
// Determine the closest and return
return
$$
.
findClosest
(
candidates
,
pos
);
}
return
$$
.
findClosestOfValues
(
values
,
pos
,
min
,
max
);
};
c3_chart_internal_fn
.
findClosestFromTargets
=
function
(
targets
,
pos
)
{
var
$$
=
this
,
candidates
;
// map to array of closest points of each target
candidates
=
targets
.
map
(
function
(
target
)
{
return
$$
.
findClosest
OfValues
(
target
.
values
,
pos
);
return
$$
.
findClosest
(
target
.
values
,
pos
);
});
// decide closest point and return
...
...
@@ -1871,11 +1841,13 @@
targets
.
forEach
(
function
(
t
)
{
var
i
;
// sort values by its x
t
.
values
=
t
.
values
.
sort
(
function
(
v1
,
v2
)
{
var
x1
=
v1
.
x
||
v1
.
x
===
0
?
v1
.
x
:
Infinity
,
x2
=
v2
.
x
||
v2
.
x
===
0
?
v2
.
x
:
Infinity
;
return
x1
-
x2
;
});
if
(
config
.
data_xSort
)
{
t
.
values
=
t
.
values
.
sort
(
function
(
v1
,
v2
)
{
var
x1
=
v1
.
x
||
v1
.
x
===
0
?
v1
.
x
:
Infinity
,
x2
=
v2
.
x
||
v2
.
x
===
0
?
v2
.
x
:
Infinity
;
return
x1
-
x2
;
});
}
// indexing each value
i
=
0
;
t
.
values
.
forEach
(
function
(
v
)
{
...
...
c3.min.js
View file @
d040c81d
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/config.js
View file @
d040c81d
...
...
@@ -22,6 +22,7 @@ c3_chart_internal_fn.getDefaultConfig = function () {
data_xs
:
{},
data_xFormat
:
'%Y-%m-%d'
,
data_xLocaltime
:
true
,
data_xSort
:
true
,
data_idConverter
:
function
(
id
)
{
return
id
;
},
data_names
:
{},
data_classes
:
{},
...
...
src/data.convert.js
View file @
d040c81d
...
...
@@ -147,11 +147,13 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
targets
.
forEach
(
function
(
t
)
{
var
i
;
// sort values by its x
t
.
values
=
t
.
values
.
sort
(
function
(
v1
,
v2
)
{
var
x1
=
v1
.
x
||
v1
.
x
===
0
?
v1
.
x
:
Infinity
,
x2
=
v2
.
x
||
v2
.
x
===
0
?
v2
.
x
:
Infinity
;
return
x1
-
x2
;
});
if
(
config
.
data_xSort
)
{
t
.
values
=
t
.
values
.
sort
(
function
(
v1
,
v2
)
{
var
x1
=
v1
.
x
||
v1
.
x
===
0
?
v1
.
x
:
Infinity
,
x2
=
v2
.
x
||
v2
.
x
===
0
?
v2
.
x
:
Infinity
;
return
x1
-
x2
;
});
}
// indexing each value
i
=
0
;
t
.
values
.
forEach
(
function
(
v
)
{
...
...
src/data.js
View file @
d040c81d
...
...
@@ -47,8 +47,7 @@ c3_chart_internal_fn.hasMultipleX = function (xs) {
return
this
.
d3
.
set
(
Object
.
keys
(
xs
).
map
(
function
(
id
)
{
return
xs
[
id
];
})).
size
()
>
1
;
};
c3_chart_internal_fn
.
isMultipleX
=
function
()
{
var
$$
=
this
,
config
=
$$
.
config
;
return
notEmpty
(
config
.
data_xs
);
return
notEmpty
(
this
.
config
.
data_xs
)
||
!
this
.
config
.
data_xSort
;
};
c3_chart_internal_fn
.
addName
=
function
(
data
)
{
var
$$
=
this
,
name
;
...
...
@@ -274,42 +273,12 @@ c3_chart_internal_fn.findSameXOfValues = function (values, index) {
return
sames
;
};
c3_chart_internal_fn
.
findClosestOfValues
=
function
(
values
,
pos
,
_min
,
_max
)
{
// MEMO: values must be sorted by x
var
$$
=
this
,
min
=
_min
?
_min
:
0
,
max
=
_max
?
_max
:
values
.
length
-
1
,
med
=
Math
.
floor
((
max
-
min
)
/
2
)
+
min
,
value
=
values
[
med
],
diff
=
$$
.
x
(
value
.
x
)
-
pos
[
$$
.
config
.
axis_rotated
?
1
:
0
],
candidates
;
// Update range for search
diff
>
0
?
max
=
med
:
min
=
med
;
// if candidates are two closest min and max, stop recursive call
if
((
max
-
min
)
===
1
||
(
min
===
0
&&
max
===
0
))
{
// Get candidates that has same min and max index
candidates
=
[];
if
(
values
[
min
].
x
||
values
[
min
].
x
===
0
)
{
candidates
=
candidates
.
concat
(
$$
.
findSameXOfValues
(
values
,
min
));
}
if
(
values
[
max
].
x
||
values
[
max
].
x
===
0
)
{
candidates
=
candidates
.
concat
(
$$
.
findSameXOfValues
(
values
,
max
));
}
// Determine the closest and return
return
$$
.
findClosest
(
candidates
,
pos
);
}
return
$$
.
findClosestOfValues
(
values
,
pos
,
min
,
max
);
};
c3_chart_internal_fn
.
findClosestFromTargets
=
function
(
targets
,
pos
)
{
var
$$
=
this
,
candidates
;
// map to array of closest points of each target
candidates
=
targets
.
map
(
function
(
target
)
{
return
$$
.
findClosest
OfValues
(
target
.
values
,
pos
);
return
$$
.
findClosest
(
target
.
values
,
pos
);
});
// decide closest point and return
...
...
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