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

#7758 fix legend element not working #7798

Merged
merged 1 commit into from
Sep 19, 2018
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
30 changes: 24 additions & 6 deletions js/notebook/src/plot/PlotInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,16 @@ export default class PlotInteraction {
}

this.toggleLine(data, id);

this.updateShowAllLines();
this.scope.plotRange.calcRange();
this.scope.update();
}

toggleAllLines(data) {
this.scope.showAllItems = !this.scope.showAllItems;
this.scope.showAllItems = this.findLegendCheckAllElement().prop("checked");

for (let lineId in this.scope.legendMergedLines) {
this.toggleLine(data, lineId);
this.toggleLine(data, lineId, this.scope.showAllItems);

this.scope.jqlegendcontainer
.find("#legendcheck_" + lineId)
Expand All @@ -365,17 +365,17 @@ export default class PlotInteraction {
this.scope.update();
}

toggleLine(data, lineId) {
toggleLine(data, lineId, showItem: boolean = null) {
if (!this.scope.legendMergedLines.hasOwnProperty(lineId)) {
return;
}

const line = this.scope.legendMergedLines[lineId];
line.showItem = this.scope.showAllItems;
line.showItem = null === showItem ? !line.showItem : showItem;

for (let i = 0; i < line.dataIds.length; i++) {
let item = data[line.dataIds[i]];
item.showItem = this.scope.showAllItems;
item.showItem = line.showItem;

if (item.showItem === false) {
item.hideTips(this.scope, true);
Expand All @@ -394,4 +394,22 @@ export default class PlotInteraction {
}
}
}

updateShowAllLines(): void {
this.scope.showAllLines = this.calculateShowAllLines();
this.findLegendCheckAllElement()
.prop("checked", this.scope.showAllLines);
}

calculateShowAllLines(): boolean {
return Object.entries(this.scope.legendMergedLines)
.reduce((total, pair) => {
const [key, value] = pair;
return total && value.showItem;
}, true);
}

findLegendCheckAllElement(): JQuery<HTMLElement> {
return this.scope.jqlegendcontainer.find("[id^=legendcheck_all]");
}
}