Skip to content

Commit 40b71f4

Browse files
authored
Merge branch 'main' into gov-filtering-cicero-api
2 parents b3c8b78 + 2578f65 commit 40b71f4

2 files changed

Lines changed: 76 additions & 3 deletions

File tree

server/routes/api/representatives.js

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ router.get('/:zipCode', async (req, res) => {
113113
photoUrl:
114114
rep.photo_origin_url ||
115115
'https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_1280.png',
116-
117-
socialMediaPages: getOfficialSocialMediaPages(rep.identifiers) // call
116+
socialMediaPages: getOfficialSocialMediaPages(rep.identifiers),
117+
photoCroppingCSS: getPhotoCroppingValues(rep.photo_cropping)
118118
}
119119

120120
return repInfo
@@ -127,6 +127,77 @@ router.get('/:zipCode', async (req, res) => {
127127
}
128128
})
129129

130+
/*
131+
* Returns string with the following properties:
132+
* - x-value: right or left. Indicates whether the photo should be cropped/positioned from the left or right side.
133+
* - y-value: top or bottom. Indicates whether the photo should be cropped/psoitioned from the top or bottom side.
134+
*
135+
* Example: "top left"
136+
*
137+
* @param {string} photoCropping - The photo cropping object from the CICERO API
138+
* @returns {string} - The photo cropping CSS value
139+
*
140+
*
141+
*/
142+
function getPhotoCroppingValues(photo_cropping_object) {
143+
// If the photo cropping object is not defined, return default value
144+
if (!photo_cropping_object) {
145+
return 'center center'
146+
}
147+
148+
// args
149+
let x = photo_cropping_object.x
150+
let y = photo_cropping_object.y
151+
let oriHeight = photo_cropping_object.oriHeight
152+
let origWidth = photo_cropping_object.origWidth
153+
154+
// 1. calculate threshold for the x space
155+
// we check if the coordinate starts on the left side of the image (the first half of the left side)
156+
let x_left_threeshold = origWidth / 4
157+
// we check if the coordinate starts on the right side of the image (the first half of the right side) and we reduce a margin of 5% to be flexible
158+
let substract_percentage = 0.05
159+
let x_right_threeshold =
160+
origWidth / 2 - substract_percentage * (origWidth / 2)
161+
// 2. calculate threeshold for the y space
162+
// we check if the coordinate starts on the top side of the image (the first half of the top side)
163+
let y_top_threeshold = oriHeight / 4
164+
// we check if the coordinate starts on the bottom side of the image (the first half of the bottom side) and we reduce a margin of 5% to be flexible
165+
let y_bottom_threeshold = oriHeight / 2 - (5 / 100) * (oriHeight / 2)
166+
167+
// 3. determine the css values for the cropping
168+
// if the coordinate does not reach any of the threesholds, we set the value to center
169+
let x_value = 'center'
170+
// left threshold met
171+
if (x <= x_left_threeshold) {
172+
x_value = 'left'
173+
}
174+
// right threshold met
175+
if (x >= x_right_threeshold) {
176+
x_value = 'right'
177+
}
178+
// we apply the same logic for the y or vertical direction
179+
let y_value = 'center'
180+
// top threshold met
181+
if (y <= y_top_threeshold) {
182+
y_value = 'top'
183+
}
184+
// bottom threshold met
185+
if (y >= y_bottom_threeshold) {
186+
y_value = 'bottom'
187+
}
188+
189+
// final css value with background position
190+
let css_value = x_value + ' ' + y_value
191+
192+
return css_value
193+
}
194+
195+
/*
196+
* Function used to extract social media pages and format them as JSON objects by using an array from another JSON object.
197+
* @param {array} identifiers - array of identifiers from the JSON object.
198+
* @return {array} socialMediaPages - array of social media pages.
199+
*/
200+
130201
function getOfficialSocialMediaPages(identifiers) {
131202
var social_media_pages = []
132203

src/components/RepresentativeCard.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
</div>
3333

3434
<v-img
35-
class="mx-auto rep-img"
35+
class="mx-auto text-align-left rep-img"
36+
v-bind="member"
3637
:src="member.photoUrl"
3738
height="75"
3839
width="75"
40+
:position="member.photoCroppingCSS"
3941
/>
4042
<v-card-subtitle class="text-center rep-img" v-text="member.address_city" />
4143
</v-card>

0 commit comments

Comments
 (0)