Skip to content
Open
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
11 changes: 10 additions & 1 deletion examples/graph-layers/graph-viewer/layout-options-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,22 @@ export function LayoutOptionsPanel({
appliedOptions,
onApply
}: LayoutOptionsPanelProps) {
const [isDagOptionsOpen, setIsDagOptionsOpen] = useState(true);
const handleDagToggle = useCallback((event: React.SyntheticEvent<HTMLDetailsElement>) => {
setIsDagOptionsOpen(event.currentTarget.open);
}, []);

if (!layout) {
return null;
}

if (layout === 'd3-dag-layout') {
return (
<details defaultOpen style={{borderTop: '1px solid #e2e8f0', paddingTop: '0.75rem'}}>
<details
open={isDagOptionsOpen}
onToggle={handleDagToggle}
style={{borderTop: '1px solid #e2e8f0', paddingTop: '0.75rem'}}
>
<summary
style={{
margin: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@
import {CompositeLayer} from '@deck.gl/core';
import {TextLayer} from '@deck.gl/layers';

// deck.gl's MultiIconLayer stores character offsets in a 16-bit buffer, so clamp the
// computed max width to avoid overflowing the attribute when stylesheet values are invalid.
const TEXT_LAYER_MAX_SAFE_WIDTH = 32767;

const clampMaxWidth = (value: unknown) => {
const width = Number(value);
if (!Number.isFinite(width) || width <= 0) {
return TEXT_LAYER_MAX_SAFE_WIDTH;
}
return Math.min(width, TEXT_LAYER_MAX_SAFE_WIDTH);
};

const normalizeMaxWidth = (value: unknown) => {
if (typeof value === 'function') {
return (d: unknown) => clampMaxWidth((value as (arg0: unknown) => unknown)(d));
}
return clampMaxWidth(value);
};

export class ZoomableTextLayer extends CompositeLayer {
static layerName = 'ZoomableTextLayer';

Expand Down Expand Up @@ -59,6 +78,8 @@ export class ZoomableTextLayer extends CompositeLayer {
// getText only expects function not plain value (string)
const newGetText = typeof getText === 'function' ? getText : () => getText;

const resolvedMaxWidth = normalizeMaxWidth(textMaxWidth);

return [
new TextLayer(
this.getSubLayerProps({
Expand All @@ -73,7 +94,7 @@ export class ZoomableTextLayer extends CompositeLayer {
getAlignmentBaseline,
getAngle,
getText: newGetText,
maxWidth: textMaxWidth ?? 12,
maxWidth: resolvedMaxWidth,
wordBreak: textWordBreak ?? 'break-all',
fontFamily: fontFamily ?? 'Red Hat Text',
wordUnits: textWordUnits ?? 'pixels',
Expand Down