Skip to content

Commit 14ba6f5

Browse files
committed
Rework rollups color
1 parent 8627e69 commit 14ba6f5

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

components/modules/rollup/RollupOverview.vue

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import BlobsTable from "./tables/BlobsTable.vue"
1515
import NamespacesTable from "./tables/NamespacesTable.vue"
1616
1717
/** Services */
18-
import { capitilize, comma, formatBytes, isMainnet, roundTo, truncateDecimalPart } from "@/services/utils"
18+
import { capitilize, comma, formatBytes, hexToRgba, isMainnet, roundTo, truncateDecimalPart } from "@/services/utils"
1919
import { exportToCSV } from "@/services/utils/export"
2020
import { getRankCategory } from "@/services/constants/rollups"
2121
@@ -173,18 +173,8 @@ onMounted(async () => {
173173
},
174174
})
175175
176-
/** Rollup Primary Color */
177-
const image = new Image()
178-
image.crossOrigin = "anonymous"
179-
image.onload = () => {
180-
const context = document.createElement("canvas").getContext("2d")
181-
context.drawImage(image, 0, 0, 1, 1)
182-
const i = context.getImageData(0, 0, 1, 1).data
183-
184-
rollupColor.value = `rgba(${i[0]},${i[1]},${i[2]},${i[3]})`
185-
rollupColorAlpha.value = `rgba(${i[0]},${i[1]},${i[2]},0)`
186-
}
187-
image.src = `${props.rollup.logo}?query=bg`
176+
rollupColor.value = hexToRgba(props.rollup.color, 1)
177+
rollupColorAlpha.value = hexToRgba(props.rollup.color, 0)
188178
})
189179
190180
/** Refetch Blobs/Messages on new page */

services/utils/general.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,23 @@ export function sortArrayOfObjects(arr, path, asc = true) {
206206
return asc ? valueA - valueB : valueB - valueA
207207
})
208208
}
209+
210+
export function hexToRgba(hex, alpha = 255) {
211+
let h = hex.replace(/^#/, '')
212+
213+
if (h.length === 3) {
214+
h = h.split('').map(c => c + c).join('')
215+
}
216+
217+
const int = parseInt(h, 16)
218+
const r = (int >> 16) & 255
219+
const g = (int >> 8) & 255
220+
const b = int & 255
221+
222+
let a = alpha
223+
if (alpha > 1) {
224+
a = Math.max(0, Math.min(255, alpha)) / 255
225+
}
226+
227+
return `rgba(${r}, ${g}, ${b}, ${a})`
228+
}

0 commit comments

Comments
 (0)