Skip to content

Commit ecb2c99

Browse files
authored
Merge pull request #50 from bence-toth/vertical-gradient-fix
Fixed vertical gradient issue
2 parents f2adf0f + b06b9a1 commit ecb2c99

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

triangle-mosaic/triangle-mosaic.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,18 @@ const getTriangleColorForGradient = ({coloring, center}) => {
233233
external: center
234234
})
235235

236-
ratio = getRatio(start.x, end.x, perpendicularPoint.x)
236+
ratio = (
237+
(start.x !== end.x)
238+
? getRatio(start.x, end.x, perpendicularPoint.x)
239+
: getRatio(start.y, end.y, perpendicularPoint.y)
240+
) || 0
237241
}
238242

239243
if (mode === 'radialGradient') {
240244
const gradientLength = getDistance(start, end)
241245
const triangleDistance = getDistance(start, center)
242246

243-
ratio = triangleDistance / gradientLength
247+
ratio = (triangleDistance / gradientLength) || 0
244248
}
245249

246250
const exactMatch = stops.find(([location]) => ratio === location)

0 commit comments

Comments
 (0)