Skip to content

ChartLayoutConstants

ClassChartGuruChartGuru
public static class ChartLayoutConstants

Centralized layout constants for consistent positioning across all chart rendering paths. These values are the single source of truth for all position calculations. Use GetScaled*() methods to obtain scale-aware values based on chart dimensions.

public static readonly Vector2 ReferenceChartSize

Reference chart size where base font sizes and spacing values look correct. Scaling is calculated relative to this size.

Returns

UnityEngine.Vector2 — No return description is available.

public const float DefaultMinTextScaleFactor = 0.25

Default minimum text scale factor to prevent text from becoming unreadably small. Can be overridden per-theme via ChartTheme.MinTextScaleFactor.

Returns

System.Single — No return description is available.

public const float DefaultMaxTextScaleFactor = 2.5

Default maximum text scale factor to prevent text from becoming too large. Can be overridden per-theme via ChartTheme.MaxTextScaleFactor.

Returns

System.Single — No return description is available.

public const float MinLayoutFontSize = 8

Minimum font size in pixels for layout calculations. Even if fonts render smaller, layout reserves at least this much space.

Returns

System.Single — No return description is available.

public const float MinVisibleFontSize = 6

Minimum font size in pixels below which text should be hidden rather than rendered. Set to 0 to always render text regardless of size.

Returns

System.Single — No return description is available.

public const float PieRadiusFraction = 0.5

Fraction of the smaller plot dimension used as the maximum pie/donut radius. Layout, sector rendering, hit geometry, and label positioning must all use this.

Returns

System.Single — No return description is available.

public const float CharWidthMultiplier = 0.6

Base character width multiplier relative to font size. Average character width is approximately 60% of font size for proportional fonts.

Returns

System.Single — No return description is available.

public const float LineHeightMultiplier = 1.3

Line height multiplier relative to font size. Typical line height is 120-140% of font size.

Returns

System.Single — No return description is available.

public const float ChartEdgePadding = 8

Base padding from chart edges. Ensures elements don’t touch the border.

Returns

System.Single — No return description is available.

public const float ElementSpacing = 4

Standard spacing between layout elements (e.g., axis title to axis labels).

Returns

System.Single — No return description is available.

public const float XAxisLabelOffsetY = 5

Vertical offset from plot area bottom edge to X-axis tick labels. In Cartesian coords: plotArea.yMin - this value.

Returns

System.Single — No return description is available.

public const float XAxisTitleOffsetY = 30

Base vertical offset from plot area bottom edge to X-axis title. Actual position calculated dynamically based on axis labels presence.

Returns

System.Single — No return description is available.

public const float YAxisLabelOffsetXLeft = 10

Horizontal offset from plot area left edge to Y-axis tick labels (left side). In Cartesian coords: plotArea.xMin - this value.

Returns

System.Single — No return description is available.

public const float YAxisLabelOffsetXRight = 5

Horizontal offset from plot area right edge to Y-axis tick labels (right side). In Cartesian coords: plotArea.xMax + this value.

Returns

System.Single — No return description is available.

public const float YAxisTitleOffsetX = 15

Base horizontal offset for Y-axis title positioning.

Returns

System.Single — No return description is available.

public const float DataLabelOffsetY = 8

Vertical offset from mark top to data label. For bars: label appears this many pixels above the bar top.

Returns

System.Single — No return description is available.

public const float DataLabelOffsetX = 6

Horizontal offset from horizontal bar end to data label. For horizontal bars: label appears this many pixels to the right of the bar.

Returns

System.Single — No return description is available.

public const float DataLabelBoundsPadding = 3

Padding from plot area edges for data labels to prevent overdraw with grid lines and axes. Labels will be kept this many pixels inside the plot area bounds.

Returns

System.Single — No return description is available.

public const float DataLabelHeightMultiplier = 1.3

Multiplier to estimate label height from font size. Accounts for line height and descenders. Typical value is 1.2-1.4. Usage: labelHeight = fontSize * DataLabelHeightMultiplier

Returns

System.Single — No return description is available.

public const float DataLabelCharWidthMultiplier = 0.6

Multiplier to estimate character width from font size. Approximation for average character width. Typical value is 0.5-0.7. Usage: charWidth = fontSize * DataLabelCharWidthMultiplier

Returns

System.Single — No return description is available.

public const float LegendTopOffsetY = 25

Vertical offset from plot area top edge to legend (when Position=Top). In Cartesian coords: plotArea.yMax + this value.

Returns

System.Single — No return description is available.

public const float LegendBottomOffsetY = 55

Vertical offset from plot area bottom edge to legend (when Position=Bottom). In Cartesian coords: plotArea.yMin - this value.

Returns

System.Single — No return description is available.

public const float LegendSideOffsetX = 15

Horizontal offset from plot area for side legends (Left/Right).

Returns

System.Single — No return description is available.

public const float LegendSwatchSize = 8

Size of legend color swatch (square).

Returns

System.Single — No return description is available.

