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
dc50b136
Commit
dc50b136
authored
Mar 15, 2015
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix legend item width when multiple charts rendered - #1011
parent
2df80e98
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
10 deletions
+49
-10
c3.js
c3.js
+5
-5
c3.min.js
c3.min.js
+0
-0
legend-spec.js
spec/legend-spec.js
+39
-0
legend.js
src/legend.js
+5
-5
No files found.
c3.js
View file @
dc50b136
...
...
@@ -3812,6 +3812,7 @@
c3_chart_internal_fn
.
initLegend
=
function
()
{
var
$$
=
this
;
$$
.
legendItemTextBox
=
{};
$$
.
legendHasRendered
=
false
;
$$
.
legend
=
$$
.
svg
.
append
(
"g"
).
attr
(
"transform"
,
$$
.
getTranslate
(
'legend'
));
if
(
!
$$
.
config
.
legend_show
)
{
...
...
@@ -3919,9 +3920,8 @@
.
style
(
'opacity'
,
0
)
.
style
(
'visibility'
,
'hidden'
);
};
var
legendItemTextBox
=
{};
c3_chart_internal_fn
.
clearLegendItemTextBoxCache
=
function
()
{
legendItemTextBox
=
{};
this
.
legendItemTextBox
=
{};
};
c3_chart_internal_fn
.
updateLegend
=
function
(
targetIds
,
options
,
transitions
)
{
var
$$
=
this
,
config
=
$$
.
config
;
...
...
@@ -3936,10 +3936,10 @@
withTransitionForTransform
=
getOption
(
options
,
"withTransitionForTransform"
,
true
);
function
getTextBox
(
textElement
,
id
)
{
if
(
!
legendItemTextBox
[
id
])
{
legendItemTextBox
[
id
]
=
$$
.
getTextRect
(
textElement
.
textContent
,
CLASS
.
legendItem
);
if
(
!
$$
.
legendItemTextBox
[
id
])
{
$$
.
legendItemTextBox
[
id
]
=
$$
.
getTextRect
(
textElement
.
textContent
,
CLASS
.
legendItem
);
}
return
legendItemTextBox
[
id
];
return
$$
.
legendItemTextBox
[
id
];
}
function
updatePositions
(
textElement
,
id
,
index
)
{
...
...
c3.min.js
View file @
dc50b136
This source diff could not be displayed because it is too large. You can
view the blob
instead.
spec/legend-spec.js
View file @
dc50b136
...
...
@@ -7,6 +7,45 @@ describe('c3 chart legend', function () {
chart
=
window
.
initChart
(
chart
,
args
,
done
);
});
describe
(
'legend when multiple charts rendered'
,
function
()
{
it
(
'should update args'
,
function
()
{
args
=
{
data
:
{
columns
:
[
[
'data1'
,
30
],
[
'data2'
,
50
],
[
'data3'
,
100
]
]
}
};
expect
(
true
).
toBeTruthy
();
});
it
(
'should update args with long data names'
,
function
()
{
args
=
{
data
:
{
columns
:
[
[
'long data name 1'
,
30
],
[
'long data name 2'
,
50
],
[
'long data name 3'
,
50
],
]
}
};
expect
(
true
).
toBeTruthy
();
});
it
(
'should have properly computed legend width'
,
function
()
{
var
expectedLeft
=
[
148
,
226
,
384
],
expectedWidth
=
[
118
,
118
,
108
];
d3
.
selectAll
(
'.c3-legend-item'
).
each
(
function
(
d
,
i
)
{
var
rect
=
d3
.
select
(
this
).
node
().
getBoundingClientRect
();
expect
(
rect
.
left
).
toBeCloseTo
(
expectedLeft
[
i
],
-
2
);
expect
(
rect
.
width
).
toBeCloseTo
(
expectedWidth
[
i
],
-
2
);
});
});
});
describe
(
'legend position'
,
function
()
{
it
(
'should update args'
,
function
()
{
...
...
src/legend.js
View file @
dc50b136
c3_chart_internal_fn
.
initLegend
=
function
()
{
var
$$
=
this
;
$$
.
legendItemTextBox
=
{};
$$
.
legendHasRendered
=
false
;
$$
.
legend
=
$$
.
svg
.
append
(
"g"
).
attr
(
"transform"
,
$$
.
getTranslate
(
'legend'
));
if
(
!
$$
.
config
.
legend_show
)
{
...
...
@@ -107,9 +108,8 @@ c3_chart_internal_fn.hideLegend = function (targetIds) {
.
style
(
'opacity'
,
0
)
.
style
(
'visibility'
,
'hidden'
);
};
var
legendItemTextBox
=
{};
c3_chart_internal_fn
.
clearLegendItemTextBoxCache
=
function
()
{
legendItemTextBox
=
{};
this
.
legendItemTextBox
=
{};
};
c3_chart_internal_fn
.
updateLegend
=
function
(
targetIds
,
options
,
transitions
)
{
var
$$
=
this
,
config
=
$$
.
config
;
...
...
@@ -124,10 +124,10 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) {
withTransitionForTransform
=
getOption
(
options
,
"withTransitionForTransform"
,
true
);
function
getTextBox
(
textElement
,
id
)
{
if
(
!
legendItemTextBox
[
id
])
{
legendItemTextBox
[
id
]
=
$$
.
getTextRect
(
textElement
.
textContent
,
CLASS
.
legendItem
);
if
(
!
$$
.
legendItemTextBox
[
id
])
{
$$
.
legendItemTextBox
[
id
]
=
$$
.
getTextRect
(
textElement
.
textContent
,
CLASS
.
legendItem
);
}
return
legendItemTextBox
[
id
];
return
$$
.
legendItemTextBox
[
id
];
}
function
updatePositions
(
textElement
,
id
,
index
)
{
...
...
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