Skip to content

Commit

Permalink
Merge pull request #882 from concord-consortium/186031756-fix-fade-in…
Browse files Browse the repository at this point in the history
…-out-effects-in-graph-adornment

fix: fade in / out effects in graph adornment (PT-186031756)
  • Loading branch information
emcelroy authored Sep 14, 2023
2 parents d9c42f4 + eaff52f commit 96557a6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 39 deletions.
16 changes: 8 additions & 8 deletions v3/cypress/e2e/adornments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ context("Graph adornments", () => {
cy.get("[data-testid=graph-adornments-grid]")
.find("[data-testid=graph-adornments-grid__cell]").should("have.length", 1)
cy.get("[data-testid=adornment-wrapper]").should("have.length", 1)
cy.get("[data-testid=adornment-wrapper]").should("have.class", "fadeIn")
cy.get("[data-testid=adornment-wrapper]").should("have.class", "visible")
cy.get("[data-testid=graph-adornments-grid]").find("*[data-testid^=graph-count]").should("exist")
cy.get("[data-testid=graph-adornments-grid]").find("*[data-testid^=graph-count]").should("have.text", "21")
cy.wait(250)
countCheckbox.click()
cy.get("[data-testid=adornment-wrapper]").should("have.class", "fadeOut")
cy.get("[data-testid=adornment-wrapper]").should("have.class", "hidden")
})
it("adds a percent to the graph when the Percent checkbox is checked", () => {
c.selectTile("graph", 0)
Expand All @@ -53,12 +53,12 @@ context("Graph adornments", () => {
cy.get("[data-testid=graph-adornments-grid]")
.find("[data-testid=graph-adornments-grid__cell]").should("have.length", 9)
cy.get("[data-testid=adornment-wrapper]").should("have.length", 9)
cy.get("[data-testid=adornment-wrapper]").should("have.class", "fadeIn")
cy.get("[data-testid=adornment-wrapper]").should("have.class", "visible")
cy.get("[data-testid=graph-adornments-grid]").find("*[data-testid^=graph-count]").should("exist")
cy.get("[data-testid=graph-adornments-grid]").find("*[data-testid^=graph-count]").first().should("have.text", "0%")
cy.wait(250)
percentCheckbox.click()
cy.get("[data-testid=adornment-wrapper]").should("have.class", "fadeOut")
cy.get("[data-testid=adornment-wrapper]").should("have.class", "hidden")
})
it("adds a movable line to the graph when the Movable Line checkbox is checked", () => {
c.selectTile("graph", 0)
Expand All @@ -74,7 +74,7 @@ context("Graph adornments", () => {
cy.get("[data-testid=graph-adornments-grid]")
.find("[data-testid=graph-adornments-grid__cell]").should("have.length", 1)
cy.get("[data-testid=adornment-wrapper]").should("have.length", 1)
cy.get("[data-testid=adornment-wrapper]").should("have.class", "fadeIn")
cy.get("[data-testid=adornment-wrapper]").should("have.class", "visible")
cy.get("[data-testid=adornment-wrapper]").find("*[data-testid^=movable-line]").should("exist")
cy.get("[data-testid=adornment-wrapper]").find("*[data-testid^=movable-line-equation-container-]")
.find("[data-testid=movable-line-equation-]").should("not.be.empty")
Expand All @@ -83,7 +83,7 @@ context("Graph adornments", () => {
// TODO: Test unpinning equation box from line
cy.wait(250)
movableLineCheckbox.click()
cy.get("[data-testid=adornment-wrapper]").should("have.class", "fadeOut")
cy.get("[data-testid=adornment-wrapper]").should("have.class", "hidden")
})
it("adds a movable point to the graph when the Movable Point checkbox is checked", () => {
c.selectTile("graph", 0)
Expand All @@ -99,13 +99,13 @@ context("Graph adornments", () => {
cy.get("[data-testid=graph-adornments-grid]")
.find("[data-testid=graph-adornments-grid__cell]").should("have.length", 1)
cy.get("[data-testid=adornment-wrapper]").should("have.length", 1)
cy.get("[data-testid=adornment-wrapper]").should("have.class", "fadeIn")
cy.get("[data-testid=adornment-wrapper]").should("have.class", "visible")
cy.get("[data-testid=graph-adornments-grid]").find("*[data-testid^=movable-point]").should("exist")
// TODO: Also test the above after attributes are added to top and right axes (i.e. when there are multiple points)
// TODO: Test dragging of point
cy.wait(250)
movablePointCheckbox.click()
cy.get("[data-testid=adornment-wrapper]").should("have.class", "fadeOut")
cy.get("[data-testid=adornment-wrapper]").should("have.class", "hidden")
})

})
2 changes: 1 addition & 1 deletion v3/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Cypress.Commands.add("dragAttributeToTarget", (source, attribute, target, num =
caseCardHeaderDropZone: ".react-data-card .data-cell-lower",
caseCardCollectionDropZone: ".react-data-card .collection-header-row",
graphTile: ".graph-plot svg",
legend: ".graph-plot .droppable-legend",
legend: ".graph-plot .legend .chakra-menu__menu-button",
x_axis: ".codap-graph .droppable-axis.droppable-svg.bottom",
x_axis_label: ".codap-graph .axis-legend-attribute-menu.bottom .chakra-menu__menu-button",
y_axis: ".codap-graph .droppable-axis.droppable-svg.left",
Expand Down
37 changes: 28 additions & 9 deletions v3/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"lodash": "^4.17.21",
"mathjs": "^11.11.0",
"mobx": "^6.10.2",
"mobx-react-lite": "^3.4.3",
"mobx-react-lite": "^4.0.4",
"nanoid": "^4.0.2",
"papaparse": "^5.4.1",
"pluralize": "^8.0.0",
Expand Down
7 changes: 2 additions & 5 deletions v3/src/components/graph/adornments/adornment.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
top: 0;
width: 100%;

&.fadeIn {
&.visible {
animation-name: adornmentFadeIn;
opacity: 1;
}
&.fadeOut {
&.hidden {
animation-name: adornmentFadeOut;
opacity: 0;
}
&.hidden {
display: none;
}
}

@keyframes adornmentFadeIn {
Expand Down
22 changes: 7 additions & 15 deletions v3/src/components/graph/adornments/adornment.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useRef } from "react"
import React from "react"
import { clsx } from "clsx"
import { observer } from "mobx-react-lite"
import { IAdornmentModel } from "./adornment-models"
Expand Down Expand Up @@ -27,14 +27,7 @@ export const Adornment = observer(function Adornment(
: layout.plotWidth,
subPlotHeight = rightCats.length > 0
? layout.plotHeight / rightCats.length
: layout.plotHeight,
isFadeInComplete = useRef(false),
isFadeOutComplete = useRef(false)

useEffect(function fadeInCleanup() {
isFadeInComplete.current = adornment.isVisible
isFadeOutComplete.current = !adornment.isVisible
}, [adornment.isVisible])
: layout.plotHeight

const classFromCellKey = adornment.classNameFromKey(cellKey)
// The adornmentKey is a unique value used for React's key prop and for the adornment wrapper's HTML ID.
Expand All @@ -46,13 +39,12 @@ export const Adornment = observer(function Adornment(
const { Component } = componentInfo

const adornmentWrapperClass = clsx(
'adornment-wrapper',
"adornment-wrapper",
`${adornmentKey}-wrapper`,
`${classFromCellKey}`,
classFromCellKey,
{
'fadeIn': adornment.isVisible && !isFadeInComplete.current,
'fadeOut': !adornment.isVisible && !isFadeOutComplete.current,
'hidden': !adornment.isVisible && isFadeOutComplete.current
"visible": adornment.isVisible,
"hidden": !adornment.isVisible
}
)

Expand All @@ -61,7 +53,7 @@ export const Adornment = observer(function Adornment(
id={adornmentKey}
className={adornmentWrapperClass}
style={{animationDuration: `${transitionDuration}ms`}}
data-testid={'adornment-wrapper'}
data-testid={"adornment-wrapper"}
>
<Component
containerId={adornmentKey}
Expand Down

0 comments on commit 96557a6

Please sign in to comment.