Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#877] [3.0] Chart legend 관련 예외 처리 #878

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 44 additions & 16 deletions src/components/chart/plugins/plugins.legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,19 @@ const modules = {
return;
}

const colorDOM = targetDOM.getElementsByClassName('ev-chart-legend-color')[0];
const nameDOM = targetDOM.getElementsByClassName('ev-chart-legend-name')[0];
const isActive = !colorDOM.className.includes('inactive');
const series = nameDOM.series;
const colorDOM = targetDOM?.getElementsByClassName('ev-chart-legend-color')[0];
const nameDOM = targetDOM?.getElementsByClassName('ev-chart-legend-name')[0];
const isActive = !colorDOM?.className.includes('inactive');
const series = nameDOM?.series;

if (isActive && this.seriesInfo.count === 1) {
return;
}

if (!colorDOM || !nameDOM) {
return;
}

if (isActive) {
this.seriesInfo.count--;
colorDOM.style.backgroundColor = opt.inactive;
Expand Down Expand Up @@ -232,6 +236,10 @@ const modules = {
resetLegend() {
const legendDOM = this.legendBoxDOM;

if (!legendDOM) {
return;
}

while (legendDOM.hasChildNodes()) {
legendDOM.removeChild(legendDOM.firstChild);
}
Expand Down Expand Up @@ -292,15 +300,19 @@ const modules = {
*/
setLegendPosition() {
const opt = this.options;
const position = opt.legend.position;
const wrapperStyle = this.wrapperDOM.style;
const legendStyle = this.legendDOM.style;
const boxStyle = this.legendBoxDOM.style;
const resizeStyle = this.resizeDOM.style;
const position = opt?.legend?.position;
const wrapperStyle = this.wrapperDOM?.style;
const legendStyle = this.legendDOM?.style;
const boxStyle = this.legendBoxDOM?.style;
const resizeStyle = this.resizeDOM?.style;

let chartRect;
const title = opt.title.show ? opt.title.height : 0;
const top = title + opt.legend.height;
const title = opt?.title?.show ? opt?.title?.height : 0;
const top = title + opt?.legend?.height;

if (!wrapperStyle || !legendStyle) {
return;
}

switch (position) {
case 'top':
Expand Down Expand Up @@ -413,9 +425,17 @@ const modules = {
* @returns {undefined}
*/
updateLegendContainerSize() {
const opt = this.options.legend;
if (!this.options || !this.legendBoxDOM) {
return;
}

const opt = this.options?.legend;
const container = this.legendBoxDOM.getElementsByClassName('ev-chart-legend-container');

if (!container) {
return;
}

for (let ix = 0; ix < container.length; ix++) {
if (opt.position === 'top' || opt.position === 'bottom') {
container[ix].style.width = `${opt.width - 8}px`;
Expand Down Expand Up @@ -571,6 +591,10 @@ const modules = {
* @returns {undefined}
*/
showLegend() {
if (!this.resizeDOM || !this.legendDOM) {
return;
}

this.resizeDOM.style.display = 'block';
this.legendDOM.style.display = 'block';
},
Expand All @@ -582,10 +606,14 @@ const modules = {
*/
hideLegend() {
const opt = this.options;
const wrapperStyle = this.wrapperDOM.style;
const resizeStyle = this.resizeDOM.style;
const legendStyle = this.legendDOM.style;
const title = opt.title.show ? opt.title.height : 0;
const wrapperStyle = this.wrapperDOM?.style;
const resizeStyle = this.resizeDOM?.style;
const legendStyle = this.legendDOM?.style;
const title = opt?.title?.show ? opt?.title?.height : 0;

if (resizeStyle || legendStyle || wrapperStyle) {
return;
}

resizeStyle.display = 'none';
legendStyle.display = 'none';
Expand Down