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
74880d64
Commit
74880d64
authored
Jun 06, 2015
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor #1086 and add spec
parent
cdecc19f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
54 deletions
+22
-54
c3.js
c3.js
+5
-21
c3.min.js
c3.min.js
+0
-0
data-spec.js
spec/data-spec.js
+12
-12
data.convert.js
src/data.convert.js
+4
-20
text.js
src/text.js
+1
-1
No files found.
c3.js
View file @
74880d64
...
...
@@ -2066,12 +2066,8 @@
var
$$
=
this
,
config
=
$$
.
config
,
ids
=
$$
.
d3
.
keys
(
data
[
0
]).
filter
(
$$
.
isNotX
,
$$
),
xs
=
$$
.
d3
.
keys
(
data
[
0
]).
filter
(
$$
.
isX
,
$$
),
zeroUnderYAxis
=
true
,
allZero
=
true
,
targets
;
$$
.
allDataIsNegative
=
true
;
// save x for update data by load when custom x and c3.x API
ids
.
forEach
(
function
(
id
)
{
var
xKey
=
$$
.
getXKey
(
id
);
...
...
@@ -2114,8 +2110,7 @@
id
:
convertedId
,
id_org
:
id
,
values
:
data
.
map
(
function
(
d
,
i
)
{
var
xKey
=
$$
.
getXKey
(
id
),
rawX
=
d
[
xKey
],
x
=
$$
.
generateTargetX
(
rawX
,
id
,
i
),
var
xKey
=
$$
.
getXKey
(
id
),
rawX
=
d
[
xKey
],
x
=
$$
.
generateTargetX
(
rawX
,
id
,
i
),
value
=
d
[
id
]
!==
null
&&
!
isNaN
(
d
[
id
])
?
+
d
[
id
]
:
null
;
// use x as categories if custom x and categorized
if
(
$$
.
isCustomX
()
&&
$$
.
isCategorized
()
&&
index
===
0
&&
rawX
)
{
...
...
@@ -2126,15 +2121,6 @@
if
(
isUndefined
(
d
[
id
])
||
$$
.
data
.
xs
[
id
].
length
<=
i
)
{
x
=
undefined
;
}
if
(
value
!==
null
&&
value
!==
0
)
{
allZero
=
false
;
}
if
(
value
>
0
)
{
zeroUnderYAxis
=
false
;
}
return
{
x
:
x
,
value
:
value
,
id
:
convertedId
};
}).
filter
(
function
(
v
)
{
return
isDefined
(
v
.
x
);
})
};
...
...
@@ -2162,11 +2148,9 @@
});
});
if
(
allZero
)
{
zeroUnderYAxis
=
false
;
}
$$
.
zeroUnderYAxis
=
zeroUnderYAxis
;
// cache information about values
$$
.
hasNegativeValue
=
$$
.
hasNegativeValueInTargets
(
targets
);
$$
.
hasPositiveValue
=
$$
.
hasPositiveValueInTargets
(
targets
);
// set target types
if
(
config
.
data_type
)
{
...
...
@@ -3408,7 +3392,7 @@
yPos
=
(
points
[
0
][
0
]
+
points
[
2
][
0
]
+
box
.
height
*
0.6
)
/
2
;
}
else
{
yPos
=
points
[
2
][
1
];
if
(
d
.
value
<
0
||
(
d
.
value
===
0
&&
$$
.
zeroUnderYAxis
))
{
if
(
d
.
value
<
0
||
(
d
.
value
===
0
&&
!
$$
.
hasPositiveValue
))
{
yPos
+=
box
.
height
;
if
(
$$
.
isBarType
(
d
)
&&
$$
.
isSafari
())
{
yPos
-=
3
;
...
...
c3.min.js
View file @
74880d64
This source diff could not be displayed because it is too large. You can
view the blob
instead.
spec/data-spec.js
View file @
74880d64
...
...
@@ -755,7 +755,7 @@ describe('c3 chart data', function () {
});
describe
(
'with
posi
tive values and null'
,
function
()
{
describe
(
'with
nega
tive values and null'
,
function
()
{
describe
(
'on not rotated axis'
,
function
()
{
...
...
@@ -763,7 +763,7 @@ describe('c3 chart data', function () {
args
=
{
data
:
{
columns
:
[
[
'data1'
,
-
190
,
-
20
0
,
-
190
,
null
],
[
'data1'
,
-
190
,
0
,
-
190
,
null
],
],
type
:
'bar'
,
labels
:
{
...
...
@@ -781,13 +781,13 @@ describe('c3 chart data', function () {
it
(
'should have y domain with proper padding'
,
function
()
{
var
domain
=
chart
.
internal
.
y
.
domain
();
expect
(
domain
[
0
]).
toBeCloseTo
(
-
2
27
,
-
1
);
expect
(
domain
[
0
]).
toBeCloseTo
(
-
2
15
,
-
1
);
expect
(
domain
[
1
]).
toBeCloseTo
(
0
,
-
1
);
});
it
(
'should locate labels above each data point'
,
function
()
{
var
texts
=
chart
.
internal
.
main
.
selectAll
(
'.c3-texts-data1 text'
),
expectedYs
=
[
368
,
387
,
368
,
12
],
expectedYs
=
[
368
,
12
,
368
,
12
],
expectedXs
=
[
74
,
221
,
368
,
515
];
texts
.
each
(
function
(
d
,
i
)
{
var
text
=
d3
.
select
(
this
);
...
...
@@ -803,13 +803,13 @@ describe('c3 chart data', function () {
it
(
'should have y domain with proper padding'
,
function
()
{
var
domain
=
chart
.
internal
.
y
.
domain
();
expect
(
domain
[
0
]).
toBeCloseTo
(
-
2
01
,
-
1
);
expect
(
domain
[
1
]).
toBeCloseTo
(
-
189
,
-
1
);
expect
(
domain
[
0
]).
toBeCloseTo
(
-
2
15
,
-
1
);
expect
(
domain
[
1
]).
toBeCloseTo
(
25
,
-
1
);
});
it
(
'should locate labels above each data point'
,
function
()
{
var
texts
=
chart
.
internal
.
main
.
selectAll
(
'.c3-texts-data1 text'
),
expectedYs
=
[
58
,
392
,
58
,
12
],
expectedYs
=
[
395
,
60
,
395
,
12
],
expectedXs
=
[
6
,
198
,
391
,
583
];
texts
.
each
(
function
(
d
,
i
)
{
var
text
=
d3
.
select
(
this
);
...
...
@@ -832,14 +832,14 @@ describe('c3 chart data', function () {
it
(
'should have y domain with proper padding'
,
function
()
{
var
domain
=
chart
.
internal
.
y
.
domain
();
expect
(
domain
[
0
]).
toBeCloseTo
(
-
2
32
,
-
1
);
expect
(
domain
[
0
]).
toBeCloseTo
(
-
2
20
,
-
1
);
expect
(
domain
[
1
]).
toBeCloseTo
(
0
,
-
1
);
});
it
(
'should locate labels above each data point'
,
function
()
{
var
texts
=
chart
.
internal
.
main
.
selectAll
(
'.c3-texts-data1 text'
),
expectedYs
=
[
57
,
163
,
269
,
375
],
expectedXs
=
[
103
,
78
,
103
,
526
];
expectedXs
=
[
103
,
594
,
103
,
526
];
texts
.
each
(
function
(
d
,
i
)
{
var
text
=
d3
.
select
(
this
);
expect
(
+
text
.
attr
(
'y'
)).
toBeCloseTo
(
expectedYs
[
i
],
-
2
);
...
...
@@ -854,14 +854,14 @@ describe('c3 chart data', function () {
it
(
'should have y domain with proper padding'
,
function
()
{
var
domain
=
chart
.
internal
.
y
.
domain
();
expect
(
domain
[
0
]).
toBeCloseTo
(
-
2
02
,
-
1
);
expect
(
domain
[
1
]).
toBeCloseTo
(
-
188
,
-
1
);
expect
(
domain
[
0
]).
toBeCloseTo
(
-
2
20
,
-
1
);
expect
(
domain
[
1
]).
toBeCloseTo
(
24
,
-
1
);
});
it
(
'should locate labels above each data point'
,
function
()
{
var
texts
=
chart
.
internal
.
main
.
selectAll
(
'.c3-texts-data1 text'
),
expectedYs
=
[
9
,
147
,
286
,
424
],
expectedXs
=
[
511
,
67
,
511
,
526
];
expectedXs
=
[
67
,
537
,
67
,
526
];
texts
.
each
(
function
(
d
,
i
)
{
var
text
=
d3
.
select
(
this
);
expect
(
+
text
.
attr
(
'y'
)).
toBeCloseTo
(
expectedYs
[
i
],
-
2
);
...
...
src/data.convert.js
View file @
74880d64
...
...
@@ -96,12 +96,8 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
var
$$
=
this
,
config
=
$$
.
config
,
ids
=
$$
.
d3
.
keys
(
data
[
0
]).
filter
(
$$
.
isNotX
,
$$
),
xs
=
$$
.
d3
.
keys
(
data
[
0
]).
filter
(
$$
.
isX
,
$$
),
zeroUnderYAxis
=
true
,
allZero
=
true
,
targets
;
$$
.
allDataIsNegative
=
true
;
// save x for update data by load when custom x and c3.x API
ids
.
forEach
(
function
(
id
)
{
var
xKey
=
$$
.
getXKey
(
id
);
...
...
@@ -144,8 +140,7 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
id
:
convertedId
,
id_org
:
id
,
values
:
data
.
map
(
function
(
d
,
i
)
{
var
xKey
=
$$
.
getXKey
(
id
),
rawX
=
d
[
xKey
],
x
=
$$
.
generateTargetX
(
rawX
,
id
,
i
),
var
xKey
=
$$
.
getXKey
(
id
),
rawX
=
d
[
xKey
],
x
=
$$
.
generateTargetX
(
rawX
,
id
,
i
),
value
=
d
[
id
]
!==
null
&&
!
isNaN
(
d
[
id
])
?
+
d
[
id
]
:
null
;
// use x as categories if custom x and categorized
if
(
$$
.
isCustomX
()
&&
$$
.
isCategorized
()
&&
index
===
0
&&
rawX
)
{
...
...
@@ -156,15 +151,6 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
if
(
isUndefined
(
d
[
id
])
||
$$
.
data
.
xs
[
id
].
length
<=
i
)
{
x
=
undefined
;
}
if
(
value
!==
null
&&
value
!==
0
)
{
allZero
=
false
;
}
if
(
value
>
0
)
{
zeroUnderYAxis
=
false
;
}
return
{
x
:
x
,
value
:
value
,
id
:
convertedId
};
}).
filter
(
function
(
v
)
{
return
isDefined
(
v
.
x
);
})
};
...
...
@@ -192,11 +178,9 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
});
});
if
(
allZero
)
{
zeroUnderYAxis
=
false
;
}
$$
.
zeroUnderYAxis
=
zeroUnderYAxis
;
// cache information about values
$$
.
hasNegativeValue
=
$$
.
hasNegativeValueInTargets
(
targets
);
$$
.
hasPositiveValue
=
$$
.
hasPositiveValueInTargets
(
targets
);
// set target types
if
(
config
.
data_type
)
{
...
...
src/text.js
View file @
74880d64
...
...
@@ -98,7 +98,7 @@ c3_chart_internal_fn.getYForText = function (points, d, textElement) {
yPos
=
(
points
[
0
][
0
]
+
points
[
2
][
0
]
+
box
.
height
*
0.6
)
/
2
;
}
else
{
yPos
=
points
[
2
][
1
];
if
(
d
.
value
<
0
||
(
d
.
value
===
0
&&
$$
.
zeroUnderYAxis
))
{
if
(
d
.
value
<
0
||
(
d
.
value
===
0
&&
!
$$
.
hasPositiveValue
))
{
yPos
+=
box
.
height
;
if
(
$$
.
isBarType
(
d
)
&&
$$
.
isSafari
())
{
yPos
-=
3
;
...
...
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