Overview
ThegetVisualCenterTransform() function computes a CSS transform string that shifts a logo to align by its visual center rather than its geometric bounds.
Use this when rendering normalized logos to achieve better optical alignment, especially for logos with asymmetric visual weight distribution.
Signature
Parameters
The normalized logo object returned from the engine’s
normalizedLogos array.Must include the visualCenter property (computed during processing if densityAware is enabled).The alignment mode to use:
'bounds'— No transform, align by geometric center (bounding box)'visual-center'— Align by visual weight center on both X and Y axes'visual-center-x'— Align by visual center horizontally only'visual-center-y'— Align by visual center vertically only (recommended for horizontal logo strips)
Return Value
Returns a CSS transform string in the formattranslate(Xpx, Ypx), or undefined if:
alignByis'bounds'- The logo has no
visualCenterdata - The computed offset is too small to matter (< 0.5px)
Alignment Modes
bounds
No transformation. Logos align by their geometric bounding box center.Use when you want consistent mathematical spacing without optical adjustments.
visual-center
Full visual alignment. Shifts logos both horizontally and vertically to align by visual weight center.Best for grid layouts or centered single logos.
visual-center-x
Horizontal visual alignment only. Shifts logos left/right to align by visual weight center, but maintains geometric vertical alignment.Useful for vertical logo stacks.
visual-center-y
Vertical visual alignment only (recommended default). Shifts logos up/down to align by visual weight center, but maintains geometric horizontal alignment.Perfect for horizontal logo strips — the most common layout. Prevents heavy/bold logos from appearing to sink and light/thin logos from appearing to float.
Usage Examples
Basic Usage
React Component
Horizontal Strip (Recommended)
Vue Component
Conditional Transform
How It Works
- Computes scale factors based on the logo’s normalized dimensions and original/cropped size
- Calculates offsets from the visual center data (stored in
logo.visualCenter.offsetXandoffsetY) - Applies axis filtering based on the alignment mode
- Rounds offsets to 0.1px precision to avoid subpixel rendering issues
- Returns
undefinedif the offset is negligible (< 0.5px)
Visual Center Data
ThevisualCenter property is computed during processing when densityAware: true (default):
densityAware is false or visual center detection fails, the logo will not have this property and the function returns undefined.
When to Use Each Mode
| Layout | Recommended Mode | Reason |
|---|---|---|
| Horizontal strip | visual-center-y | Prevents sinking/floating effect |
| Vertical stack | visual-center-x | Aligns asymmetric logos |
| Grid | visual-center | Full optical alignment |
| Tight mathematical layout | bounds | Consistent geometric spacing |
Performance
This function performs simple arithmetic operations and is safe to call on every render. The computation is deterministic and does not trigger any side effects.Related
- NormalizedLogo — Logo object structure
- AlignmentMode — Alignment mode type
- VisualCenter — Visual center data structure
- createLogoSoup — Core engine