public const float LegendSwatchPadding = 6

Padding between swatch and label text.

Returns

System.Single — No return description is available.

public const float LegendItemSpacing = 16

Spacing between legend items (horizontal layout).

Returns

System.Single — No return description is available.

public const float LegendBorderPadding = 4

Minimum inset between horizontal legends and the chart frame.

Returns

System.Single — No return description is available.

public const float LegendSidePlotPadding = 6

Inner padding between an outside leading legend and the plot area.

Returns

System.Single — No return description is available.

public const float MinSideLegendWidth = 80

Minimum width for side-positioned legends (Leading/Trailing). Ensures enough space for swatch + text.

Returns

System.Single — No return description is available.

public const float LegendRowSpacing = 4

Row spacing for multi-row legends.

Returns

System.Single — No return description is available.

public const float DefaultPadding = 8

Default padding around chart elements.

Returns

System.Single — No return description is available.

public const float SidePaddingPercent = 0.05

Side padding as percentage of plot area width for continuous charts.

Returns

System.Single — No return description is available.

public const float RightPaddingPercent = 0.08

Right padding as percentage for bar charts to leave room for labels.

Returns

System.Single — No return description is available.

public const float TopPaddingPercent = 0.08

Top padding as percentage of plot area Height (8%). Used by most chart types to leave room at top.

Returns

System.Single — No return description is available.

public const float LineSidePaddingPercent = 0.02

Side padding for line charts as percentage of plot area Width (2%).

Returns

System.Single — No return description is available.

public const float PointSidePaddingPercent = 0.05

Side padding for point/scatter charts as percentage of plot area Width (5%).

Returns

System.Single — No return description is available.

public const float TinyPaddingPixels = 2

Fixed pixel padding for tiny/compact charts.

Returns

System.Single — No return description is available.

public const float TinyPointPaddingPixels = 4

Fixed pixel padding for tiny point charts (slightly larger).

Returns

System.Single — No return description is available.

public static float GetTextScaleFactor(Vector2 chartSize, float minScale = 0.25, float maxScale = 2.5)

Calculates the text scale factor based on chart dimensions. Uses the smaller dimension ratio to ensure text fits in constrained spaces.

Parameters

Name Type Description
chartSize UnityEngine.Vector2 Current chart dimensions
minScale System.Single Minimum scale factor (default: DefaultMinTextScaleFactor)
maxScale System.Single Maximum scale factor (default: DefaultMaxTextScaleFactor)

Returns

System.Single — No return description is available.

GetContentScaleFactor(Vector2, LegendPosition, float, float)

Section titled “GetContentScaleFactor(Vector2, LegendPosition, float, float)”
public static float GetContentScaleFactor(Vector2 chartSize, LegendPosition position, float minScale = 0.25, float maxScale = 2.5)

Calculates a content scale factor that constrains by the dimension relevant to the legend’s position. Top/Bottom legends spread horizontally, so only width matters. Leading/Trailing legends stack vertically, so only height matters. Left/Right (inside-plot) and Hidden fall back to the standard min-based factor. Also used for scaling symbols and other content elements.

Parameters

Name Type Description
chartSize UnityEngine.Vector2
position ChartGuru.LegendPosition
minScale System.Single
maxScale System.Single

Returns

System.Single — No return description is available.

public static float GetScaledFontSize(float baseFontSize, float scaleFactor)

Gets the scaled font size for rendering. Returns actual scaled size, clamped to MinVisibleFontSize. Use this for actual text rendering.

Parameters

Name Type Description
baseFontSize System.Single
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetLayoutFontSize(float baseFontSize, float scaleFactor)

Gets the font size to use for layout space calculations. Always returns at least MinLayoutFontSize to ensure space is reserved for labels.

Parameters

Name Type Description
baseFontSize System.Single
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static bool IsTextVisible(float baseFontSize, float scaleFactor)

Returns true if text at this scaled size should be visible.

Parameters

Name Type Description
baseFontSize System.Single
scaleFactor System.Single

Returns

System.Boolean — No return description is available.

public static float EstimateTextWidth(string text, float fontSize)

Estimates the width of a text string based on font size.

Parameters

Name Type Description
text System.String
fontSize System.Single

Returns

System.Single — No return description is available.

public static float EstimateTextHeight(float fontSize)

Estimates the height of a single line of text based on font size.

Parameters

Name Type Description
fontSize System.Single

Returns

System.Single — No return description is available.

EstimateRotatedTextHeight(float, float, LabelRotation)

Section titled “EstimateRotatedTextHeight(float, float, LabelRotation)”
public static float EstimateRotatedTextHeight(float textWidth, float textHeight, LabelRotation rotation)

No description is available for this member.

Parameters

Name Type Description
textWidth System.Single
textHeight System.Single
rotation ChartGuru.LabelRotation

Returns

System.Single — No return description is available.

EstimateXAxisLabelHeight(float, float, int, int)

