Skip to content

fix: [NGRM] When zoomed in text labels on 3D axes shrinks. #2510 #2511

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

Merged
merged 17 commits into from
Apr 16, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { LayerExtension } from "@deck.gl/core";

/**
* The `FixedSizeExtension` class is a custom Deck.gl layer extension that modifies the size of rendered objects
* based on their clip-space position. This extension can be used to ensure that objects maintain a fixed size
* relative to the viewport, regardless of their depth in the scene.
*
* @extends LayerExtension
*
* @remarks
* The `getShaders` method injects a custom shader snippet into the vertex shader stage of Deck.gl's rendering pipeline.
* Specifically, it modifies the `size` variable by scaling it with `gl_Position.w`, which represents the depth
* component in clip space.
*
* @example
* ```typescript
* import { FixedSizeExtension } from './fixed-size-extension';
* import { TextLayer } from '@deck.gl/layers';
*
* const layer = new TextLayer({
* data,
* getPosition: d => d.coordinates,
* getText: d => d.label,
* getSize: d => d.size,
* extensions: [new FixedSizeExtension()],
* });
* ```
* @note See this discussion for more details: https://github.com/visgl/deck.gl/issues/7992
*/
export class FixedSizeExtension extends LayerExtension {
getShaders() {
return {
inject: {
"vs:DECKGL_FILTER_SIZE": "size *= gl_Position.w;",
},
};
}
}
38 changes: 22 additions & 16 deletions typescript/packages/subsurface-viewer/src/layers/axes/axesLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
import type { ExtendedLayerProps, Position3D } from "../utils/layerTools";
import BoxLayer from "./boxLayer";
import { ticks } from "d3-array";
import { FixedSizeExtension } from "../../extensions/fixed-size-extension";

export interface AxesLayerProps extends ExtendedLayerProps {
/**
Expand All @@ -27,7 +28,11 @@ export interface AxesLayerProps extends ExtendedLayerProps {
*/
bounds: BoundingBox3D;
labelColor?: Color;
labelFontSize?: number;
/**
* Font size for tick labels, specified in pixels. Axis labels are +7 pixels relative to this size.
* @default 12
*/
labelFontSize: number;
fontFamily?: string;
axisColor?: Color;
/** If true means that input z values are interpreted as depths.
Expand All @@ -46,6 +51,7 @@ const defaultProps = {
id: "axes-layer",
visible: true,
ZIncreasingDownwards: true,
labelFontSize: 12,
};

type TextLayerData = {
Expand Down Expand Up @@ -222,6 +228,7 @@ export default class AxesLayer extends CompositeLayer<AxesLayerProps> {
this.getBaseLine(d, is_orthographic),
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
getColor: this.props.labelColor || [0, 0, 0, 255],
extensions: [new FixedSizeExtension()],
})
);

Expand Down Expand Up @@ -256,7 +263,7 @@ function maketextLayerData(
tick_lines: number[],
tick_labels: string[],
bounds: BoundingBox3D,
labelFontSize?: number
labelFontSize: number
): [TextLayerData] {
const x_min = bounds[0];
const x_max = bounds[3];
Expand All @@ -273,29 +280,28 @@ function maketextLayerData(

const offset = ((dx + dy + dz) / 3.0) * 0.1;

const axisAnnotationData = {
label: "X",
from: [0.0, 0.0, 0.0],
to: [x_max + offset, y_min, z_min],
size: labelFontSize + 7,
};

const data = [
axisAnnotationData,
{
label: "X",
from: [0.0, 0.0, 0.0],
to: [x_max + offset, y_min, z_min],
size: labelFontSize ?? 26,
},
{
...axisAnnotationData,
label: "Y",
from: [0.0, 0.0, 0.0],
to: [x_min, y_max + offset, z_min],
size: labelFontSize ?? 26,
},
];

if (!is_orthographic) {
const z_axis_annotaion = {
data.push({
...axisAnnotationData,
label: "Z",
from: [0.0, 0.0, 0.0],
to: [x_min, y_min, z_max + offset],
size: labelFontSize ?? 26,
};
data.push(z_axis_annotaion);
});
}

for (let i = 0; i < tick_lines.length / 6; i++) {
Expand All @@ -315,7 +321,7 @@ function maketextLayerData(
label: label,
from: from,
to: to,
size: labelFontSize ?? 11,
size: labelFontSize,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { WellFeature } from "../types";
import { getTrajectory } from "../utils/trajectory";
import type { MergedTextLayerProps } from "./mergedTextLayer";
import { MergedTextLayer } from "./mergedTextLayer";
import { FixedSizeExtension } from "../../../extensions/fixed-size-extension";

type WellLabelLayerData = WellFeature;

Expand Down Expand Up @@ -97,6 +98,9 @@ const DEFAULT_PROPS: DefaultProps<WellLabelLayerProps> = {
enter: ([r, g, b]: Color) => [r, g, b, 0],
},
},

// Ensure labels honor pixel size in screen space
extensions: [new FixedSizeExtension()],
};

const getCumulativeDistance = (well_xyz: Position[]): number[] => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.