📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
improvements: custom-events colour using string to colour
kruzhambus9f0e9fd98e06
diff --git a/src/pages/Project/View/ViewProject.helpers.tsx b/src/pages/Project/View/ViewProject.helpers.tsxindex 29d0c0150..51c7e8d67 100644--- a/src/pages/Project/View/ViewProject.helpers.tsx+++ b/src/pages/Project/View/ViewProject.helpers.tsx@@ -281,6 +281,34 @@ const getColumnsPerf = (chart: {return columns}+const stringToColour = (str: string) => {+ let hash = 0++ // Loop through each character in the string+ for (let i = 0; i < str.length; i++) {+ // Get the ASCII code for the current character+ const charCode = str.charCodeAt(i)+ // Update the hash value using a simple algorithm+ hash = charCode + ((hash << 5) - hash)+ }++ // Initialise color value to #+ let colour = '#'++ // Generate 3-byte color code (RRGGBB)+ for (let i = 0; i < 3; i++) {+ // Get the next 8 bits of the hash value+ const value = (hash >> (i * 8)) & 0xFF+ // Convert the value to a 2-digit hex string+ const hexString = (`00${value.toString(16)}`).substr(-2)+ // Append the hex string to the color value+ colour += hexString+ }++ // Return the resulting color value+ return colour+}+// setting the default values for the time period dropdownconst noRegionPeriods = ['custom', 'yesterday']@@ -310,6 +338,19 @@ const getSettings = (return [el, ...customEvents[el]]}) : []+ let customEventsColors: {+ [key: string]: string,+ } = {}++ _forEach(_keys(customEvents), (el) => {+ customEventsColors = {+ ...customEventsColors,+ [el]: stringToColour(el),+ }+ })++ console.log('customEventsColors', customEventsColors)+if (!_isEmpty(forecasedChartData)) {lines.push({value: _last(chart?.x),@@ -389,6 +430,7 @@ const getSettings = (trendlineUnique: '#436abf',trendlineTotal: '#eba14b',sessionDuration: '#c945ed',+ ...customEventsColors,},regions,axes: {