Skip to content
This repository has been archived by the owner on Jan 29, 2021. It is now read-only.

Commit

Permalink
Fix: Fixed Selecting Paired Result Legend Item Affects Multiple Graphs (
Browse files Browse the repository at this point in the history
fixes #212) (#224)
  • Loading branch information
JananiGunasekaran authored Jun 3, 2020
1 parent ff9a7a8 commit 597a1b5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/js/controls/PairedResult/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,21 @@ const clickHandler = (graphContext, control, config, canvasSVG) => (
canvasSVG
.selectAll(`.${styles.pairedPoint}[aria-describedby="${item.key}"]`)
.attr("aria-hidden", legendSelected);
const boxPath = d3.selectAll(`.${styles.pairedBox}`);
showLine(config, boxPath);
/*
Select only those .carbon-data-pair elements that belong to the particular canvas for which a paired result legend item was clicked
and pass them to showLine() method.
This ensures that when there are multiple canvases with paired results in each canvas,
selecting a paired result legend item in one canvas does not affect paired results in other canvases.
*/
const pairedBoxGroupClipPath = `url(#${config.clipPathId})`;
const pairedBoxGroup = d3.selectAll(`.${styles.pairedBoxGroup}`);
pairedBoxGroup.each(function () {
const clipPath = d3.select(this).attr("clip-path");
if (clipPath === pairedBoxGroupClipPath) {
const boxPath = d3.select(this).selectAll(`.${styles.pairedBox}`);
showLine(config, boxPath);
}
});
window.requestAnimationFrame(
onAnimationHandler(graphContext, config, canvasSVG, item)
);
Expand Down
31 changes: 31 additions & 0 deletions src/test/unit/controls/PairedResult/PairedResultLoad-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2007,5 +2007,36 @@ describe("Paired Result - Load", () => {
.getAttribute("aria-describedby")
).toEqual(pairPrimary.key);
});
describe("When multiple canvases with paired results present", () => {
it("Shoud not affect paired results in other canvases", () => {
const inputPrimary = getInput(valuesDefault);
const primaryGraph = new Graph(getAxes(axisDefault));
primaryGraph.loadContent(new PairedResult(inputPrimary));
const secondaryGraph = new Graph(getAxes(axisDefault));
secondaryGraph.loadContent(new PairedResult(inputSecondary));
const legendItem = document.querySelector(
`.${styles.legendItem}[aria-describedby="${inputPrimary.key}_high"]`
);
triggerEvent(legendItem, "click");
const primaryGraphPRElement = pairedResultGraphContainer.querySelector(
`.${styles.pairedBoxGroup}[aria-describedby="${inputPrimary.key}"]`
);
const secondaryGraphPRElement = pairedResultGraphContainer.querySelector(
`.${styles.pairedBoxGroup}[aria-describedby="${inputSecondary.key}"]`
);
expect(
fetchElementByClass(
primaryGraphPRElement,
styles.pairedLine
).getAttribute("aria-hidden")
).toBe("true");
expect(
fetchElementByClass(
secondaryGraphPRElement,
styles.pairedLine
).getAttribute("aria-hidden")
).toBe("false");
});
});
});
});

0 comments on commit 597a1b5

Please sign in to comment.