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
9bf1f229
Commit
9bf1f229
authored
Aug 21, 2015
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1337 from teichmaj/issue_1028_tooltip_order
fix data order of tooltip
parents
b1a4e741
25e8ad2f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
2 deletions
+42
-2
Gruntfile.coffee
Gruntfile.coffee
+1
-1
tooltip-spec.js
spec/tooltip-spec.js
+21
-0
tooltip.js
src/tooltip.js
+20
-1
No files found.
Gruntfile.coffee
View file @
9bf1f229
...
...
@@ -92,7 +92,7 @@ module.exports = (grunt) ->
specs
:
'spec/*-spec.js'
helpers
:
'spec/*-helper.js'
styles
:
'c3.css'
vendor
:
'https://raw
.githubuserconten
t.com/mbostock/d3/v3.5.0/d3.min.js'
vendor
:
'https://raw
gi
t.com/mbostock/d3/v3.5.0/d3.min.js'
uglify
:
c3
:
...
...
spec/tooltip-spec.js
View file @
9bf1f229
...
...
@@ -98,4 +98,25 @@ describe('c3 chart tooltip', function () {
expect
(
left
).
toBe
(
leftExpected
);
});
});
describe
(
'tooltip getTooltipContent'
,
function
()
{
beforeAll
(
function
()
{
tooltipConfiguration
=
{
data_order
:
'desc'
};
});
it
(
'should sort values desc'
,
function
()
{
var
eventRect
=
d3
.
select
(
'.c3-event-rect-2'
).
node
();
window
.
setMouseEvent
(
chart
,
'mousemove'
,
100
,
100
,
eventRect
);
var
tooltipTable
=
d3
.
select
(
'.c3-tooltip'
)[
0
];
var
expected
=
[
""
,
"c3-tooltip-name--data3"
,
"c3-tooltip-name--data1"
,
"c3-tooltip-name--data2"
];
var
i
;
for
(
i
=
0
;
i
<
tooltipTable
[
0
].
rows
.
length
;
i
++
)
{
expect
(
tooltipTable
[
0
].
rows
[
i
].
className
).
toBe
(
expected
[
i
]);
}
});
});
});
src/tooltip.js
View file @
9bf1f229
...
...
@@ -29,7 +29,26 @@ c3_chart_internal_fn.getTooltipContent = function (d, defaultTitleFormat, defaul
titleFormat
=
config
.
tooltip_format_title
||
defaultTitleFormat
,
nameFormat
=
config
.
tooltip_format_name
||
function
(
name
)
{
return
name
;
},
valueFormat
=
config
.
tooltip_format_value
||
defaultValueFormat
,
text
,
i
,
title
,
value
,
name
,
bgcolor
;
text
,
i
,
title
,
value
,
name
,
bgcolor
,
orderAsc
=
$$
.
isOrderAsc
();
if
(
config
.
data_groups
.
length
===
0
)
{
d
.
sort
(
function
(
a
,
b
){
return
orderAsc
?
a
.
value
-
b
.
value
:
b
.
value
-
a
.
value
;
});
}
else
{
var
ids
=
$$
.
orderTargets
(
$$
.
data
.
targets
).
map
(
function
(
i
)
{
return
i
.
id
;
});
d
.
sort
(
function
(
a
,
b
)
{
if
(
a
.
value
>
0
&&
b
.
value
>
0
)
{
return
orderAsc
?
ids
.
indexOf
(
a
.
id
)
-
ids
.
indexOf
(
b
.
id
)
:
ids
.
indexOf
(
b
.
id
)
-
ids
.
indexOf
(
a
.
id
);
}
else
{
return
orderAsc
?
a
.
value
-
b
.
value
:
b
.
value
-
a
.
value
;
}
});
}
for
(
i
=
0
;
i
<
d
.
length
;
i
++
)
{
if
(
!
(
d
[
i
]
&&
(
d
[
i
].
value
||
d
[
i
].
value
===
0
)))
{
continue
;
}
...
...
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