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
606bf62c
Commit
606bf62c
authored
Jun 06, 2015
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'yordis-put-cero-under-the-line-when-all-data-is-negative'
parents
56092012
74880d64
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
18 deletions
+28
-18
c3.js
c3.js
+8
-3
c3.min.js
c3.min.js
+0
-0
data-spec.js
spec/data-spec.js
+12
-12
data.convert.js
src/data.convert.js
+7
-2
text.js
src/text.js
+1
-1
No files found.
c3.js
View file @
606bf62c
...
@@ -2110,7 +2110,8 @@
...
@@ -2110,7 +2110,8 @@
id
:
convertedId
,
id
:
convertedId
,
id_org
:
id
,
id_org
:
id
,
values
:
data
.
map
(
function
(
d
,
i
)
{
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
// use x as categories if custom x and categorized
if
(
$$
.
isCustomX
()
&&
$$
.
isCategorized
()
&&
index
===
0
&&
rawX
)
{
if
(
$$
.
isCustomX
()
&&
$$
.
isCategorized
()
&&
index
===
0
&&
rawX
)
{
if
(
i
===
0
)
{
config
.
axis_x_categories
=
[];
}
if
(
i
===
0
)
{
config
.
axis_x_categories
=
[];
}
...
@@ -2120,7 +2121,7 @@
...
@@ -2120,7 +2121,7 @@
if
(
isUndefined
(
d
[
id
])
||
$$
.
data
.
xs
[
id
].
length
<=
i
)
{
if
(
isUndefined
(
d
[
id
])
||
$$
.
data
.
xs
[
id
].
length
<=
i
)
{
x
=
undefined
;
x
=
undefined
;
}
}
return
{
x
:
x
,
value
:
d
[
id
]
!==
null
&&
!
isNaN
(
d
[
id
])
?
+
d
[
id
]
:
null
,
id
:
convertedId
};
return
{
x
:
x
,
value
:
value
,
id
:
convertedId
};
}).
filter
(
function
(
v
)
{
return
isDefined
(
v
.
x
);
})
}).
filter
(
function
(
v
)
{
return
isDefined
(
v
.
x
);
})
};
};
});
});
...
@@ -2147,6 +2148,10 @@
...
@@ -2147,6 +2148,10 @@
});
});
});
});
// cache information about values
$$
.
hasNegativeValue
=
$$
.
hasNegativeValueInTargets
(
targets
);
$$
.
hasPositiveValue
=
$$
.
hasPositiveValueInTargets
(
targets
);
// set target types
// set target types
if
(
config
.
data_type
)
{
if
(
config
.
data_type
)
{
$$
.
setTargetType
(
$$
.
mapToIds
(
targets
).
filter
(
function
(
id
)
{
return
!
(
id
in
config
.
data_types
);
}),
config
.
data_type
);
$$
.
setTargetType
(
$$
.
mapToIds
(
targets
).
filter
(
function
(
id
)
{
return
!
(
id
in
config
.
data_types
);
}),
config
.
data_type
);
...
@@ -3387,7 +3392,7 @@
...
@@ -3387,7 +3392,7 @@
yPos
=
(
points
[
0
][
0
]
+
points
[
2
][
0
]
+
box
.
height
*
0.6
)
/
2
;
yPos
=
(
points
[
0
][
0
]
+
points
[
2
][
0
]
+
box
.
height
*
0.6
)
/
2
;
}
else
{
}
else
{
yPos
=
points
[
2
][
1
];
yPos
=
points
[
2
][
1
];
if
(
d
.
value
<
0
)
{
if
(
d
.
value
<
0
||
(
d
.
value
===
0
&&
!
$$
.
hasPositiveValue
)
)
{
yPos
+=
box
.
height
;
yPos
+=
box
.
height
;
if
(
$$
.
isBarType
(
d
)
&&
$$
.
isSafari
())
{
if
(
$$
.
isBarType
(
d
)
&&
$$
.
isSafari
())
{
yPos
-=
3
;
yPos
-=
3
;
...
...
c3.min.js
View file @
606bf62c
This source diff could not be displayed because it is too large. You can
view the blob
instead.
spec/data-spec.js
View file @
606bf62c
...
@@ -755,7 +755,7 @@ describe('c3 chart data', function () {
...
@@ -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
()
{
describe
(
'on not rotated axis'
,
function
()
{
...
@@ -763,7 +763,7 @@ describe('c3 chart data', function () {
...
@@ -763,7 +763,7 @@ describe('c3 chart data', function () {
args
=
{
args
=
{
data
:
{
data
:
{
columns
:
[
columns
:
[
[
'data1'
,
-
190
,
-
20
0
,
-
190
,
null
],
[
'data1'
,
-
190
,
0
,
-
190
,
null
],
],
],
type
:
'bar'
,
type
:
'bar'
,
labels
:
{
labels
:
{
...
@@ -781,13 +781,13 @@ describe('c3 chart data', function () {
...
@@ -781,13 +781,13 @@ describe('c3 chart data', function () {
it
(
'should have y domain with proper padding'
,
function
()
{
it
(
'should have y domain with proper padding'
,
function
()
{
var
domain
=
chart
.
internal
.
y
.
domain
();
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
);
expect
(
domain
[
1
]).
toBeCloseTo
(
0
,
-
1
);
});
});
it
(
'should locate labels above each data point'
,
function
()
{
it
(
'should locate labels above each data point'
,
function
()
{
var
texts
=
chart
.
internal
.
main
.
selectAll
(
'.c3-texts-data1 text'
),
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
];
expectedXs
=
[
74
,
221
,
368
,
515
];
texts
.
each
(
function
(
d
,
i
)
{
texts
.
each
(
function
(
d
,
i
)
{
var
text
=
d3
.
select
(
this
);
var
text
=
d3
.
select
(
this
);
...
@@ -803,13 +803,13 @@ describe('c3 chart data', function () {
...
@@ -803,13 +803,13 @@ describe('c3 chart data', function () {
it
(
'should have y domain with proper padding'
,
function
()
{
it
(
'should have y domain with proper padding'
,
function
()
{
var
domain
=
chart
.
internal
.
y
.
domain
();
var
domain
=
chart
.
internal
.
y
.
domain
();
expect
(
domain
[
0
]).
toBeCloseTo
(
-
2
01
,
-
1
);
expect
(
domain
[
0
]).
toBeCloseTo
(
-
2
15
,
-
1
);
expect
(
domain
[
1
]).
toBeCloseTo
(
-
189
,
-
1
);
expect
(
domain
[
1
]).
toBeCloseTo
(
25
,
-
1
);
});
});
it
(
'should locate labels above each data point'
,
function
()
{
it
(
'should locate labels above each data point'
,
function
()
{
var
texts
=
chart
.
internal
.
main
.
selectAll
(
'.c3-texts-data1 text'
),
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
];
expectedXs
=
[
6
,
198
,
391
,
583
];
texts
.
each
(
function
(
d
,
i
)
{
texts
.
each
(
function
(
d
,
i
)
{
var
text
=
d3
.
select
(
this
);
var
text
=
d3
.
select
(
this
);
...
@@ -832,14 +832,14 @@ describe('c3 chart data', function () {
...
@@ -832,14 +832,14 @@ describe('c3 chart data', function () {
it
(
'should have y domain with proper padding'
,
function
()
{
it
(
'should have y domain with proper padding'
,
function
()
{
var
domain
=
chart
.
internal
.
y
.
domain
();
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
);
expect
(
domain
[
1
]).
toBeCloseTo
(
0
,
-
1
);
});
});
it
(
'should locate labels above each data point'
,
function
()
{
it
(
'should locate labels above each data point'
,
function
()
{
var
texts
=
chart
.
internal
.
main
.
selectAll
(
'.c3-texts-data1 text'
),
var
texts
=
chart
.
internal
.
main
.
selectAll
(
'.c3-texts-data1 text'
),
expectedYs
=
[
57
,
163
,
269
,
375
],
expectedYs
=
[
57
,
163
,
269
,
375
],
expectedXs
=
[
103
,
78
,
103
,
526
];
expectedXs
=
[
103
,
594
,
103
,
526
];
texts
.
each
(
function
(
d
,
i
)
{
texts
.
each
(
function
(
d
,
i
)
{
var
text
=
d3
.
select
(
this
);
var
text
=
d3
.
select
(
this
);
expect
(
+
text
.
attr
(
'y'
)).
toBeCloseTo
(
expectedYs
[
i
],
-
2
);
expect
(
+
text
.
attr
(
'y'
)).
toBeCloseTo
(
expectedYs
[
i
],
-
2
);
...
@@ -854,14 +854,14 @@ describe('c3 chart data', function () {
...
@@ -854,14 +854,14 @@ describe('c3 chart data', function () {
it
(
'should have y domain with proper padding'
,
function
()
{
it
(
'should have y domain with proper padding'
,
function
()
{
var
domain
=
chart
.
internal
.
y
.
domain
();
var
domain
=
chart
.
internal
.
y
.
domain
();
expect
(
domain
[
0
]).
toBeCloseTo
(
-
2
02
,
-
1
);
expect
(
domain
[
0
]).
toBeCloseTo
(
-
2
20
,
-
1
);
expect
(
domain
[
1
]).
toBeCloseTo
(
-
188
,
-
1
);
expect
(
domain
[
1
]).
toBeCloseTo
(
24
,
-
1
);
});
});
it
(
'should locate labels above each data point'
,
function
()
{
it
(
'should locate labels above each data point'
,
function
()
{
var
texts
=
chart
.
internal
.
main
.
selectAll
(
'.c3-texts-data1 text'
),
var
texts
=
chart
.
internal
.
main
.
selectAll
(
'.c3-texts-data1 text'
),
expectedYs
=
[
9
,
147
,
286
,
424
],
expectedYs
=
[
9
,
147
,
286
,
424
],
expectedXs
=
[
511
,
67
,
511
,
526
];
expectedXs
=
[
67
,
537
,
67
,
526
];
texts
.
each
(
function
(
d
,
i
)
{
texts
.
each
(
function
(
d
,
i
)
{
var
text
=
d3
.
select
(
this
);
var
text
=
d3
.
select
(
this
);
expect
(
+
text
.
attr
(
'y'
)).
toBeCloseTo
(
expectedYs
[
i
],
-
2
);
expect
(
+
text
.
attr
(
'y'
)).
toBeCloseTo
(
expectedYs
[
i
],
-
2
);
...
...
src/data.convert.js
View file @
606bf62c
...
@@ -140,7 +140,8 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
...
@@ -140,7 +140,8 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
id
:
convertedId
,
id
:
convertedId
,
id_org
:
id
,
id_org
:
id
,
values
:
data
.
map
(
function
(
d
,
i
)
{
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
// use x as categories if custom x and categorized
if
(
$$
.
isCustomX
()
&&
$$
.
isCategorized
()
&&
index
===
0
&&
rawX
)
{
if
(
$$
.
isCustomX
()
&&
$$
.
isCategorized
()
&&
index
===
0
&&
rawX
)
{
if
(
i
===
0
)
{
config
.
axis_x_categories
=
[];
}
if
(
i
===
0
)
{
config
.
axis_x_categories
=
[];
}
...
@@ -150,7 +151,7 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
...
@@ -150,7 +151,7 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
if
(
isUndefined
(
d
[
id
])
||
$$
.
data
.
xs
[
id
].
length
<=
i
)
{
if
(
isUndefined
(
d
[
id
])
||
$$
.
data
.
xs
[
id
].
length
<=
i
)
{
x
=
undefined
;
x
=
undefined
;
}
}
return
{
x
:
x
,
value
:
d
[
id
]
!==
null
&&
!
isNaN
(
d
[
id
])
?
+
d
[
id
]
:
null
,
id
:
convertedId
};
return
{
x
:
x
,
value
:
value
,
id
:
convertedId
};
}).
filter
(
function
(
v
)
{
return
isDefined
(
v
.
x
);
})
}).
filter
(
function
(
v
)
{
return
isDefined
(
v
.
x
);
})
};
};
});
});
...
@@ -177,6 +178,10 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
...
@@ -177,6 +178,10 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
});
});
});
});
// cache information about values
$$
.
hasNegativeValue
=
$$
.
hasNegativeValueInTargets
(
targets
);
$$
.
hasPositiveValue
=
$$
.
hasPositiveValueInTargets
(
targets
);
// set target types
// set target types
if
(
config
.
data_type
)
{
if
(
config
.
data_type
)
{
$$
.
setTargetType
(
$$
.
mapToIds
(
targets
).
filter
(
function
(
id
)
{
return
!
(
id
in
config
.
data_types
);
}),
config
.
data_type
);
$$
.
setTargetType
(
$$
.
mapToIds
(
targets
).
filter
(
function
(
id
)
{
return
!
(
id
in
config
.
data_types
);
}),
config
.
data_type
);
...
...
src/text.js
View file @
606bf62c
...
@@ -98,7 +98,7 @@ c3_chart_internal_fn.getYForText = function (points, d, textElement) {
...
@@ -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
;
yPos
=
(
points
[
0
][
0
]
+
points
[
2
][
0
]
+
box
.
height
*
0.6
)
/
2
;
}
else
{
}
else
{
yPos
=
points
[
2
][
1
];
yPos
=
points
[
2
][
1
];
if
(
d
.
value
<
0
)
{
if
(
d
.
value
<
0
||
(
d
.
value
===
0
&&
!
$$
.
hasPositiveValue
)
)
{
yPos
+=
box
.
height
;
yPos
+=
box
.
height
;
if
(
$$
.
isBarType
(
d
)
&&
$$
.
isSafari
())
{
if
(
$$
.
isBarType
(
d
)
&&
$$
.
isSafari
())
{
yPos
-=
3
;
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