Skip to content

Commit

Permalink
#7758 fix legend element not working
Browse files Browse the repository at this point in the history
  • Loading branch information
piorek committed Sep 19, 2018
1 parent 969a381 commit 274f455
Showing 1 changed file with 24 additions and 6 deletions.
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]");
}
}

0 comments on commit 274f455

Please sign in to comment.