-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from MetaCell/feature/CELE-107
CELE-107 Selection sync across widgets
- Loading branch information
Showing
11 changed files
with
348 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
applications/visualizer/frontend/src/components/viewers/EM/neuronsMapFeature.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import type { FeatureLike } from "ol/Feature"; | ||
import Fill from "ol/style/Fill"; | ||
import Stroke from "ol/style/Stroke"; | ||
import Style from "ol/style/Style"; | ||
import Text from "ol/style/Text"; | ||
|
||
export function hexToRGBArray(hex: string): [number, number, number] { | ||
hex = hex.replace("#", ""); | ||
const r = Number.parseInt(hex.slice(0, 2), 16); | ||
const g = Number.parseInt(hex.slice(2, 4), 16); | ||
const b = Number.parseInt(hex.slice(4, 6), 16); | ||
|
||
return [r, g, b]; | ||
} | ||
|
||
export function activeNeuronStyle(feature: FeatureLike, color?: string): Style { | ||
const opacity = 0.2; | ||
const [r, g, b] = color ? hexToRGBArray(color) : feature.get("color"); | ||
const rgbaColor = `rgba(${r}, ${g}, ${b}, ${opacity})`; | ||
|
||
return new Style({ | ||
stroke: new Stroke({ | ||
color: [r, g, b], | ||
width: 2, | ||
}), | ||
fill: new Fill({ | ||
color: rgbaColor, | ||
}), | ||
}); | ||
} | ||
|
||
export function selectedNeuronStyle(feature: FeatureLike, color?: string): Style { | ||
const opacity = 0.5; | ||
const [r, g, b] = color ? hexToRGBArray(color) : feature.get("color"); | ||
const rgbaColor = `rgba(${r}, ${g}, ${b}, ${opacity})`; | ||
|
||
return new Style({ | ||
stroke: new Stroke({ | ||
color: [r, g, b], | ||
width: 4, | ||
}), | ||
fill: new Fill({ | ||
color: rgbaColor, | ||
}), | ||
text: new Text({ | ||
text: feature.get("name"), | ||
scale: 2, | ||
}), | ||
}); | ||
} | ||
|
||
export function neuronFeatureName(feature: FeatureLike): string { | ||
const neuronName = feature.getProperties()?.name; | ||
|
||
if (typeof neuronName !== "string") { | ||
throw Error("neuron segment doesn't have a valid name property"); | ||
} | ||
|
||
return neuronName; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.