Skip to content
Snippets Groups Projects
Commit 67be9680 authored by Xiao Gui's avatar Xiao Gui
Browse files

update color palette

parent 56155f89
No related branches found
No related tags found
No related merge requests found
...@@ -2,10 +2,16 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Out ...@@ -2,10 +2,16 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Out
import { SapiAtlasModel, SapiParcellationModel, SapiSpaceModel } from "src/atlasComponents/sapi/type"; import { SapiAtlasModel, SapiParcellationModel, SapiSpaceModel } from "src/atlasComponents/sapi/type";
import { FilterGroupedParcellationPipe, GroupedParcellation } from "src/atlasComponents/sapiViews/core/parcellation"; import { FilterGroupedParcellationPipe, GroupedParcellation } from "src/atlasComponents/sapiViews/core/parcellation";
export const defaultColorPalette = [ export const darkThemePalette = [
"#480202", "#141414",
"#6b1205", "#242424",
"#921d1d", "#333333",
]
export const lightThemePalette = [
"#ffffff",
"#fafafa",
"#f5f5f5",
] ]
export type ATP = { export type ATP = {
...@@ -37,7 +43,7 @@ const pipe = new FilterGroupedParcellationPipe() ...@@ -37,7 +43,7 @@ const pipe = new FilterGroupedParcellationPipe()
export class PureATPSelector implements OnChanges{ export class PureATPSelector implements OnChanges{
@Input('sxplr-pure-atp-selector-color-palette') @Input('sxplr-pure-atp-selector-color-palette')
colorPalette: string[] = defaultColorPalette colorPalette: string[] = darkThemePalette
@Input(`sxplr-pure-atp-selector-selected-atp`) @Input(`sxplr-pure-atp-selector-selected-atp`)
public selectedATP: ATP public selectedATP: ATP
......
...@@ -7,7 +7,7 @@ import { atlasId, provideDarkTheme } from "src/atlasComponents/sapi/stories.base ...@@ -7,7 +7,7 @@ import { atlasId, provideDarkTheme } from "src/atlasComponents/sapi/stories.base
import { SapiAtlasModel, SapiParcellationModel, SapiSpaceModel } from "src/atlasComponents/sapi/type"; import { SapiAtlasModel, SapiParcellationModel, SapiSpaceModel } from "src/atlasComponents/sapi/type";
import { UtilModule } from "src/util"; import { UtilModule } from "src/util";
import { ATPSelectorModule } from "../module"; import { ATPSelectorModule } from "../module";
import { defaultColorPalette } from "./pureATPSelector.components" import { darkThemePalette } from "./pureATPSelector.components"
import { loadAtlasEtcData, wrapperDecoratorFn } from "../story.base" import { loadAtlasEtcData, wrapperDecoratorFn } from "../story.base"
import { provideMockStore } from "@ngrx/store/testing"; import { provideMockStore } from "@ngrx/store/testing";
...@@ -39,9 +39,9 @@ import { provideMockStore } from "@ngrx/store/testing"; ...@@ -39,9 +39,9 @@ import { provideMockStore } from "@ngrx/store/testing";
] ]
}) })
class AtlasLayerSelectorWrapper { class AtlasLayerSelectorWrapper {
atlasColor: string = defaultColorPalette[0] atlasColor: string = darkThemePalette[0]
spaceColor: string = defaultColorPalette[1] spaceColor: string = darkThemePalette[1]
parcellationColor: string = defaultColorPalette[2] parcellationColor: string = darkThemePalette[2]
allAtlases: SapiAtlasModel[] allAtlases: SapiAtlasModel[]
availableTemplates: SapiSpaceModel[] availableTemplates: SapiSpaceModel[]
selectedATP: { selectedATP: {
...@@ -122,9 +122,9 @@ const Template: Story<AtlasLayerSelectorWrapper> = (args: AtlasLayerSelectorWrap ...@@ -122,9 +122,9 @@ const Template: Story<AtlasLayerSelectorWrapper> = (args: AtlasLayerSelectorWrap
export const Default = Template.bind({}) export const Default = Template.bind({})
Default.args = { Default.args = {
atlasColor: defaultColorPalette[0], atlasColor: darkThemePalette[0],
spaceColor: defaultColorPalette[1], spaceColor: darkThemePalette[1],
parcellationColor: defaultColorPalette[2], parcellationColor: darkThemePalette[2],
} }
Default.loaders = [ Default.loaders = [
async () => { async () => {
......
import { Component, OnDestroy } from "@angular/core"; import { Component, Inject, OnDestroy } from "@angular/core";
import { MatDialog } from "@angular/material/dialog"; import { MatDialog } from "@angular/material/dialog";
import { Store } from "@ngrx/store"; import { Store } from "@ngrx/store";
import { Observable, of, Subject, Subscription } from "rxjs"; import { Observable, of, Subject, Subscription } from "rxjs";
...@@ -8,8 +8,9 @@ import { ParcellationSupportedInSpacePipe } from "src/atlasComponents/sapiViews/ ...@@ -8,8 +8,9 @@ import { ParcellationSupportedInSpacePipe } from "src/atlasComponents/sapiViews/
import { atlasSelection } from "src/state"; import { atlasSelection } from "src/state";
import { fromRootStore } from "src/state/atlasSelection"; import { fromRootStore } from "src/state/atlasSelection";
import { DialogFallbackCmp } from "src/ui/dialogInfo"; import { DialogFallbackCmp } from "src/ui/dialogInfo";
import { DARKTHEME } from "src/util/injectionTokens";
import { ParcellationVisibilityService } from "../../../parcellation/parcellationVis.service"; import { ParcellationVisibilityService } from "../../../parcellation/parcellationVis.service";
import { defaultColorPalette, ATP } from "../pureDumb/pureATPSelector.components" import { darkThemePalette, lightThemePalette, ATP } from "../pureDumb/pureATPSelector.components"
function isATPGuard(obj: any): obj is ATP { function isATPGuard(obj: any): obj is ATP {
if (!obj) return false if (!obj) return false
...@@ -25,7 +26,8 @@ function isATPGuard(obj: any): obj is ATP { ...@@ -25,7 +26,8 @@ function isATPGuard(obj: any): obj is ATP {
}) })
export class WrapperATPSelector implements OnDestroy{ export class WrapperATPSelector implements OnDestroy{
defaultColorPalette = defaultColorPalette darkThemePalette = darkThemePalette
lightThemePalette = lightThemePalette
#subscription: Subscription[] = [] #subscription: Subscription[] = []
#parcSupportedInSpacePipe = new ParcellationSupportedInSpacePipe(this.sapi) #parcSupportedInSpacePipe = new ParcellationSupportedInSpacePipe(this.sapi)
...@@ -63,6 +65,7 @@ export class WrapperATPSelector implements OnDestroy{ ...@@ -63,6 +65,7 @@ export class WrapperATPSelector implements OnDestroy{
private store$: Store, private store$: Store,
private sapi: SAPI, private sapi: SAPI,
private svc: ParcellationVisibilityService, private svc: ParcellationVisibilityService,
@Inject(DARKTHEME) public darktheme$: Observable<boolean>
){ ){
this.#subscription.push( this.#subscription.push(
this.selectLeaf$.pipe( this.selectLeaf$.pipe(
......
<sxplr-pure-atp-selector <sxplr-pure-atp-selector
[sxplr-pure-atp-selector-color-palette]="defaultColorPalette" [sxplr-pure-atp-selector-color-palette]="(darktheme$ | async) ? darkThemePalette : lightThemePalette"
[sxplr-pure-atp-selector-selected-atp]="selectedATP$ | async" [sxplr-pure-atp-selector-selected-atp]="selectedATP$ | async"
[sxplr-pure-atp-selector-atlases]="allAtlases$ | async" [sxplr-pure-atp-selector-atlases]="allAtlases$ | async"
[sxplr-pure-atp-selector-templates]="availableTemplates$ | async" [sxplr-pure-atp-selector-templates]="availableTemplates$ | async"
......
...@@ -3,7 +3,7 @@ import { SmartChipContent } from "../smartChip.content.directive" ...@@ -3,7 +3,7 @@ import { SmartChipContent } from "../smartChip.content.directive"
import { SmartChipMenu } from "../smartChip.menu.directive"; import { SmartChipMenu } from "../smartChip.menu.directive";
import { rgbToHsl, hexToRgb } from 'common/util' import { rgbToHsl, hexToRgb } from 'common/util'
const cssColorIsDark = (input: string) => { const cssColorToHsl = (input: string) => {
if (/rgb/i.test(input)) { if (/rgb/i.test(input)) {
const match = /\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(input) const match = /\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(input)
if (!match) throw new Error(`rgb cannot be extracted ${input}`) if (!match) throw new Error(`rgb cannot be extracted ${input}`)
...@@ -13,7 +13,7 @@ const cssColorIsDark = (input: string) => { ...@@ -13,7 +13,7 @@ const cssColorIsDark = (input: string) => {
parseInt(match[3]), parseInt(match[3]),
] ]
const [_h, _s, l] = rgbToHsl(...rgb) const [_h, _s, l] = rgbToHsl(...rgb)
return l < 0.4 return l
} }
if (/hsl/i.test(input)) { if (/hsl/i.test(input)) {
const match = /\((.*)\)/.exec(input) const match = /\((.*)\)/.exec(input)
...@@ -21,13 +21,13 @@ const cssColorIsDark = (input: string) => { ...@@ -21,13 +21,13 @@ const cssColorIsDark = (input: string) => {
const trimmedL = l.trim() const trimmedL = l.trim()
if (/%$/.test(trimmedL)) { if (/%$/.test(trimmedL)) {
const match = /^([0-9]+)%/.exec(trimmedL) const match = /^([0-9]+)%/.exec(trimmedL)
return (parseInt(match[1]) / 100) < 0.4 return parseInt(match[1]) / 100
} }
} }
if (/^#/i.test(input) && input.length === 7) { if (/^#/i.test(input) && input.length === 7) {
const [r, g, b] = hexToRgb(input) const [r, g, b] = hexToRgb(input)
const [_h, _s, l] = rgbToHsl(r, g, b) const [_h, _s, l] = rgbToHsl(r, g, b)
return l < 0.6 return l
} }
throw new Error(`Cannot parse css color: ${input}`) throw new Error(`Cannot parse css color: ${input}`)
} }
...@@ -73,7 +73,8 @@ export class SmartChip<T extends object> implements OnChanges{ ...@@ -73,7 +73,8 @@ export class SmartChip<T extends object> implements OnChanges{
ngOnChanges(simpleChanges: SimpleChanges) { ngOnChanges(simpleChanges: SimpleChanges) {
if (simpleChanges.color) { if (simpleChanges.color) {
this.darkTheme = cssColorIsDark(this.color) const brightness = cssColorToHsl(this.color)
this.darkTheme = brightness < 0.4
? 'darktheme' ? 'darktheme'
: 'lighttheme' : 'lighttheme'
} }
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
.smart-chip .smart-chip
{ {
box-sizing: border-box;
height: 100%; height: 100%;
display: inline-block;
padding: 0.5rem 1rem; padding: 0.5rem 1rem;
border-radius: 1rem; border-radius: 1rem;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment