|
UsoUIElements 0.1.0
Data Centric implimentation of Unity's UI Elements (UI Toolkit)
|
A custom pie chart visualization control that extends Unity's VisualElement to provide dynamic data-driven circular chart rendering. Creates interactive pie charts based on supplied percentage values and colors, with real-time update capabilities and customizable appearance. More...
Public Member Functions | |
| UsoPieChart () | |
| Initializes a new instance of the UsoPieChart class with default settings and visual content generation. Sets up the chart for rendering and establishes the drawing callback for dynamic visual updates. | |
| void | UpdateChartData (List< PercentageColorData > newData) |
| Updates the pie chart's data with a new collection of percentage and color information. Replaces the current chart data and triggers an immediate visual refresh to display the changes. | |
Public Attributes | |
| List< PercentageColorData > | percentageColorData |
| Collection of percentage and color data that defines the pie chart segments. Each entry represents a slice of the pie with its proportional size and display color. | |
Properties | |
| float | diameter [get] |
| Gets the diameter of the pie chart calculated as twice the radius. This read-only property provides the total width and height of the circular chart area. | |
| float | radius [get, set] |
| Gets or sets the radius of the pie chart in pixels. Automatically updates the chart's visual dimensions and triggers a repaint when changed. | |
| float | value [get, set] |
| Gets or sets a legacy value property maintained for potential future functionality. Triggers a visual repaint when changed to ensure chart consistency. | |
Private Member Functions | |
| void | DrawCanvas (MeshGenerationContext ctx) |
| Renders the pie chart visual content using Unity's 2D painter system within the provided mesh generation context. Creates individual pie slices based on the percentageColorData collection with appropriate colors and proportions. | |
Private Attributes | |
| VisualElement | m_Chart |
| Visual element reference for the chart container. Used for managing chart-specific styling and layout properties. | |
| float | m_Radius = 100.0f |
| Private backing field for the pie chart's radius in pixels. Controls the size of the circular chart area and affects the overall visual scale. | |
| float | m_Value = 40.0f |
| Private backing field for a legacy value property. Maintained for potential future functionality or backward compatibility. | |
A custom pie chart visualization control that extends Unity's VisualElement to provide dynamic data-driven circular chart rendering. Creates interactive pie charts based on supplied percentage values and colors, with real-time update capabilities and customizable appearance.
This control provides comprehensive pie chart functionality within the USO UI framework's custom elements collection. It uses Unity's 2D painter system for high-performance rendering of circular chart segments with customizable colors and percentages. The chart automatically handles percentage-to-angle conversions, supports dynamic data updates, and provides smooth visual rendering through Unity's mesh generation context. The control is designed for displaying proportional data relationships in an intuitive circular format, commonly used for statistics, progress indicators, and data visualization scenarios.
Usage Example:
The control supports real-time updates through the UpdateChartData method and automatically manages visual refresh through Unity's dirty repaint system for optimal performance.
| GWG.UsoUIElements.CustomElements.UsoPieChart.UsoPieChart | ( | ) |
Initializes a new instance of the UsoPieChart class with default settings and visual content generation. Sets up the chart for rendering and establishes the drawing callback for dynamic visual updates.
The constructor registers the DrawCanvas method with Unity's generateVisualContent callback system, enabling the chart to render its visual content through Unity's 2D painter system. This approach provides high-performance rendering with automatic integration into Unity's UI rendering pipeline.
|
private |
Renders the pie chart visual content using Unity's 2D painter system within the provided mesh generation context. Creates individual pie slices based on the percentageColorData collection with appropriate colors and proportions.
| ctx | The MeshGenerationContext providing access to Unity's 2D painter for rendering operations. |
This method implements the core rendering logic for the pie chart, converting percentage data into angular segments and drawing them as filled arc shapes. The rendering process:
The method uses cumulative angle calculation to ensure segments are positioned correctly adjacent to each other, creating a complete circular representation. Each segment is drawn as a filled path starting from the chart center to create proper pie slice geometry.
| void GWG.UsoUIElements.CustomElements.UsoPieChart.UpdateChartData | ( | List< PercentageColorData > | newData | ) |
Updates the pie chart's data with a new collection of percentage and color information. Replaces the current chart data and triggers an immediate visual refresh to display the changes.
| newData | A list of PercentageColorData objects defining the new chart segments. |
This method provides the primary interface for updating chart content dynamically. It completely replaces the existing data set and automatically triggers a repaint to ensure the visual representation matches the new data immediately. The method supports real-time data visualization scenarios where chart content needs to change based on user interaction or data updates.
|
private |
Visual element reference for the chart container. Used for managing chart-specific styling and layout properties.
|
private |
Private backing field for the pie chart's radius in pixels. Controls the size of the circular chart area and affects the overall visual scale.
|
private |
Private backing field for a legacy value property. Maintained for potential future functionality or backward compatibility.
| List<PercentageColorData> GWG.UsoUIElements.CustomElements.UsoPieChart.percentageColorData |
Collection of percentage and color data that defines the pie chart segments. Each entry represents a slice of the pie with its proportional size and display color.
The list is initialized with default sample data showing a 40% green segment and 60% orange segment. This provides immediate visual feedback when the chart is first created and serves as an example of the expected data structure for chart customization.
|
get |
Gets the diameter of the pie chart calculated as twice the radius. This read-only property provides the total width and height of the circular chart area.
The diameter in pixels, calculated as radius * 2.
This property is used internally for setting chart dimensions and provides external access to the total chart size for layout calculations and positioning purposes.
|
getset |
Gets or sets the radius of the pie chart in pixels. Automatically updates the chart's visual dimensions and triggers a repaint when changed.
The radius value in pixels. Default is 100.0f.
Setting this property automatically updates both width and height of the chart to maintain a circular appearance. The chart dimensions are set to twice the radius (diameter) and a visual repaint is triggered to reflect the size change immediately.
|
getset |
Gets or sets a legacy value property maintained for potential future functionality. Triggers a visual repaint when changed to ensure chart consistency.
A floating-point value. Default is 40.0f.
This property appears to be maintained for backward compatibility or future enhancement. Currently, it triggers a repaint when changed but doesn't directly affect chart rendering, which is controlled by the percentageColorData collection.