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
fc69b670
Commit
fc69b670
authored
Nov 13, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tooltip position with left padding - #701
parent
45e879b3
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
94 additions
and
34 deletions
+94
-34
c3.js
c3.js
+5
-6
c3.min.js
c3.min.js
+0
-0
c3-helper.js
spec/c3-helper.js
+6
-5
shape.bar-spec.js
spec/shape.bar-spec.js
+9
-17
tooltip-spec.js
spec/tooltip-spec.js
+69
-0
axis.js
src/axis.js
+4
-1
size.js
src/size.js
+1
-5
No files found.
c3.js
View file @
fc69b670
...
@@ -2505,11 +2505,7 @@
...
@@ -2505,11 +2505,7 @@
c3_chart_internal_fn
.
getAxisWidthByAxisId
=
function
(
id
,
withoutRecompute
)
{
c3_chart_internal_fn
.
getAxisWidthByAxisId
=
function
(
id
,
withoutRecompute
)
{
var
$$
=
this
,
position
=
$$
.
getAxisLabelPositionById
(
id
);
var
$$
=
this
,
position
=
$$
.
getAxisLabelPositionById
(
id
);
if
(
withoutRecompute
)
{
return
$$
.
getMaxTickWidth
(
id
,
withoutRecompute
)
+
(
position
.
isInner
?
20
:
40
);
var
box
=
$$
.
d3
.
select
(
'.c3-axis-y'
).
node
().
getBoundingClientRect
();
return
Math
.
floor
(
box
.
left
+
box
.
width
);
}
return
$$
.
getMaxTickWidth
(
id
)
+
(
position
.
isInner
?
20
:
40
);
};
};
c3_chart_internal_fn
.
getHorizontalAxisHeight
=
function
(
axisId
)
{
c3_chart_internal_fn
.
getHorizontalAxisHeight
=
function
(
axisId
)
{
var
$$
=
this
,
config
=
$$
.
config
,
h
=
30
;
var
$$
=
this
,
config
=
$$
.
config
,
h
=
30
;
...
@@ -4179,9 +4175,12 @@
...
@@ -4179,9 +4175,12 @@
.
attr
(
'dx'
,
this
.
xForRotatedTickText
(
rotate
));
.
attr
(
'dx'
,
this
.
xForRotatedTickText
(
rotate
));
};
};
c3_chart_internal_fn
.
getMaxTickWidth
=
function
(
id
)
{
c3_chart_internal_fn
.
getMaxTickWidth
=
function
(
id
,
withoutRecompute
)
{
var
$$
=
this
,
config
=
$$
.
config
,
var
$$
=
this
,
config
=
$$
.
config
,
maxWidth
=
0
,
targetsToShow
,
scale
,
axis
;
maxWidth
=
0
,
targetsToShow
,
scale
,
axis
;
if
(
withoutRecompute
&&
$$
.
currentMaxTickWidths
[
id
])
{
return
$$
.
currentMaxTickWidths
[
id
];
}
if
(
$$
.
svg
)
{
if
(
$$
.
svg
)
{
targetsToShow
=
$$
.
filterTargetsToShow
(
$$
.
data
.
targets
);
targetsToShow
=
$$
.
filterTargetsToShow
(
$$
.
data
.
targets
);
if
(
id
===
'y'
)
{
if
(
id
===
'y'
)
{
...
...
c3.min.js
View file @
fc69b670
This source diff could not be displayed because it is too large. You can
view the blob
instead.
spec/c3-helper.js
View file @
fc69b670
...
@@ -10,17 +10,18 @@ function initDom() {
...
@@ -10,17 +10,18 @@ function initDom() {
}
}
typeof
initDom
!==
'undefined'
;
typeof
initDom
!==
'undefined'
;
function
set
Event
(
chart
,
x
,
y
)
{
function
set
MouseEvent
(
chart
,
name
,
x
,
y
,
element
)
{
'use strict'
;
'use strict'
;
var
paddingLeft
=
chart
.
internal
.
main
.
node
().
transform
.
baseVal
.
getItem
(
0
).
matrix
.
e
,
var
paddingLeft
=
chart
.
internal
.
main
.
node
().
transform
.
baseVal
.
getItem
(
0
).
matrix
.
e
,
evt
=
document
.
createEvent
(
"MouseEvents"
);
ev
en
t
=
document
.
createEvent
(
"MouseEvents"
);
ev
t
.
initMouseEvent
(
"click"
,
true
,
true
,
window
,
ev
ent
.
initMouseEvent
(
name
,
true
,
true
,
window
,
0
,
0
,
0
,
x
+
paddingLeft
,
y
+
5
,
0
,
0
,
0
,
x
+
paddingLeft
,
y
+
5
,
false
,
false
,
false
,
false
,
0
,
null
);
false
,
false
,
false
,
false
,
0
,
null
);
chart
.
internal
.
d3
.
event
=
evt
;
chart
.
internal
.
d3
.
event
=
event
;
if
(
element
)
{
element
.
dispatchEvent
(
event
);
}
}
}
typeof
setEvent
!==
'undefined'
;
typeof
set
Mouse
Event
!==
'undefined'
;
function
initChart
(
chart
,
args
,
done
)
{
function
initChart
(
chart
,
args
,
done
)
{
'use strict'
;
'use strict'
;
...
...
spec/shape.bar-spec.js
View file @
fc69b670
...
@@ -4,7 +4,7 @@ var describe = window.describe,
...
@@ -4,7 +4,7 @@ var describe = window.describe,
beforeEach
=
window
.
beforeEach
;
beforeEach
=
window
.
beforeEach
;
var
initDom
=
window
.
initDom
,
var
initDom
=
window
.
initDom
,
set
Event
=
window
.
set
Event
;
set
MouseEvent
=
window
.
setMouse
Event
;
describe
(
'c3 chart shape bar'
,
function
()
{
describe
(
'c3 chart shape bar'
,
function
()
{
'use strict'
;
'use strict'
;
...
@@ -26,16 +26,8 @@ describe('c3 chart shape bar', function () {
...
@@ -26,16 +26,8 @@ describe('c3 chart shape bar', function () {
};
};
beforeEach
(
function
(
done
)
{
beforeEach
(
function
(
done
)
{
if
(
typeof
chart
===
'undefined'
)
{
chart
=
window
.
initChart
(
chart
,
args
,
done
);
initDom
();
}
chart
=
window
.
c3
.
generate
(
args
);
d3
=
chart
.
internal
.
d3
;
d3
=
chart
.
internal
.
d3
;
chart
.
internal
.
d3
.
select
(
'.jasmine_html-reporter'
).
style
(
'display'
,
'none'
);
window
.
setTimeout
(
function
()
{
done
();
},
10
);
});
});
describe
(
'internal.isWithinBar'
,
function
()
{
describe
(
'internal.isWithinBar'
,
function
()
{
...
@@ -44,25 +36,25 @@ describe('c3 chart shape bar', function () {
...
@@ -44,25 +36,25 @@ describe('c3 chart shape bar', function () {
it
(
'should not be within bar'
,
function
()
{
it
(
'should not be within bar'
,
function
()
{
var
bar
=
d3
.
select
(
'.c3-target-data1 .c3-bar-0'
).
node
();
var
bar
=
d3
.
select
(
'.c3-target-data1 .c3-bar-0'
).
node
();
set
Event
(
chart
,
0
,
0
);
set
MouseEvent
(
chart
,
'click'
,
0
,
0
);
expect
(
chart
.
internal
.
isWithinBar
(
bar
)).
toBeFalsy
();
expect
(
chart
.
internal
.
isWithinBar
(
bar
)).
toBeFalsy
();
});
});
it
(
'should be within bar'
,
function
()
{
it
(
'should be within bar'
,
function
()
{
var
bar
=
d3
.
select
(
'.c3-target-data1 .c3-bar-0'
).
node
();
var
bar
=
d3
.
select
(
'.c3-target-data1 .c3-bar-0'
).
node
();
set
Event
(
chart
,
31
,
280
);
set
MouseEvent
(
chart
,
'click'
,
31
,
280
);
expect
(
chart
.
internal
.
isWithinBar
(
bar
)).
toBeTruthy
();
expect
(
chart
.
internal
.
isWithinBar
(
bar
)).
toBeTruthy
();
});
});
it
(
'should not be within bar of negative value'
,
function
()
{
it
(
'should not be within bar of negative value'
,
function
()
{
var
bar
=
d3
.
select
(
'.c3-target-data3 .c3-bar-0'
).
node
();
var
bar
=
d3
.
select
(
'.c3-target-data3 .c3-bar-0'
).
node
();
set
Event
(
chart
,
68
,
280
);
set
MouseEvent
(
chart
,
'click'
,
68
,
280
);
expect
(
chart
.
internal
.
isWithinBar
(
bar
)).
toBeFalsy
();
expect
(
chart
.
internal
.
isWithinBar
(
bar
)).
toBeFalsy
();
});
});
it
(
'should be within bar of negative value'
,
function
()
{
it
(
'should be within bar of negative value'
,
function
()
{
var
bar
=
d3
.
select
(
'.c3-target-data3 .c3-bar-0'
).
node
();
var
bar
=
d3
.
select
(
'.c3-target-data3 .c3-bar-0'
).
node
();
set
Event
(
chart
,
68
,
350
);
set
MouseEvent
(
chart
,
'click'
,
68
,
350
);
expect
(
chart
.
internal
.
isWithinBar
(
bar
)).
toBeTruthy
();
expect
(
chart
.
internal
.
isWithinBar
(
bar
)).
toBeTruthy
();
});
});
...
@@ -77,19 +69,19 @@ describe('c3 chart shape bar', function () {
...
@@ -77,19 +69,19 @@ describe('c3 chart shape bar', function () {
it
(
'should not be within bar'
,
function
()
{
it
(
'should not be within bar'
,
function
()
{
var
bar
=
d3
.
select
(
'.c3-target-data1 .c3-bar-0'
).
node
();
var
bar
=
d3
.
select
(
'.c3-target-data1 .c3-bar-0'
).
node
();
set
Event
(
chart
,
0
,
0
);
set
MouseEvent
(
chart
,
'click'
,
0
,
0
);
expect
(
chart
.
internal
.
isWithinBar
(
bar
)).
toBeFalsy
();
expect
(
chart
.
internal
.
isWithinBar
(
bar
)).
toBeFalsy
();
});
});
it
(
'should be within bar'
,
function
()
{
it
(
'should be within bar'
,
function
()
{
var
bar
=
d3
.
select
(
'.c3-target-data1 .c3-bar-0'
).
node
();
var
bar
=
d3
.
select
(
'.c3-target-data1 .c3-bar-0'
).
node
();
set
Event
(
chart
,
190
,
20
);
set
MouseEvent
(
chart
,
'click'
,
190
,
20
);
expect
(
chart
.
internal
.
isWithinBar
(
bar
)).
toBeTruthy
();
expect
(
chart
.
internal
.
isWithinBar
(
bar
)).
toBeTruthy
();
});
});
it
(
'should be within bar of negative value'
,
function
()
{
it
(
'should be within bar of negative value'
,
function
()
{
var
bar
=
d3
.
select
(
'.c3-target-data3 .c3-bar-0'
).
node
();
var
bar
=
d3
.
select
(
'.c3-target-data3 .c3-bar-0'
).
node
();
set
Event
(
chart
,
68
,
50
);
set
MouseEvent
(
chart
,
'click'
,
68
,
50
);
expect
(
chart
.
internal
.
isWithinBar
(
bar
)).
toBeTruthy
();
expect
(
chart
.
internal
.
isWithinBar
(
bar
)).
toBeTruthy
();
});
});
...
...
spec/tooltip-spec.js
0 → 100644
View file @
fc69b670
var
describe
=
window
.
describe
,
expect
=
window
.
expect
,
it
=
window
.
it
,
beforeEach
=
window
.
beforeEach
;
describe
(
'c3 chart tooltip'
,
function
()
{
'use strict'
;
var
chart
,
d3
;
var
args
=
{
data
:
{
columns
:
[
[
'data1'
,
30
,
200
,
100
,
400
,
150
,
250
],
[
'data2'
,
50
,
20
,
10
,
40
,
15
,
25
],
[
'data3'
,
150
,
120
,
110
,
140
,
115
,
125
]
]
}
};
beforeEach
(
function
(
done
)
{
chart
=
window
.
initChart
(
chart
,
args
,
done
);
d3
=
chart
.
internal
.
d3
;
});
describe
(
'tooltip position'
,
function
()
{
describe
(
'without left margin'
,
function
()
{
it
(
'should show tooltip on proper position'
,
function
()
{
var
eventRect
=
d3
.
select
(
'.c3-event-rect-2'
).
node
();
window
.
setMouseEvent
(
chart
,
'mousemove'
,
100
,
100
,
eventRect
);
var
tooltipContainer
=
d3
.
select
(
'.c3-tooltip-container'
),
top
=
Math
.
floor
(
+
tooltipContainer
.
style
(
'top'
).
replace
(
/px/
,
''
)),
left
=
Math
.
floor
(
+
tooltipContainer
.
style
(
'left'
).
replace
(
/px/
,
''
)),
topExpected
=
115
,
leftExpected
=
304
;
expect
(
top
).
toBe
(
topExpected
);
expect
(
left
).
toBe
(
leftExpected
);
});
});
describe
(
'with left margin'
,
function
()
{
it
(
'should set left margin'
,
function
()
{
d3
.
select
(
'#chart'
).
style
(
'margin-left'
,
'300px'
);
expect
(
true
).
toBeTruthy
();
});
it
(
'should show tooltip on proper position'
,
function
()
{
var
eventRect
=
d3
.
select
(
'.c3-event-rect-2'
).
node
();
window
.
setMouseEvent
(
chart
,
'mousemove'
,
100
,
100
,
eventRect
);
var
tooltipContainer
=
d3
.
select
(
'.c3-tooltip-container'
),
top
=
Math
.
floor
(
+
tooltipContainer
.
style
(
'top'
).
replace
(
/px/
,
''
)),
left
=
Math
.
floor
(
+
tooltipContainer
.
style
(
'left'
).
replace
(
/px/
,
''
)),
topExpected
=
115
,
leftExpected
=
304
;
expect
(
top
).
toBe
(
topExpected
);
expect
(
left
).
toBe
(
leftExpected
);
});
});
});
});
src/axis.js
View file @
fc69b670
...
@@ -258,9 +258,12 @@ c3_chart_internal_fn.rotateTickText = function (axis, transition, rotate) {
...
@@ -258,9 +258,12 @@ c3_chart_internal_fn.rotateTickText = function (axis, transition, rotate) {
.
attr
(
'dx'
,
this
.
xForRotatedTickText
(
rotate
));
.
attr
(
'dx'
,
this
.
xForRotatedTickText
(
rotate
));
};
};
c3_chart_internal_fn
.
getMaxTickWidth
=
function
(
id
)
{
c3_chart_internal_fn
.
getMaxTickWidth
=
function
(
id
,
withoutRecompute
)
{
var
$$
=
this
,
config
=
$$
.
config
,
var
$$
=
this
,
config
=
$$
.
config
,
maxWidth
=
0
,
targetsToShow
,
scale
,
axis
;
maxWidth
=
0
,
targetsToShow
,
scale
,
axis
;
if
(
withoutRecompute
&&
$$
.
currentMaxTickWidths
[
id
])
{
return
$$
.
currentMaxTickWidths
[
id
];
}
if
(
$$
.
svg
)
{
if
(
$$
.
svg
)
{
targetsToShow
=
$$
.
filterTargetsToShow
(
$$
.
data
.
targets
);
targetsToShow
=
$$
.
filterTargetsToShow
(
$$
.
data
.
targets
);
if
(
id
===
'y'
)
{
if
(
id
===
'y'
)
{
...
...
src/size.js
View file @
fc69b670
...
@@ -71,11 +71,7 @@ c3_chart_internal_fn.getSvgLeft = function (withoutRecompute) {
...
@@ -71,11 +71,7 @@ c3_chart_internal_fn.getSvgLeft = function (withoutRecompute) {
c3_chart_internal_fn
.
getAxisWidthByAxisId
=
function
(
id
,
withoutRecompute
)
{
c3_chart_internal_fn
.
getAxisWidthByAxisId
=
function
(
id
,
withoutRecompute
)
{
var
$$
=
this
,
position
=
$$
.
getAxisLabelPositionById
(
id
);
var
$$
=
this
,
position
=
$$
.
getAxisLabelPositionById
(
id
);
if
(
withoutRecompute
)
{
return
$$
.
getMaxTickWidth
(
id
,
withoutRecompute
)
+
(
position
.
isInner
?
20
:
40
);
var
box
=
$$
.
d3
.
select
(
'.c3-axis-y'
).
node
().
getBoundingClientRect
();
return
Math
.
floor
(
box
.
left
+
box
.
width
);
}
return
$$
.
getMaxTickWidth
(
id
)
+
(
position
.
isInner
?
20
:
40
);
};
};
c3_chart_internal_fn
.
getHorizontalAxisHeight
=
function
(
axisId
)
{
c3_chart_internal_fn
.
getHorizontalAxisHeight
=
function
(
axisId
)
{
var
$$
=
this
,
config
=
$$
.
config
,
h
=
30
;
var
$$
=
this
,
config
=
$$
.
config
,
h
=
30
;
...
...
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