Skip to content
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
4 changes: 4 additions & 0 deletions app/(studio)/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ export interface StylingSettings {
labelOutlineColor: string;
labelFontSize: number;
labelOutlineThickness: number;
labelOffsetX: number;
labelOffsetY: number;
labelAlignment:
| 'auto'
| 'top-left'
Expand All @@ -214,6 +216,8 @@ export interface StylingSettings {
labelOutlineColor: string;
labelFontSize: number;
labelOutlineThickness: number;
labelOffsetX: number;
labelOffsetY: number;
};
individualLabelOverrides?: Record<string, IndividualLabelOverride>;
drawnPaths?: DrawnPath[]; // Array of user-drawn paths
Expand Down
62 changes: 62 additions & 0 deletions components/map-styling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ interface StylingSettings {
labelOutlineColor: string;
labelFontSize: number;
labelOutlineThickness: number;
labelOffsetX: number;
labelOffsetY: number;
labelAlignment:
| 'auto'
| 'top-left'
Expand All @@ -133,6 +135,8 @@ interface StylingSettings {
labelOutlineColor: string;
labelFontSize: number;
labelOutlineThickness: number;
labelOffsetX: number;
labelOffsetY: number;
};
}

Expand Down Expand Up @@ -1025,6 +1029,35 @@ export function MapStyling({
/>
</div>
</div>

<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="symbol-label-offset-x" className="text-sm">
X offset ({stylingSettings.symbol.labelOffsetX ?? 0}px)
</Label>
<Slider
id="symbol-label-offset-x"
value={[stylingSettings.symbol.labelOffsetX ?? 0]}
onValueChange={(value) => updateSetting('symbol', 'labelOffsetX', value[0])}
min={-50}
max={50}
step={1}
/>
</div>
<div className="space-y-2">
<Label htmlFor="symbol-label-offset-y" className="text-sm">
Y offset ({stylingSettings.symbol.labelOffsetY ?? 0}px)
</Label>
<Slider
id="symbol-label-offset-y"
value={[stylingSettings.symbol.labelOffsetY ?? 0]}
onValueChange={(value) => updateSetting('symbol', 'labelOffsetY', value[0])}
min={-50}
max={50}
step={1}
/>
</div>
</div>
</div>

<div className="space-y-2">
Expand Down Expand Up @@ -1207,6 +1240,35 @@ export function MapStyling({
/>
</div>
</div>

<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="choropleth-label-offset-x" className="text-sm">
X offset ({stylingSettings.choropleth.labelOffsetX ?? 0}px)
</Label>
<Slider
id="choropleth-label-offset-x"
value={[stylingSettings.choropleth.labelOffsetX ?? 0]}
onValueChange={(value) => updateSetting('choropleth', 'labelOffsetX', value[0])}
min={-50}
max={50}
step={1}
/>
</div>
<div className="space-y-2">
<Label htmlFor="choropleth-label-offset-y" className="text-sm">
Y offset ({stylingSettings.choropleth.labelOffsetY ?? 0}px)
</Label>
<Slider
id="choropleth-label-offset-y"
value={[stylingSettings.choropleth.labelOffsetY ?? 0]}
onValueChange={(value) => updateSetting('choropleth', 'labelOffsetY', value[0])}
min={-50}
max={50}
step={1}
/>
</div>
</div>
</div>
</div>
)}
Expand Down
12 changes: 8 additions & 4 deletions modules/map-preview/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,10 @@ export const renderSymbolLabels = ({
});

// Apply position override if exists, otherwise use calculated position
const finalX = hasPositionOverride ? override!.x! : projected[0] + position.dx;
const finalY = hasPositionOverride ? override!.y! : projected[1] + position.dy;
const offsetX = stylingSettings.symbol.labelOffsetX ?? 0;
const offsetY = stylingSettings.symbol.labelOffsetY ?? 0;
const finalX = hasPositionOverride ? override!.x! : projected[0] + position.dx + offsetX;
const finalY = hasPositionOverride ? override!.y! : projected[1] + position.dy + offsetY;

// Use override textAnchor/dominantBaseline if provided, otherwise use calculated position
const finalTextAnchor = textAnchor ?? position.anchor;
Expand Down Expand Up @@ -511,8 +513,10 @@ export const renderChoroplethLabels = ({
};

// Apply position override if exists, otherwise use centroid
const finalX = hasPositionOverride ? override!.x! : centroid[0];
const finalY = hasPositionOverride ? override!.y! : centroid[1];
const offsetX = stylingSettings.choropleth.labelOffsetX ?? 0;
const offsetY = stylingSettings.choropleth.labelOffsetY ?? 0;
const finalX = hasPositionOverride ? override!.x! : centroid[0] + offsetX;
const finalY = hasPositionOverride ? override!.y! : centroid[1] + offsetY;

textElement
.attr('x', finalX)
Expand Down
4 changes: 4 additions & 0 deletions state/studio-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ const createDefaultStylingSettings = (): StylingSettings => ({
labelOutlineColor: '#ffffff',
labelFontSize: 10,
labelOutlineThickness: 0,
labelOffsetX: 0,
labelOffsetY: 0,
labelAlignment: 'auto',
customSvgPath: '',
},
Expand All @@ -207,6 +209,8 @@ const createDefaultStylingSettings = (): StylingSettings => ({
labelOutlineColor: '#ffffff',
labelFontSize: 10,
labelOutlineThickness: 0,
labelOffsetX: 0,
labelOffsetY: 0,
},
individualLabelOverrides: {},
drawnPaths: [],
Expand Down
Loading