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
abbeb175
Commit
abbeb175
authored
Oct 27, 2016
by
Дмитрий Никулин
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make gaps equal when culling tick text
parent
9dc074da
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
33 deletions
+44
-33
c3.axis.js
src/c3.axis.js
+44
-33
No files found.
src/c3.axis.js
View file @
abbeb175
...
@@ -85,6 +85,38 @@ function c3_axis(d3, params, $$) {
...
@@ -85,6 +85,38 @@ function c3_axis(d3, params, $$) {
tickTextCharSize
=
size
;
tickTextCharSize
=
size
;
return
size
;
return
size
;
}
}
function
hasIntersection
(
rect1
,
rect2
)
{
var
r1x2
=
rect1
.
x
+
rect1
.
width
;
var
r2x2
=
rect2
.
x
+
rect2
.
width
;
var
r1y2
=
rect1
.
y
+
rect1
.
height
;
var
r2y2
=
rect2
.
y
+
rect2
.
height
;
return
(
rect1
.
x
<
r2x2
&&
r1x2
>
rect2
.
x
&&
rect1
.
y
<
r2y2
&&
r1y2
>
rect2
.
y
);
}
function
cullRects
(
rects
){
if
(
rects
.
length
<
2
)
return
;
var
cullGap
=
0
;
var
i
,
j
,
l
=
rects
.
length
;
for
(
i
=
1
,
j
=
0
;
i
<
l
;
i
++
){
if
(
hasIntersection
(
rects
[
i
],
rects
[
j
])){
cullGap
=
Math
.
max
(
cullGap
,
i
-
j
);
}
else
{
j
=
i
;
}
}
if
(
!
cullGap
)
return
;
var
cullStep
=
cullGap
+
1
;
for
(
i
=
0
;
i
<
l
;
i
++
){
if
(
i
%
cullStep
){
rects
[
i
]
=
null
;
}
}
}
function
axis
(
g
)
{
function
axis
(
g
)
{
g
.
each
(
function
()
{
g
.
each
(
function
()
{
var
g
=
d3
.
select
(
this
);
var
g
=
d3
.
select
(
this
);
...
@@ -172,16 +204,6 @@ function c3_axis(d3, params, $$) {
...
@@ -172,16 +204,6 @@ function c3_axis(d3, params, $$) {
return
dy
;
return
dy
;
}
}
function
hasIntersection
(
rect1
,
rect2
)
{
var
r1x2
=
rect1
.
x
+
rect1
.
width
;
var
r2x2
=
rect2
.
x
+
rect2
.
width
;
var
r1y2
=
rect1
.
y
+
rect1
.
height
;
var
r2y2
=
rect2
.
y
+
rect2
.
height
;
return
(
rect1
.
x
<
r2x2
&&
r1x2
>
rect2
.
x
&&
rect1
.
y
<
r2y2
&&
r1y2
>
rect2
.
y
);
}
function
tickSize
(
d
)
{
function
tickSize
(
d
)
{
return
innerTickSize
;
return
innerTickSize
;
}
}
...
@@ -203,13 +225,6 @@ function c3_axis(d3, params, $$) {
...
@@ -203,13 +225,6 @@ function c3_axis(d3, params, $$) {
tspan
.
exit
().
remove
();
tspan
.
exit
().
remove
();
var
axisId
=
$$
.
isXAxis
(
orient
)
?
'x'
:
'y'
;
var
axisId
=
$$
.
isXAxis
(
orient
)
?
'x'
:
'y'
;
var
textClass
=
'.c3-axis-'
+
axisId
+
' .tick'
var
textRects
=
text
.
data
().
map
(
function
(
data
)
{
var
rect
=
$$
.
getTextRect
(
textFormatted
(
data
),
textClass
);
// Smaal additional padding between texts
rect
.
width
+=
10
;
return
rect
;
});
var
fontSize
=
parseFloat
(
getStyleValue
(
$$
,
'.c3-axis-y .tick'
,
'font-size'
));
var
fontSize
=
parseFloat
(
getStyleValue
(
$$
,
'.c3-axis-y .tick'
,
'font-size'
));
...
@@ -342,26 +357,22 @@ function c3_axis(d3, params, $$) {
...
@@ -342,26 +357,22 @@ function c3_axis(d3, params, $$) {
break
;
break
;
}
}
var
last
=
textRects
.
length
-
1
;
var
textClass
=
'.c3-axis-'
+
axisId
+
' .tick'
;
var
textRects
=
text
.
data
().
map
(
function
(
data
)
{
rectPositionFn
(
textRects
[
0
],
text
.
data
()[
0
]);
var
rect
=
$$
.
getTextRect
(
textFormatted
(
data
),
textClass
);
rectPositionFn
(
textRects
[
last
],
text
.
data
().
pop
());
// Smaal additional padding between texts
rect
.
width
+=
10
;
var
addedTextRects
=
[
textRects
[
0
],
textRects
[
last
]];
return
rect
;
text
.
style
(
'display'
,
function
(
d
,
i
){
});
if
(
i
===
0
||
i
===
last
)
return
'block'
;
var
rect
=
textRects
[
i
];
text
.
each
(
function
(
d
,
i
){
rectPositionFn
(
rect
,
d
);
rectPositionFn
(
textRects
[
i
],
d
);
var
visible
=
!
addedTextRects
.
some
(
function
(
added
){
return
hasIntersection
(
rect
,
added
);
});
});
if
(
visible
){
cullRects
(
textRects
);
addedTextRects
.
push
(
rect
);
}
return
visible
?
'block'
:
'none'
;
text
.
style
(
'display'
,
function
(
d
,
i
){
return
textRects
[
i
]
===
null
?
'none'
:
'block'
;
});
});
});
});
}
}
...
...
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