Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make color assignment more predictable #110

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add support for processing the new offspot file-manager (#104)

### Changed

- Colors assigned to package names are not random anymore (#109)
- Many small UI adjustments (#106)

### Fixed

- Top toolbar is not working properly when there is no yearly aggregation (#101)

## [0.2.1] - 2024-01-26

### Added
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/stores/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineStore } from 'pinia'
import axios from 'axios'
import AggregationDetails from '@/types/AggregationDetails'
import AggregationKpiValue from '@/types/AggregationKpiValue'
import { getRandomColor } from '../utils'
import { colorScheme } from '../utils'

// Hard-coded for now, to be reworked once we will need this also for the slider
const monthText = (monthDigit: string): string => {
Expand Down Expand Up @@ -49,6 +49,7 @@ export type RootState = {
errorMessage: string | null
currentPage: Page
packagesColors: { [id: string]: string }
nextPackageColor: number
drawerVisible: boolean
}
export const useMainStore = defineStore('main', {
Expand All @@ -62,6 +63,7 @@ export const useMainStore = defineStore('main', {
currentPage: Page.Dashboard,
packagesColors: {},
drawerVisible: true,
nextPackageColor: 0,
}) as RootState,
getters: {
hasAggregationValues: (state) =>
Expand Down Expand Up @@ -128,7 +130,12 @@ export const useMainStore = defineStore('main', {
// and customisable (see #56 and #57)
return (packageName: string): string => {
if (!(packageName in state.packagesColors)) {
state.packagesColors[packageName] = getRandomColor()
state.packagesColors[packageName] =
colorScheme[state.nextPackageColor]
state.nextPackageColor++
if (state.nextPackageColor >= colorScheme.length) {
state.nextPackageColor = 0
}
}
return state.packagesColors[packageName]
}
Expand Down
33 changes: 17 additions & 16 deletions frontend/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
/*
Color scheme is from https://venngage.com/tools/accessible-color-palette-generator#colorGenerator
We selected colors mostly randomly
*/
export const colorScheme = [
'#00bf7d',
'#00b4c5',
'#f57600',
'#8babf1',
'#e6308a',
'#89ce00',
'#e6308a',
'#9b8bf4',
'#606ff3',
'#9b8bf4',
]

/*
* Get a random Hex color in our color scheme, to be used in CSS
*/
export const getRandomColor = (): string => {
/*
Color scheme is from https://venngage.com/tools/accessible-color-palette-generator#colorGenerator
We selected colors mostly randomly
*/
const colorScheme = [
'#00bf7d',
'#00b4c5',
'#f57600',
'#8babf1',
'#e6308a',
'#89ce00',
'#e6308a',
'#9b8bf4',
'#606ff3',
'#9b8bf4',
]
return colorScheme[Math.floor(Math.random() * colorScheme.length)]
}
Loading