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
908e828b
Commit
908e828b
authored
Mar 09, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add legend.equally option for locate legends equllay - #62
parent
9ab4969a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
36 deletions
+61
-36
c3.js
c3.js
+61
-36
c3.min.js
c3.min.js
+0
-0
No files found.
c3.js
View file @
908e828b
...
@@ -77,7 +77,8 @@
...
@@ -77,7 +77,8 @@
// legend
// legend
var
__legend_show
=
getConfig
([
'legend'
,
'show'
],
true
),
var
__legend_show
=
getConfig
([
'legend'
,
'show'
],
true
),
__legend_position
=
getConfig
([
'legend'
,
'position'
],
'bottom'
),
__legend_position
=
getConfig
([
'legend'
,
'position'
],
'bottom'
),
__legend_item_onclick
=
getConfig
([
'legend'
,
'item'
,
'onclick'
],
function
()
{});
__legend_item_onclick
=
getConfig
([
'legend'
,
'item'
,
'onclick'
],
function
()
{}),
__legend_equally
=
getConfig
([
'legend'
,
'equally'
],
false
);
// axis
// axis
var
__axis_rotated
=
getConfig
([
'axis'
,
'rotated'
],
false
),
var
__axis_rotated
=
getConfig
([
'axis'
,
'rotated'
],
false
),
...
@@ -358,6 +359,7 @@
...
@@ -358,6 +359,7 @@
return
maxDataCount
>
1
?
(
base
*
ratio
)
/
(
maxDataCount
-
1
)
:
base
;
return
maxDataCount
>
1
?
(
base
*
ratio
)
/
(
maxDataCount
-
1
)
:
base
;
}
}
function
getLegendWidth
()
{
function
getLegendWidth
()
{
// TODO: legend width should be an option
return
__legend_show
?
isLegendRight
?
150
:
currentWidth
:
0
;
return
__legend_show
?
isLegendRight
?
150
:
currentWidth
:
0
;
}
}
function
getLegendHeight
()
{
function
getLegendHeight
()
{
...
@@ -2827,61 +2829,84 @@
...
@@ -2827,61 +2829,84 @@
function
updateLegend
(
targets
,
options
)
{
function
updateLegend
(
targets
,
options
)
{
var
ids
=
getTargetIds
(
targets
),
l
;
var
ids
=
getTargetIds
(
targets
),
l
;
var
xForLegend
,
xForLegendText
,
xForLegendRect
,
yForLegend
,
yForLegendText
,
yForLegendRect
;
var
xForLegend
,
xForLegendText
,
xForLegendRect
,
yForLegend
,
yForLegendText
,
yForLegendRect
;
var
item_height
=
0
,
item_width
=
0
,
paddingTop
=
4
,
paddingRight
=
30
,
margin
,
updateSizes
;
var
paddingTop
=
4
,
paddingRight
=
30
,
margin
;
var
totalLength
=
0
,
offsets
=
{},
widths
=
{},
heights
=
{};
var
withTransition
;
var
withTransition
;
options
=
isUndefined
(
options
)
?
{}
:
options
;
options
=
isUndefined
(
options
)
?
{}
:
options
;
withTransition
=
isDefined
(
options
.
withTransition
)
?
options
.
withTransition
:
true
;
withTransition
=
isDefined
(
options
.
withTransition
)
?
options
.
withTransition
:
true
;
if
(
isLegendRight
)
{
function
getXOffset
(
id
,
i
)
{
xForLegend
=
function
()
{
return
legendWidth
*
0.2
;
};
return
__legend_equally
?
widths
[
id
]
*
i
:
offsets
[
id
];
yForLegend
=
function
(
d
,
i
)
{
return
margin
+
item_height
*
i
;
};
}
}
else
{
function
getYOffset
(
id
,
i
)
{
xForLegend
=
function
(
d
,
i
)
{
return
margin
+
item_width
*
i
;
};
return
__legend_equally
?
heights
[
id
]
*
i
:
offsets
[
id
];
yForLegend
=
function
()
{
return
legendHeight
*
0.2
;
};
}
}
xForLegendText
=
function
(
d
,
i
)
{
return
xForLegend
(
d
,
i
)
+
14
;
};
function
updatePositions
(
textElement
,
id
)
{
yForLegendText
=
function
(
d
,
i
)
{
return
yForLegend
(
d
,
i
)
+
9
;
};
xForLegendRect
=
function
(
d
,
i
)
{
return
xForLegend
(
d
,
i
)
-
4
;
};
yForLegendRect
=
function
(
d
,
i
)
{
return
yForLegend
(
d
,
i
)
-
7
;
};
updateSizes
=
function
(
textElement
)
{
var
box
=
textElement
.
getBBox
(),
var
box
=
textElement
.
getBBox
(),
width
=
Math
.
ceil
((
box
.
width
+
paddingRight
)
/
10
)
*
10
,
width
=
Math
.
ceil
((
box
.
width
+
paddingRight
)
/
10
)
*
10
,
height
=
Math
.
ceil
((
box
.
height
+
paddingTop
)
/
10
)
*
10
;
height
=
Math
.
ceil
((
box
.
height
+
paddingTop
)
/
10
)
*
10
,
if
(
width
>
item_width
)
{
length
=
isLegendRight
?
height
:
width
,
item_width
=
width
;
areaLength
=
isLegendRight
?
legendHeight
:
legendWidth
,
if
(
!
isLegendRight
)
{
maxWidth
,
maxHeight
;
margin
=
(
legendWidth
-
item_width
*
Object
.
keys
(
targets
).
length
)
/
2
;
widths
[
id
]
=
width
;
heights
[
id
]
=
height
;
if
(
__legend_equally
)
{
maxWidth
=
d3
.
max
(
Object
.
keys
(
widths
).
map
(
function
(
key
)
{
return
widths
[
key
];
}));
maxHeight
=
d3
.
max
(
Object
.
keys
(
heights
).
map
(
function
(
key
)
{
return
heights
[
key
];
}));
if
(
width
>=
maxWidth
)
{
Object
.
keys
(
widths
).
forEach
(
function
(
key
)
{
widths
[
key
]
=
width
;
});
if
(
!
isLegendRight
)
{
margin
=
(
legendWidth
-
width
*
Object
.
keys
(
targets
).
length
)
/
2
;
}
}
}
}
if
(
height
>=
maxHeight
)
{
if
(
height
>
item_height
)
{
Object
.
keys
(
heights
).
forEach
(
function
(
key
)
{
heights
[
key
]
=
height
;
});
item_height
=
height
;
if
(
isLegendRight
)
{
if
(
isLegendRight
)
{
margin
=
(
legendHeight
-
height
*
Object
.
keys
(
targets
).
length
)
/
2
;
margin
=
(
legendHeight
-
item_height
*
Object
.
keys
(
targets
).
length
)
/
2
;
}
}
}
}
else
{
offsets
[
id
]
=
totalLength
;
totalLength
+=
length
;
margin
=
(
areaLength
-
totalLength
)
/
2
;
}
}
};
}
if
(
isLegendRight
)
{
xForLegend
=
function
()
{
return
legendWidth
*
0.2
;
};
yForLegend
=
function
(
id
,
i
)
{
return
margin
+
getYOffset
(
id
,
i
);
};
}
else
{
xForLegend
=
function
(
id
,
i
)
{
return
margin
+
getXOffset
(
id
,
i
);
};
yForLegend
=
function
()
{
return
legendHeight
*
0.2
;
};
}
xForLegendText
=
function
(
id
,
i
)
{
return
xForLegend
(
id
,
i
)
+
14
;
};
yForLegendText
=
function
(
id
,
i
)
{
return
yForLegend
(
id
,
i
)
+
9
;
};
xForLegendRect
=
function
(
id
,
i
)
{
return
xForLegend
(
id
,
i
)
-
4
;
};
yForLegendRect
=
function
(
id
,
i
)
{
return
yForLegend
(
id
,
i
)
-
7
;
};
// Define g for legend area
// Define g for legend area
l
=
legend
.
selectAll
(
'.legend-item'
)
l
=
legend
.
selectAll
(
'.legend-item'
)
.
data
(
ids
)
.
data
(
ids
)
.
enter
().
append
(
'g'
)
.
enter
().
append
(
'g'
)
.
attr
(
'class'
,
function
(
d
)
{
return
'legend-item legend-item-'
+
d
;
})
.
attr
(
'class'
,
function
(
id
)
{
return
'legend-item legend-item-'
+
i
d
;
})
.
style
(
'cursor'
,
'pointer'
)
.
style
(
'cursor'
,
'pointer'
)
.
on
(
'click'
,
function
(
d
)
{
.
on
(
'click'
,
function
(
i
d
)
{
__legend_item_onclick
(
d
);
__legend_item_onclick
(
i
d
);
})
})
.
on
(
'mouseover'
,
function
(
d
)
{
.
on
(
'mouseover'
,
function
(
i
d
)
{
focusLegend
(
d
);
focusLegend
(
i
d
);
c3
.
focus
(
d
);
c3
.
focus
(
i
d
);
})
})
.
on
(
'mouseout'
,
function
()
{
.
on
(
'mouseout'
,
function
()
{
revertLegend
();
revertLegend
();
c3
.
revert
();
c3
.
revert
();
});
});
l
.
append
(
'text'
)
l
.
append
(
'text'
)
.
text
(
function
(
d
)
{
return
isDefined
(
__data_names
[
d
])
?
__data_names
[
d
]
:
d
;
})
.
text
(
function
(
id
)
{
return
isDefined
(
__data_names
[
id
])
?
__data_names
[
id
]
:
i
d
;
})
.
each
(
function
(
)
{
updateSizes
(
this
);
})
.
each
(
function
(
id
)
{
updatePositions
(
this
,
id
);
})
.
style
(
"pointer-events"
,
"none"
)
.
style
(
"pointer-events"
,
"none"
)
.
attr
(
'x'
,
isLegendRight
?
xForLegendText
:
-
200
)
.
attr
(
'x'
,
isLegendRight
?
xForLegendText
:
-
200
)
.
attr
(
'y'
,
isLegendRight
?
-
200
:
yForLegend
);
.
attr
(
'y'
,
isLegendRight
?
-
200
:
yForLegend
);
...
@@ -2890,12 +2915,12 @@
...
@@ -2890,12 +2915,12 @@
.
style
(
'fill-opacity'
,
0
)
.
style
(
'fill-opacity'
,
0
)
.
attr
(
'x'
,
isLegendRight
?
xForLegendRect
:
-
200
)
.
attr
(
'x'
,
isLegendRight
?
xForLegendRect
:
-
200
)
.
attr
(
'y'
,
isLegendRight
?
-
200
:
yForLegendRect
)
.
attr
(
'y'
,
isLegendRight
?
-
200
:
yForLegendRect
)
.
attr
(
'width'
,
item_width
+
14
)
.
attr
(
'width'
,
function
(
id
)
{
return
widths
[
id
];
}
)
.
attr
(
'height'
,
24
);
.
attr
(
'height'
,
function
(
id
)
{
return
heights
[
id
];
}
);
l
.
append
(
'rect'
)
l
.
append
(
'rect'
)
.
attr
(
"class"
,
"legend-item-tile"
)
.
attr
(
"class"
,
"legend-item-tile"
)
.
style
(
"pointer-events"
,
"none"
)
.
style
(
"pointer-events"
,
"none"
)
.
style
(
'fill'
,
function
(
d
)
{
return
color
(
d
);
})
.
style
(
'fill'
,
function
(
id
)
{
return
color
(
i
d
);
})
.
attr
(
'x'
,
isLegendRight
?
xForLegendText
:
-
200
)
.
attr
(
'x'
,
isLegendRight
?
xForLegendText
:
-
200
)
.
attr
(
'y'
,
isLegendRight
?
-
200
:
yForLegendText
)
.
attr
(
'y'
,
isLegendRight
?
-
200
:
yForLegendText
)
.
attr
(
'width'
,
10
)
.
attr
(
'width'
,
10
)
...
@@ -2903,7 +2928,7 @@
...
@@ -2903,7 +2928,7 @@
legend
.
selectAll
(
'text'
)
legend
.
selectAll
(
'text'
)
.
data
(
ids
)
.
data
(
ids
)
.
each
(
function
(
)
{
updateSizes
(
this
);
})
.
each
(
function
(
id
)
{
updatePositions
(
this
,
id
);
})
.
transition
().
duration
(
withTransition
?
250
:
0
)
.
transition
().
duration
(
withTransition
?
250
:
0
)
.
attr
(
'x'
,
xForLegendText
)
.
attr
(
'x'
,
xForLegendText
)
.
attr
(
'y'
,
yForLegendText
);
.
attr
(
'y'
,
yForLegendText
);
...
...
c3.min.js
View file @
908e828b
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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