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
e3c291fc
Commit
e3c291fc
authored
Mar 10, 2015
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix convert json not to mutate input object - #993
parent
73ec414d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
4 deletions
+76
-4
c3.js
c3.js
+3
-2
c3.min.js
c3.min.js
+0
-0
data-spec.js
spec/data-spec.js
+70
-0
data.convert.js
src/data.convert.js
+3
-2
No files found.
c3.js
View file @
e3c291fc
...
...
@@ -1977,10 +1977,11 @@
var
$$
=
this
,
new_rows
=
[],
targetKeys
,
data
;
if
(
keys
)
{
// when keys specified, json would be an array that includes objects
targetKeys
=
keys
.
value
;
if
(
keys
.
x
)
{
targetKeys
.
push
(
keys
.
x
);
targetKeys
=
keys
.
value
.
concat
(
keys
.
x
);
$$
.
config
.
data_x
=
keys
.
x
;
}
else
{
targetKeys
=
keys
.
value
;
}
new_rows
.
push
(
targetKeys
);
json
.
forEach
(
function
(
o
)
{
...
...
c3.min.js
View file @
e3c291fc
This source diff could not be displayed because it is too large. You can
view the blob
instead.
spec/data-spec.js
View file @
e3c291fc
...
...
@@ -7,6 +7,76 @@ describe('c3 chart data', function () {
chart
=
window
.
initChart
(
chart
,
args
,
done
);
});
describe
(
'load json'
,
function
()
{
it
(
'should update args'
,
function
()
{
args
=
{
data
:
{
json
:
{
data1
:
[
30
,
20
,
50
],
data2
:
[
200
,
130
,
90
]
}
}
};
expect
(
true
).
toBeTruthy
();
});
it
(
'should draw correctly'
,
function
()
{
var
expectedCx
=
[
6
,
299
,
593
],
expectedCy
=
[
370
,
390
,
331
];
d3
.
selectAll
(
'.c3-circles-data1 .c3-circle'
).
each
(
function
(
d
,
i
)
{
var
circle
=
d3
.
select
(
this
);
expect
(
+
circle
.
attr
(
'cx'
)).
toBeCloseTo
(
expectedCx
[
i
],
-
2
);
expect
(
+
circle
.
attr
(
'cy'
)).
toBeCloseTo
(
expectedCy
[
i
],
-
2
);
});
});
it
(
'should update args'
,
function
()
{
args
=
{
data
:
{
json
:
[{
"date"
:
"2014-06-03"
,
"443"
:
"3000"
,
"995"
:
"500"
},
{
"date"
:
"2014-06-04"
,
"443"
:
"1000"
},
{
"date"
:
"2014-06-05"
,
"443"
:
"5000"
,
"995"
:
"1000"
}],
keys
:
{
x
:
'date'
,
value
:
[
"443"
,
"995"
]
}
},
axis
:
{
x
:
{
type
:
"category"
}
}
};
expect
(
true
).
toBeTruthy
();
});
it
(
'should draw correctly'
,
function
()
{
var
expectedCx
=
{
443
:
[
98
,
294
,
490
],
995
:
[
98
,
294
,
490
]},
expectedCy
=
{
443
:
[
193
,
351
,
36
],
995
:
[
390
,
429
,
351
]};
d3
.
selectAll
(
'.c3-circles-443 .c3-circle'
).
each
(
function
(
d
,
i
)
{
var
circle
=
d3
.
select
(
this
);
expect
(
+
circle
.
attr
(
'cx'
)).
toBeCloseTo
(
expectedCx
[
443
][
i
],
-
2
);
expect
(
+
circle
.
attr
(
'cy'
)).
toBeCloseTo
(
expectedCy
[
443
][
i
],
-
2
);
});
d3
.
selectAll
(
'.c3-circles-995 .c3-circle'
).
each
(
function
(
d
,
i
)
{
var
circle
=
d3
.
select
(
this
);
expect
(
+
circle
.
attr
(
'cx'
)).
toBeCloseTo
(
expectedCx
[
995
][
i
],
-
2
);
expect
(
+
circle
.
attr
(
'cy'
)).
toBeCloseTo
(
expectedCy
[
995
][
i
],
-
2
);
});
});
});
describe
(
'function in data.order'
,
function
()
{
it
(
'should update args'
,
function
()
{
args
=
{
...
...
src/data.convert.js
View file @
e3c291fc
...
...
@@ -37,10 +37,11 @@ c3_chart_internal_fn.convertJsonToData = function (json, keys) {
var
$$
=
this
,
new_rows
=
[],
targetKeys
,
data
;
if
(
keys
)
{
// when keys specified, json would be an array that includes objects
targetKeys
=
keys
.
value
;
if
(
keys
.
x
)
{
targetKeys
.
push
(
keys
.
x
);
targetKeys
=
keys
.
value
.
concat
(
keys
.
x
);
$$
.
config
.
data_x
=
keys
.
x
;
}
else
{
targetKeys
=
keys
.
value
;
}
new_rows
.
push
(
targetKeys
);
json
.
forEach
(
function
(
o
)
{
...
...
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