Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
Face details presentation (#161)
Browse files Browse the repository at this point in the history
* Create EmotionsCard component and add styling for it

* Modify carousel styles to center values

* Modifying html tags and styling feature details

* Fix width of emotions bar

* Fix if in emotionscard
  • Loading branch information
Lyczeq authored Sep 28, 2021
1 parent 46757e8 commit 0ad664f
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 26 deletions.
16 changes: 15 additions & 1 deletion frontend/src/assets/styles/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export const FeatureTitle = styled.p`
height: 10%;
width: 100%;
padding: 3% 0;
margin-bottom: 5%;
background: rgb(32, 104, 223);
background-image: linear-gradient(244deg, rgba(0, 232, 51, 0.5), rgba(60, 144, 228, 0));
font-size: 20px;
Expand All @@ -139,6 +138,13 @@ export const FeatureCarousel = styled(Carousel)`
height: 90%;
justify-content: center;
.rec.rec-item-wrapper {
height: 150px;
display: flex;
flex-direction: column;
justify-content: center;
}
.rec.rec-arrow {
background-color: #1da697;
margin: 0 2%;
Expand Down Expand Up @@ -181,6 +187,14 @@ export const FeatureCarousel = styled(Carousel)`
background-color: rgba(32, 104, 223, 0.5);
box-shadow: 0 0 1px 3px rgb(32, 104, 223);
}
ul {
align-self: center;
list-style: none;
}
li {
text-align: center;
}
`;

export const TextAnalysis = styled.div`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { EmotionsTemplate, EmotionBar } from './EmotionsCard.styles';

const EmotionsCard = ({ emotionsArray }) => {
return (
<EmotionsTemplate>
{emotionsArray.map((obj, i) => {
return (
<div key={i}>
<p key={obj}>{obj.emotion}</p>
{obj.emotionValue === 0 ? <p key={i}>Unknown</p> : <EmotionBar emotionValue={obj.emotionValue} key={i} />}
</div>
);
})}
</EmotionsTemplate>
);
};

export default EmotionsCard;
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import styled from 'styled-components';

export const EmotionsTemplate = styled.div`
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
p {
text-transform: capitalize;
}
div {
display: grid;
grid-template-columns: 1fr 1fr;
grid-row-gap: 1%;
}
`;

export const EmotionBar = styled.div`
display: block;
align-self: center;
width: ${({ emotionValue }) => {
switch (emotionValue) {
case 5:
return '100%';
case 4:
return '80%';
case 3:
return '60%';
case 2:
return '40%';
default:
return '15%';
}
}};
max-width: 80%;
height: 80%;
margin-left: 8%;
border-radius: 5px;
background: rgb(32, 104, 223);
background-image: linear-gradient(244deg, rgba(0, 232, 51, 0.5), rgba(60, 144, 228, 0));
`;
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
import { FeatureItem, FeatureTemplate, FeatureTitle, FeatureCarousel } from 'assets/styles/style';
import { FeatureTemplate, FeatureTitle, FeatureCarousel } from 'assets/styles/style';
import EmotionsCard from './EmotionsCard';

const faceDetailsValues = {
VERY_UNLIKELY: 'Very Unlikely',
UNLIKELY: 'Unlikely',
VERY_LIKELY: 'Very Likely',
LIKELY: 'Likely',
UNKNOWN: 'Unknown',
POSSIBLE: 'Possible',
const getEmotionsWithValues = (obj) => {
const emotionsObject = { ...obj };

const faceDetailsValues = {
VERY_LIKELY: 5,
LIKELY: 4,
POSSIBLE: 3,
UNLIKELY: 2,
VERY_UNLIKELY: 1,
UNKNOWN: 0,
};

const emotionNames = Object.keys(emotionsObject);
const emotionsMap = emotionNames.map((emotion) => {
return {
emotion,
emotionValue: faceDetailsValues[emotionsObject[emotion]],
};
});
return emotionsMap;
};

const extractEmotions = (faceDetails) => {
const copiedArray = [...faceDetails];

return copiedArray?.map(getEmotionsWithValues);
};

export const FaceTile = ({ faceDetails }) => {
Expand All @@ -15,14 +35,8 @@ export const FaceTile = ({ faceDetails }) => {
<FeatureTemplate>
<FeatureTitle>Face details</FeatureTitle>
<FeatureCarousel isNotMany={isNotMany}>
{faceDetails?.map((obj, i) => (
<FeatureItem key={i}>
{Object.keys(obj).map((k, i) => (
<p key={i}>
{k}: {faceDetailsValues[obj[k]]}
</p>
))}
</FeatureItem>
{extractEmotions(faceDetails).map((emotionsArray, i) => (
<EmotionsCard key={i} emotionsArray={emotionsArray} />
))}
</FeatureCarousel>
</FeatureTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export const FeatureTile = ({ title, features, offDots }) => {
<FeatureTemplate>
<FeatureTitle>{title}</FeatureTitle>
<FeatureCarousel isNotMany={isNotMany} offDots={offDots}>
{chunks.map((array) => (
<div>
{chunks.map((array, i) => (
<ul key={i}>
{array.map((element, i) => (
<p key={i}>{element}</p>
<li key={i}>{element}</li>
))}
</div>
</ul>
))}
</FeatureCarousel>
</FeatureTemplate>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { FeatureTemplate, FeatureItem, FeatureTitle, FeatureCarousel } from 'assets/styles/style';
import { FeatureTemplate, FeatureTitle, FeatureCarousel, TextAnalysis } from 'assets/styles/style';

export const TextEntityTile = ({ entity }) => {
return (
<FeatureTemplate>
<FeatureTitle>Text Entity Details</FeatureTitle>
<FeatureCarousel>
{entity?.map((obj, i) => (
<FeatureItem key={i}>
<TextAnalysis key={i}>
<p>{obj.name}</p>
<p>Type: {obj.type}</p>
<p>Sentiment: {obj.sentiment}</p>
</FeatureItem>
<p>
<span>Type</span>: {obj.type}
</p>
<p><span>Sentiment</span>: {obj.sentiment}</p>
</TextAnalysis>
))}
</FeatureCarousel>
</FeatureTemplate>
Expand Down

0 comments on commit 0ad664f

Please sign in to comment.