Open
Conversation
…ext, PushStyle, etc.)
…itGap to DigitalSpacing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per-Index Color Support with ImPlotSpec
Summary
This PR introduces comprehensive per-index color support across all ImPlot plot types. Users can now specify an array of colors to apply different colors to each vertex, segment, bar, marker, or other primitive in their plots, enabling rich data visualizations with color-coded information.
This implementation is based on previous work #332 by @niavok and #665 by @vincentjzy.
Features
New Properties
Four new
ImPlotSpecproperties have been added to enable per-index coloring:ImPlotProp_LineColors- Array ofImU32colors for line segments/verticesImPlotProp_FillColors- Array ofImU32colors for filled regionsImPlotProp_MarkerLineColors- Array ofImU32colors for marker outlinesImPlotProp_MarkerFillColors- Array ofImU32colors for marker fillsSupported Plot Types
Per-index colors are now supported in:
PlotLine)PlotShaded)PlotScatter)PlotBubble)PlotBars)PlotStairs)PlotStems)PlotInfLines)Usage Example
Constant Color (Existing Behavior)
The existing single-color properties continue to work as before:
Per-Index Colors (New Feature)
To use per-index colors, provide an array of
ImU32colors:Scatter Plot with Per-Marker Colors
Bar Plot with Per-Bar Colors
Implementation Details
Color Getter Architecture
The implementation uses a template-based color getter system:
GetterConstColor- Returns a constant color for all indices (used when single color is specified)GetterIdxColor- Returns per-index colors from an array (used when color array is specified)Both getters support alpha blending via a constructor parameter.
Backward Compatibility
All existing code continues to work without modification. The new per-index color properties are optional and only used when explicitly provided. When not specified, plots use the existing single-color properties (
ImPlotProp_LineColor,ImPlotProp_FillColor, etc.).Demo
A comprehensive "Per-Index Colors" demo has been added to
implot_demo.cppshowcasing:Run the demo to see all the colorful plot examples in action!
Testing
Notes
ImU32(useImGui::GetColorU32()orImColorto convert fromImVec4)FillAlphaproperty when applicable