Skip to content
Snippets Groups Projects
Unverified Commit f055f697 authored by xgui3783's avatar xgui3783 Committed by GitHub
Browse files

Merge pull request #876 from HumanBrainProject/bugfix_regionColor

bugfix: region colour
parents 3e256794 a17dd747
No related branches found
No related tags found
No related merge requests found
import { TestBed } from '@angular/core/testing'
import { MockStore, provideMockStore } from '@ngrx/store/testing'
import { RegionBase, regionInOtherTemplateSelector, getRegionParentParcRefSpace } from './region.base'
const util = require('common/util')
/**
* regions
......@@ -520,5 +521,96 @@ describe('> region.base.ts', () => {
expect(regionBase.position).toBeTruthy()
})
})
describe('> rgb', () => {
let strToRgbSpy: jasmine.Spy
let mockStore: MockStore
beforeEach(() => {
strToRgbSpy = spyOn(util, 'strToRgb')
mockStore = TestBed.inject(MockStore)
mockStore.overrideSelector(regionInOtherTemplateSelector, [])
mockStore.overrideSelector(getRegionParentParcRefSpace, { template: null, parcellation: null })
})
afterEach(() => {
strToRgbSpy.calls.reset()
})
it('> will take region.rgb if exists', () => {
const regionBase = new RegionBase(mockStore)
regionBase.region = {
rgb: [100, 120, 140]
}
expect(
regionBase.rgbString
).toEqual(`rgb(100,120,140)`)
})
it('> if rgb not provided, and labelIndex > 65500, set to white', () => {
const regionBase = new RegionBase(mockStore)
regionBase.region = {
labelIndex: 65535
}
expect(
regionBase.rgbString
).toEqual(`rgb(255,255,255)`)
})
describe('> if rgb not provided, labelIndex < 65500', () => {
describe('> arguments for strToRgb', () => {
it('> if ngId is defined, use ngId', () => {
const regionBase = new RegionBase(mockStore)
regionBase.region = {
ngId: 'foo',
name: 'bar',
labelIndex: 152
}
expect(strToRgbSpy).toHaveBeenCalledWith(`foo152`)
})
it('> if ngId is not defined, use name', () => {
const regionBase = new RegionBase(mockStore)
regionBase.region = {
name: 'bar',
labelIndex: 152
}
expect(strToRgbSpy).toHaveBeenCalledWith(`bar152`)
})
})
it('> calls strToRgb, and use return value for rgb', () => {
const getRandomNum = () => Math.floor(255*Math.random())
const arr = [
getRandomNum(),
getRandomNum(),
getRandomNum()
]
strToRgbSpy.and.returnValue(arr)
const regionBase = new RegionBase(mockStore)
regionBase.region = {
foo: 'bar'
}
expect(
regionBase.rgbString
).toEqual(`rgb(${arr.join(',')})`)
})
it('> if strToRgb returns falsy, uses fallback', () => {
strToRgbSpy.and.returnValue(null)
const regionBase = new RegionBase(mockStore)
regionBase.region = {
foo: 'bar'
}
expect(
regionBase.rgbString
).toEqual(`rgb(255,200,200)`)
})
})
})
})
})
......@@ -36,10 +36,10 @@ export class RegionBase {
this.position = val && val.position
if (!this._region) return
let rgb = this._region.rgb
rgb = rgb || this._region.labelIndex > 65500 ? [255, 255, 255] : null
rgb = rgb || strToRgb(`${this._region.ngId || this._region.name}${this._region.labelIndex}`)
rgb = rgb || [255, 200, 200]
const rgb = this._region.rgb
|| (this._region.labelIndex > 65500 && [255, 255, 255])
|| strToRgb(`${this._region.ngId || this._region.name}${this._region.labelIndex}`)
|| [255, 200, 200]
this.rgbString = `rgb(${rgb.join(',')})`
const [_h, _s, l] = rgbToHsl(...rgb)
......
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