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
6292548a
Commit
6292548a
authored
Jan 12, 2015
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix padding.left when rotated category axis - #872
parent
b03d5309
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
76 additions
and
45 deletions
+76
-45
c3.js
c3.js
+29
-13
c3.min.js
c3.min.js
+0
-0
axis-spec.js
spec/axis-spec.js
+4
-5
grid-spec.js
spec/grid-spec.js
+1
-1
interaction-spec.js
spec/interaction-spec.js
+8
-8
legend-spec.js
spec/legend-spec.js
+1
-1
tooltip-spec.js
spec/tooltip-spec.js
+4
-4
axis.js
src/axis.js
+28
-6
core.js
src/core.js
+1
-7
No files found.
c3.js
View file @
6292548a
...
...
@@ -478,13 +478,7 @@
if
(
targetsToShow
.
length
)
{
$$
.
updateXDomain
(
targetsToShow
,
withUpdateXDomain
,
withUpdateOrgXDomain
,
withTrimXDomain
);
if
(
!
config
.
axis_x_tick_values
)
{
if
(
config
.
axis_x_tick_fit
||
config
.
axis_x_tick_count
)
{
tickValues
=
$$
.
generateTickValues
(
$$
.
mapTargetsToUniqueXs
(
targetsToShow
),
config
.
axis_x_tick_count
,
$$
.
isTimeSeries
());
}
else
{
tickValues
=
undefined
;
}
$$
.
xAxis
.
tickValues
(
tickValues
);
$$
.
subXAxis
.
tickValues
(
tickValues
);
tickValues
=
$$
.
updateXAxisTickValues
(
targetsToShow
);
}
}
else
{
$$
.
xAxis
.
tickValues
([]);
...
...
@@ -4068,13 +4062,14 @@
.
attr
(
"transform"
,
config
.
axis_rotated
?
""
:
"rotate(-90)"
)
.
style
(
"text-anchor"
,
$$
.
textAnchorForY2AxisLabel
.
bind
(
$$
));
};
c3_chart_internal_fn
.
getXAxis
=
function
(
scale
,
orient
,
tickFormat
,
tickValues
,
withOuterTick
)
{
c3_chart_internal_fn
.
getXAxis
=
function
(
scale
,
orient
,
tickFormat
,
tickValues
,
withOuterTick
,
withoutTransition
)
{
var
$$
=
this
,
config
=
$$
.
config
,
axisParams
=
{
isCategory
:
$$
.
isCategorized
(),
withOuterTick
:
withOuterTick
,
tickMultiline
:
config
.
axis_x_tick_multiline
,
tickWidth
:
config
.
axis_x_tick_width
tickWidth
:
config
.
axis_x_tick_width
,
withoutTransition
:
withoutTransition
,
},
axis
=
c3_axis
(
$$
.
d3
,
axisParams
).
scale
(
scale
).
orient
(
orient
);
...
...
@@ -4101,6 +4096,19 @@
return
axis
;
};
c3_chart_internal_fn
.
updateXAxisTickValues
=
function
(
targets
,
axis
)
{
var
$$
=
this
,
config
=
$$
.
config
,
tickValues
;
if
(
config
.
axis_x_tick_fit
||
config
.
axis_x_tick_count
)
{
tickValues
=
$$
.
generateTickValues
(
$$
.
mapTargetsToUniqueXs
(
targets
),
config
.
axis_x_tick_count
,
$$
.
isTimeSeries
());
}
if
(
axis
)
{
axis
.
tickValues
(
tickValues
);
}
else
{
$$
.
xAxis
.
tickValues
(
tickValues
);
$$
.
subXAxis
.
tickValues
(
tickValues
);
}
return
tickValues
;
};
c3_chart_internal_fn
.
getYAxis
=
function
(
scale
,
orient
,
tickFormat
,
tickValues
,
withOuterTick
)
{
var
axisParams
=
{
withOuterTick
:
withOuterTick
},
axis
=
c3_axis
(
this
.
d3
,
axisParams
).
scale
(
scale
).
orient
(
orient
).
tickFormat
(
tickFormat
);
...
...
@@ -4304,7 +4312,7 @@
c3_chart_internal_fn
.
getMaxTickWidth
=
function
(
id
,
withoutRecompute
)
{
var
$$
=
this
,
config
=
$$
.
config
,
maxWidth
=
0
,
targetsToShow
,
scale
,
axis
;
maxWidth
=
0
,
targetsToShow
,
scale
,
axis
,
body
,
svg
;
if
(
withoutRecompute
&&
$$
.
currentMaxTickWidths
[
id
])
{
return
$$
.
currentMaxTickWidths
[
id
];
}
...
...
@@ -4319,13 +4327,21 @@
}
else
{
scale
=
$$
.
x
.
copy
().
domain
(
$$
.
getXDomain
(
targetsToShow
));
axis
=
$$
.
getXAxis
(
scale
,
$$
.
xOrient
,
$$
.
xAxisTickFormat
,
$$
.
xAxisTickValues
);
$$
.
updateXAxisTickValues
(
targetsToShow
,
axis
);
}
$$
.
d3
.
select
(
'body'
).
append
(
"g"
).
style
(
'visibility'
,
'hidden'
).
call
(
axis
).
each
(
function
()
{
body
=
this
.
d3
.
select
(
'body'
).
classed
(
'c3'
,
true
);
svg
=
body
.
append
(
'svg'
).
style
(
'visibility'
,
'hidden'
);
svg
.
append
(
'g'
).
call
(
axis
).
each
(
function
()
{
$$
.
d3
.
select
(
this
).
selectAll
(
'text tspan'
).
each
(
function
()
{
var
box
=
this
.
getBoundingClientRect
();
if
(
box
.
left
>
0
&&
maxWidth
<
box
.
width
)
{
maxWidth
=
box
.
width
;
}
if
(
box
.
left
>
=
0
&&
maxWidth
<
box
.
width
)
{
maxWidth
=
box
.
width
;
}
});
}).
remove
();
});
// TODO: time lag to get maxWidth
window
.
setTimeout
(
function
()
{
svg
.
remove
();
},
100
);
body
.
classed
(
'c3'
,
false
);
}
$$
.
currentMaxTickWidths
[
id
]
=
maxWidth
<=
0
?
$$
.
currentMaxTickWidths
[
id
]
:
maxWidth
;
return
$$
.
currentMaxTickWidths
[
id
];
...
...
c3.min.js
View file @
6292548a
This source diff could not be displayed because it is too large. You can
view the blob
instead.
spec/axis-spec.js
View file @
6292548a
...
...
@@ -380,11 +380,10 @@ describe('c3 chart axis', function () {
expectedTickTexts
=
[
'this is a very'
,
'long tick text'
,
'on category'
,
'axis'
,
'on category axis'
],
expectedX
=
'0'
;
expect
(
tspans
.
size
()).
toBe
(
4
);
expect
(
tspans
.
size
()).
toBe
(
3
);
tspans
.
each
(
function
(
d
,
i
)
{
var
tspan
=
d3
.
select
(
this
);
expect
(
tspan
.
text
()).
toBe
(
expectedTickTexts
[
i
]);
...
...
@@ -697,7 +696,7 @@ describe('c3 chart axis', function () {
it
(
'should not have inner y axis'
,
function
()
{
var
paddingLeft
=
chart
.
internal
.
getCurrentPaddingLeft
(),
tickTexts
=
chart
.
internal
.
main
.
selectAll
(
'.c3-axis-y g.tick text'
);
expect
(
paddingLeft
).
toBe
(
50
);
expect
(
paddingLeft
).
toBe
GreaterThan
(
19
);
tickTexts
.
each
(
function
()
{
expect
(
+
d3
.
select
(
this
).
attr
(
'x'
)).
toBeLessThan
(
0
);
});
...
...
@@ -742,7 +741,7 @@ describe('c3 chart axis', function () {
it
(
'should not have inner y axis'
,
function
()
{
var
paddingRight
=
chart
.
internal
.
getCurrentPaddingRight
(),
tickTexts
=
chart
.
internal
.
main
.
selectAll
(
'.c3-axis-2y g.tick text'
);
expect
(
paddingRight
).
toBeGreaterThan
(
3
9
);
expect
(
paddingRight
).
toBeGreaterThan
(
1
9
);
tickTexts
.
each
(
function
()
{
expect
(
+
d3
.
select
(
this
).
attr
(
'x'
)).
toBeGreaterThan
(
0
);
});
...
...
spec/grid-spec.js
View file @
6292548a
...
...
@@ -119,7 +119,7 @@ describe('c3 chart grid', function () {
var
line
=
d3
.
select
(
this
),
l
=
line
.
select
(
'line'
),
t
=
line
.
select
(
'text'
);
expect
(
+
l
.
attr
(
'x1'
)).
toBeCloseTo
(
expectedX1
[
i
],
-
1
);
expect
(
+
l
.
attr
(
'x1'
)).
toBeCloseTo
(
expectedX1
[
i
],
-
2
);
expect
(
t
.
text
()).
toBe
(
expectedText
[
i
]);
});
});
...
...
spec/interaction-spec.js
View file @
6292548a
...
...
@@ -46,8 +46,8 @@ describe('c3 chart interaction', function () {
widths
=
[
60
,
67.5
,
202
,
194
];
d3
.
selectAll
(
'.c3-event-rect'
).
each
(
function
(
d
,
i
)
{
var
box
=
d3
.
select
(
this
).
node
().
getBoundingClientRect
();
expect
(
box
.
left
).
toBe
(
lefts
[
i
]
);
expect
(
box
.
width
).
toBe
(
widths
[
i
]
);
expect
(
box
.
left
).
toBe
CloseTo
(
lefts
[
i
],
-
2
);
expect
(
box
.
width
).
toBe
CloseTo
(
widths
[
i
],
-
2
);
});
});
...
...
@@ -70,8 +70,8 @@ describe('c3 chart interaction', function () {
expect
(
eventRects
.
size
()).
toBe
(
1
);
eventRects
.
each
(
function
()
{
var
box
=
d3
.
select
(
this
).
node
().
getBoundingClientRect
();
expect
(
box
.
left
).
toBe
(
40.5
);
expect
(
box
.
width
).
toBe
(
598
);
expect
(
box
.
left
).
toBe
CloseTo
(
40.5
,
-
2
);
expect
(
box
.
width
).
toBe
CloseTo
(
598
,
-
2
);
});
});
});
...
...
@@ -96,8 +96,8 @@ describe('c3 chart interaction', function () {
widths
=
[
149.5
,
160
,
147
,
136
];
d3
.
selectAll
(
'.c3-event-rect'
).
each
(
function
(
d
,
i
)
{
var
box
=
d3
.
select
(
this
).
node
().
getBoundingClientRect
();
expect
(
box
.
left
).
toBe
(
lefts
[
i
]
);
expect
(
box
.
width
).
toBe
(
widths
[
i
]
);
expect
(
box
.
left
).
toBe
CloseTo
(
lefts
[
i
],
-
2
);
expect
(
box
.
width
).
toBe
CloseTo
(
widths
[
i
],
-
2
);
});
});
...
...
@@ -120,8 +120,8 @@ describe('c3 chart interaction', function () {
expect
(
eventRects
.
size
()).
toBe
(
1
);
eventRects
.
each
(
function
()
{
var
box
=
d3
.
select
(
this
).
node
().
getBoundingClientRect
();
expect
(
box
.
left
).
toBe
(
40.5
);
expect
(
box
.
width
).
toBe
(
598
);
expect
(
box
.
left
).
toBe
CloseTo
(
40.5
,
-
2
);
expect
(
box
.
width
).
toBe
CloseTo
(
598
,
-
2
);
});
});
...
...
spec/legend-spec.js
View file @
6292548a
...
...
@@ -56,7 +56,7 @@ describe('c3 chart legend', function () {
it
(
'should be positioned properly'
,
function
()
{
var
box
=
d3
.
select
(
'.c3-legend-background'
).
node
().
getBoundingClientRect
();
expect
(
box
.
top
).
toBe
(
5.5
);
expect
(
box
.
left
).
toBe
(
60.5
);
expect
(
box
.
left
).
toBe
GreaterThan
(
30
);
});
it
(
'should have automatically calculated height'
,
function
()
{
...
...
spec/tooltip-spec.js
View file @
6292548a
...
...
@@ -44,9 +44,9 @@ describe('c3 chart tooltip', function () {
top
=
Math
.
floor
(
+
tooltipContainer
.
style
(
'top'
).
replace
(
/px/
,
''
)),
left
=
Math
.
floor
(
+
tooltipContainer
.
style
(
'left'
).
replace
(
/px/
,
''
)),
topExpected
=
115
,
leftExpected
=
307
;
leftExpected
=
280
;
expect
(
top
).
toBe
(
topExpected
);
expect
(
left
).
toBe
(
leftExpected
);
expect
(
left
).
toBe
GreaterThan
(
leftExpected
);
});
});
...
...
@@ -66,9 +66,9 @@ describe('c3 chart tooltip', function () {
top
=
Math
.
floor
(
+
tooltipContainer
.
style
(
'top'
).
replace
(
/px/
,
''
)),
left
=
Math
.
floor
(
+
tooltipContainer
.
style
(
'left'
).
replace
(
/px/
,
''
)),
topExpected
=
115
,
leftExpected
=
307
;
leftExpected
=
280
;
expect
(
top
).
toBe
(
topExpected
);
expect
(
left
).
toBe
(
leftExpected
);
expect
(
left
).
toBe
GreaterThan
(
leftExpected
);
});
});
...
...
src/axis.js
View file @
6292548a
...
...
@@ -30,13 +30,14 @@ c3_chart_internal_fn.initAxis = function () {
.
attr
(
"transform"
,
config
.
axis_rotated
?
""
:
"rotate(-90)"
)
.
style
(
"text-anchor"
,
$$
.
textAnchorForY2AxisLabel
.
bind
(
$$
));
};
c3_chart_internal_fn
.
getXAxis
=
function
(
scale
,
orient
,
tickFormat
,
tickValues
,
withOuterTick
)
{
c3_chart_internal_fn
.
getXAxis
=
function
(
scale
,
orient
,
tickFormat
,
tickValues
,
withOuterTick
,
withoutTransition
)
{
var
$$
=
this
,
config
=
$$
.
config
,
axisParams
=
{
isCategory
:
$$
.
isCategorized
(),
withOuterTick
:
withOuterTick
,
tickMultiline
:
config
.
axis_x_tick_multiline
,
tickWidth
:
config
.
axis_x_tick_width
tickWidth
:
config
.
axis_x_tick_width
,
withoutTransition
:
withoutTransition
,
},
axis
=
c3_axis
(
$$
.
d3
,
axisParams
).
scale
(
scale
).
orient
(
orient
);
...
...
@@ -63,6 +64,19 @@ c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues,
return
axis
;
};
c3_chart_internal_fn
.
updateXAxisTickValues
=
function
(
targets
,
axis
)
{
var
$$
=
this
,
config
=
$$
.
config
,
tickValues
;
if
(
config
.
axis_x_tick_fit
||
config
.
axis_x_tick_count
)
{
tickValues
=
$$
.
generateTickValues
(
$$
.
mapTargetsToUniqueXs
(
targets
),
config
.
axis_x_tick_count
,
$$
.
isTimeSeries
());
}
if
(
axis
)
{
axis
.
tickValues
(
tickValues
);
}
else
{
$$
.
xAxis
.
tickValues
(
tickValues
);
$$
.
subXAxis
.
tickValues
(
tickValues
);
}
return
tickValues
;
};
c3_chart_internal_fn
.
getYAxis
=
function
(
scale
,
orient
,
tickFormat
,
tickValues
,
withOuterTick
)
{
var
axisParams
=
{
withOuterTick
:
withOuterTick
},
axis
=
c3_axis
(
this
.
d3
,
axisParams
).
scale
(
scale
).
orient
(
orient
).
tickFormat
(
tickFormat
);
...
...
@@ -266,7 +280,7 @@ c3_chart_internal_fn.rotateTickText = function (axis, transition, rotate) {
c3_chart_internal_fn
.
getMaxTickWidth
=
function
(
id
,
withoutRecompute
)
{
var
$$
=
this
,
config
=
$$
.
config
,
maxWidth
=
0
,
targetsToShow
,
scale
,
axis
;
maxWidth
=
0
,
targetsToShow
,
scale
,
axis
,
body
,
svg
;
if
(
withoutRecompute
&&
$$
.
currentMaxTickWidths
[
id
])
{
return
$$
.
currentMaxTickWidths
[
id
];
}
...
...
@@ -281,13 +295,21 @@ c3_chart_internal_fn.getMaxTickWidth = function (id, withoutRecompute) {
}
else
{
scale
=
$$
.
x
.
copy
().
domain
(
$$
.
getXDomain
(
targetsToShow
));
axis
=
$$
.
getXAxis
(
scale
,
$$
.
xOrient
,
$$
.
xAxisTickFormat
,
$$
.
xAxisTickValues
);
$$
.
updateXAxisTickValues
(
targetsToShow
,
axis
);
}
$$
.
d3
.
select
(
'body'
).
append
(
"g"
).
style
(
'visibility'
,
'hidden'
).
call
(
axis
).
each
(
function
()
{
body
=
this
.
d3
.
select
(
'body'
).
classed
(
'c3'
,
true
);
svg
=
body
.
append
(
'svg'
).
style
(
'visibility'
,
'hidden'
);
svg
.
append
(
'g'
).
call
(
axis
).
each
(
function
()
{
$$
.
d3
.
select
(
this
).
selectAll
(
'text tspan'
).
each
(
function
()
{
var
box
=
this
.
getBoundingClientRect
();
if
(
box
.
left
>
0
&&
maxWidth
<
box
.
width
)
{
maxWidth
=
box
.
width
;
}
if
(
box
.
left
>
=
0
&&
maxWidth
<
box
.
width
)
{
maxWidth
=
box
.
width
;
}
});
}).
remove
();
});
// TODO: time lag to get maxWidth
window
.
setTimeout
(
function
()
{
svg
.
remove
();
},
100
);
body
.
classed
(
'c3'
,
false
);
}
$$
.
currentMaxTickWidths
[
id
]
=
maxWidth
<=
0
?
$$
.
currentMaxTickWidths
[
id
]
:
maxWidth
;
return
$$
.
currentMaxTickWidths
[
id
];
...
...
src/core.js
View file @
6292548a
...
...
@@ -473,13 +473,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) {
if
(
targetsToShow
.
length
)
{
$$
.
updateXDomain
(
targetsToShow
,
withUpdateXDomain
,
withUpdateOrgXDomain
,
withTrimXDomain
);
if
(
!
config
.
axis_x_tick_values
)
{
if
(
config
.
axis_x_tick_fit
||
config
.
axis_x_tick_count
)
{
tickValues
=
$$
.
generateTickValues
(
$$
.
mapTargetsToUniqueXs
(
targetsToShow
),
config
.
axis_x_tick_count
,
$$
.
isTimeSeries
());
}
else
{
tickValues
=
undefined
;
}
$$
.
xAxis
.
tickValues
(
tickValues
);
$$
.
subXAxis
.
tickValues
(
tickValues
);
tickValues
=
$$
.
updateXAxisTickValues
(
targetsToShow
);
}
}
else
{
$$
.
xAxis
.
tickValues
([]);
...
...
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