Section titled “EstimateXAxisLabelHeight(float, float, int, int)”
public static float EstimateXAxisLabelHeight(float fontSize, float availableWidth, int labelCount, int avgLabelLength = 4)

Estimates the height needed for X-axis labels, accounting for potential rotation. For small charts where labels are likely to be rotated, allocates more vertical space.

Parameters

Name Type Description
fontSize System.Single The font size for labels.
availableWidth System.Single The available width for the X-axis.
labelCount System.Int32 Number of X-axis labels.
avgLabelLength System.Int32 Average character length of labels (default 4).

Returns

System.Single — Estimated height needed for X-axis labels.

TruncateWithEllipsis(string, float, float)

Section titled “TruncateWithEllipsis(string, float, float)”
public static string TruncateWithEllipsis(string text, float maxWidth, float fontSize)

Truncates text with ellipsis if it exceeds the maximum width. Returns the original text if it fits, or truncated text with “…” appended.

Parameters

Name Type Description
text System.String
maxWidth System.Single
fontSize System.Single

Returns

System.String — No return description is available.

public static float GetScaledChartEdgePadding(float scaleFactor)

Gets scaled chart edge padding.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledElementSpacing(float scaleFactor)

Gets scaled element spacing.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledXAxisLabelOffsetY(float scaleFactor)

Gets scaled X-axis label offset.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledXAxisTitleOffsetY(float scaleFactor)

Gets scaled X-axis title offset.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledYAxisLabelOffsetXLeft(float scaleFactor)

Gets scaled Y-axis label offset for left-positioned axis.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledYAxisLabelOffsetXRight(float scaleFactor)

Gets scaled Y-axis label offset for right-positioned axis.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledYAxisTitleOffsetX(float scaleFactor)

Gets scaled Y-axis title offset.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledDataLabelOffsetY(float scaleFactor)

Gets scaled data label vertical offset.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledDataLabelOffsetX(float scaleFactor)

Gets scaled data label horizontal offset.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledDataLabelBoundsPadding(float scaleFactor)

Gets scaled data label bounds padding.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledLegendSwatchSize(float scaleFactor)

Gets scaled legend swatch size.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledLegendSwatchPadding(float scaleFactor)

Gets scaled legend swatch padding.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledLegendSidePlotPadding(float scaleFactor)

Gets scaled side legend padding next to the plot area.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledLegendItemSpacing(float scaleFactor)

Gets scaled legend item spacing.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledMinSideLegendWidth(float scaleFactor)

Gets scaled minimum side legend width.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

public static float GetScaledLegendRowSpacing(float scaleFactor)

Gets scaled legend row spacing.

Parameters

Name Type Description
scaleFactor System.Single

Returns

System.Single — No return description is available.

GetScaledLegendSymbolSize(float, ChartTheme)

Section titled “GetScaledLegendSymbolSize(float, ChartTheme)”
public static float GetScaledLegendSymbolSize(float scaleFactor, ChartTheme theme)

Gets scaled legend symbol size, using theme value if available.

Parameters

Name Type Description
scaleFactor System.Single
theme ChartGuru.ChartTheme

Returns

System.Single — No return description is available.

GetScaledLegendItemSpacing(float, ChartTheme)

Section titled “GetScaledLegendItemSpacing(float, ChartTheme)”
public static float GetScaledLegendItemSpacing(float scaleFactor, ChartTheme theme)

Gets scaled legend item spacing, using theme value if available.

Parameters

Name Type Description
scaleFactor System.Single
theme ChartGuru.ChartTheme

Returns

System.Single — No return description is available.

public static float GetLegendItemSpacing(ChartTheme theme)

Gets the legend item spacing, using theme value if available.

Parameters

Name Type Description
theme ChartGuru.ChartTheme

Returns

System.Single — No return description is available.

public static float GetLegendSymbolSize(ChartTheme theme)

Gets the legend symbol size, using theme value if available.

Parameters

Name Type Description
theme ChartGuru.ChartTheme

Returns

System.Single — No return description is available.

GetChartPadding(ChartType, float, float, bool, bool, bool)

Section titled “GetChartPadding(ChartType, float, float, bool, bool, bool)”
public static ChartLayoutConstants.ChartPadding GetChartPadding(ChartType chartType, float plotWidth, float plotHeight, bool isTiny = false, bool hasNegativeValues = false, bool isNormalizedStacking = false)

Gets the appropriate padding values for a chart type. Returns consistent values between series rendering and threshold zones.

Parameters

Name Type Description
chartType ChartGuru.ChartType The type of chart being rendered
plotWidth System.Single The width of the plot area in pixels
plotHeight System.Single The height of the plot area in pixels
isTiny System.Boolean Whether this is a tiny/compact chart
hasNegativeValues System.Boolean Whether the chart has negative Values (affects bottom padding)
isNormalizedStacking System.Boolean Whether using normalized Stacking (no top padding)

Returns

ChartGuru.ChartLayoutConstants.ChartPadding — ChartPadding struct with side, top, and bottom padding values