Skip to content

Commit

Permalink
fix color scales
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Sep 23, 2024
1 parent 0c93e1a commit 44345db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion frontend/src/modules/2DViewer/view/utils/layerFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PolygonData_api, SurfaceDef_api, WellboreTrajectory_api } from "@api";
import { Layer } from "@deck.gl/core/typed";
import { GeoJsonLayer } from "@deck.gl/layers/typed";
import { ColorScaleGradientType } from "@lib/utils/ColorScale";
import { Vec2, rotatePoint2Around } from "@lib/utils/vec2";
import { GridMappedProperty_trans, GridSurface_trans } from "@modules/3DViewer/view/queries/queryDataTransforms";
import { SurfaceDataFloat_trans } from "@modules/_shared/Surface/queryDataTransforms";
Expand Down Expand Up @@ -287,7 +288,18 @@ function makeColorMapFunction(
}

return (value: number) => {
const nonNormalizedValue = value * (colorScale.getMax() - colorScale.getMin()) + colorScale.getMin();
let nonNormalizedValue = value * (colorScale.getMax() - colorScale.getMin()) + colorScale.getMin();
if (colorScale.getGradientType() === ColorScaleGradientType.Diverging) {
if (nonNormalizedValue < colorScale.getDivMidPoint()) {
nonNormalizedValue = value * (colorScale.getDivMidPoint() - colorScale.getMin()) + colorScale.getMin();
}
if (nonNormalizedValue >= colorScale.getDivMidPoint()) {
nonNormalizedValue =
1 -
(nonNormalizedValue - colorScale.getDivMidPoint()) /
(colorScale.getMax() - colorScale.getDivMidPoint());
}
}
const interpolatedColor = colorScale.getColorForValue(nonNormalizedValue);
const color = parse(interpolatedColor) as Rgb;
if (color === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function findColorScale(layer: Layer<any, any>): { id: string; colorScale: Color
if (!colorScaleItem.getAreBoundariesUserDefined()) {
const range = layer.getLayerDelegate().getValueRange();
if (range) {
colorScaleWithName.setRange(range[0], range[1]);
colorScaleWithName.setRangeAndMidPoint(range[0], range[1], (range[0] + range[1]) / 2);
}
}

Expand Down

0 comments on commit 44345db

Please sign in to comment.