implot.h 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  1. // MIT License
  2. // Copyright (c) 2021 Evan Pezent
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. // The above copyright notice and this permission notice shall be included in all
  10. // copies or substantial portions of the Software.
  11. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. // SOFTWARE.
  18. // ImPlot v0.11 WIP
  19. #pragma once
  20. #include "imgui.h"
  21. //-----------------------------------------------------------------------------
  22. // Macros and Defines
  23. //-----------------------------------------------------------------------------
  24. // Define attributes of all API symbols declarations (e.g. for DLL under Windows)
  25. // Using ImPlot via a shared library is not recommended, because we don't guarantee
  26. // backward nor forward ABI compatibility and also function call overhead. If you
  27. // do use ImPlot as a DLL, be sure to call SetImGuiContext (see Miscellanous section).
  28. #ifndef IMPLOT_API
  29. #define IMPLOT_API
  30. #endif
  31. // ImPlot version string
  32. #define IMPLOT_VERSION "0.11 WIP"
  33. // Indicates variable should deduced automatically.
  34. #define IMPLOT_AUTO -1
  35. // Special color used to indicate that a color should be deduced automatically.
  36. #define IMPLOT_AUTO_COL ImVec4(0,0,0,-1)
  37. //-----------------------------------------------------------------------------
  38. // Forward Declarations and Basic Types
  39. //-----------------------------------------------------------------------------
  40. // Forward declarations
  41. struct ImPlotContext; // ImPlot context (opaque struct, see implot_internal.h)
  42. // Enums/Flags
  43. typedef int ImPlotFlags; // -> enum ImPlotFlags_
  44. typedef int ImPlotAxisFlags; // -> enum ImPlotAxisFlags_
  45. typedef int ImPlotSubplotFlags; // -> enum ImPlotSubplotFlags_
  46. typedef int ImPlotCol; // -> enum ImPlotCol_
  47. typedef int ImPlotStyleVar; // -> enum ImPlotStyleVar_
  48. typedef int ImPlotMarker; // -> enum ImPlotMarker_
  49. typedef int ImPlotColormap; // -> enum ImPlotColormap_
  50. typedef int ImPlotLocation; // -> enum ImPlotLocation_
  51. typedef int ImPlotOrientation; // -> enum ImPlotOrientation_
  52. typedef int ImPlotYAxis; // -> enum ImPlotYAxis_;
  53. typedef int ImPlotBin; // -> enum ImPlotBin_
  54. // Options for plots (see BeginPlot).
  55. enum ImPlotFlags_ {
  56. ImPlotFlags_None = 0, // default
  57. ImPlotFlags_NoTitle = 1 << 0, // the plot title will not be displayed (titles are also hidden if preceeded by double hashes, e.g. "##MyPlot")
  58. ImPlotFlags_NoLegend = 1 << 1, // the legend will not be displayed
  59. ImPlotFlags_NoMenus = 1 << 2, // the user will not be able to open context menus with right-click
  60. ImPlotFlags_NoBoxSelect = 1 << 3, // the user will not be able to box-select with right-click drag
  61. ImPlotFlags_NoMousePos = 1 << 4, // the mouse position, in plot coordinates, will not be displayed inside of the plot
  62. ImPlotFlags_NoHighlight = 1 << 5, // plot items will not be highlighted when their legend entry is hovered
  63. ImPlotFlags_NoChild = 1 << 6, // a child window region will not be used to capture mouse scroll (can boost performance for single ImGui window applications)
  64. ImPlotFlags_Equal = 1 << 7, // primary x and y axes will be constrained to have the same units/pixel (does not apply to auxiliary y-axes)
  65. ImPlotFlags_YAxis2 = 1 << 8, // enable a 2nd y-axis on the right side
  66. ImPlotFlags_YAxis3 = 1 << 9, // enable a 3rd y-axis on the right side
  67. ImPlotFlags_Query = 1 << 10, // the user will be able to draw query rects with middle-mouse or CTRL + right-click drag
  68. ImPlotFlags_Crosshairs = 1 << 11, // the default mouse cursor will be replaced with a crosshair when hovered
  69. ImPlotFlags_AntiAliased = 1 << 12, // plot lines will be software anti-aliased (not recommended for high density plots, prefer MSAA)
  70. ImPlotFlags_CanvasOnly = ImPlotFlags_NoTitle | ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMousePos
  71. };
  72. // Options for plot axes (see BeginPlot).
  73. enum ImPlotAxisFlags_ {
  74. ImPlotAxisFlags_None = 0, // default
  75. ImPlotAxisFlags_NoLabel = 1 << 0, // the axis label will not be displayed (axis labels also hidden if the supplied string name is NULL)
  76. ImPlotAxisFlags_NoGridLines = 1 << 1, // no grid lines will be displayed
  77. ImPlotAxisFlags_NoTickMarks = 1 << 2, // no tick marks will be displayed
  78. ImPlotAxisFlags_NoTickLabels = 1 << 3, // no text labels will be displayed
  79. ImPlotAxisFlags_Foreground = 1 << 4, // grid lines will be displayed in the foreground (i.e. on top of data) in stead of the background
  80. ImPlotAxisFlags_LogScale = 1 << 5, // a logartithmic (base 10) axis scale will be used (mutually exclusive with ImPlotAxisFlags_Time)
  81. ImPlotAxisFlags_Time = 1 << 6, // axis will display date/time formatted labels (mutually exclusive with ImPlotAxisFlags_LogScale)
  82. ImPlotAxisFlags_Invert = 1 << 7, // the axis will be inverted
  83. ImPlotAxisFlags_NoInitialFit = 1 << 8, // axis will not be initially fit to data extents on the first rendered frame (also the case if SetNextPlotLimits explicitly called)
  84. ImPlotAxisFlags_AutoFit = 1 << 9, // axis will be auto-fitting to data extents
  85. ImPlotAxisFlags_RangeFit = 1 << 10, // axis will only fit points if the point is in the visible range of the **orthoganol** axis
  86. ImPlotAxisFlags_LockMin = 1 << 11, // the axis minimum value will be locked when panning/zooming
  87. ImPlotAxisFlags_LockMax = 1 << 12, // the axis maximum value will be locked when panning/zooming
  88. ImPlotAxisFlags_Lock = ImPlotAxisFlags_LockMin | ImPlotAxisFlags_LockMax,
  89. ImPlotAxisFlags_NoDecorations = ImPlotAxisFlags_NoLabel | ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_NoTickMarks | ImPlotAxisFlags_NoTickLabels
  90. };
  91. // Options for subplots (see BeginSubplot).
  92. enum ImPlotSubplotFlags_ {
  93. ImPlotSubplotFlags_None = 0, // default
  94. ImPlotSubplotFlags_NoTitle = 1 << 0, // the subplot title will not be displayed (titles are also hidden if preceeded by double hashes, e.g. "##MySubplot")
  95. ImPlotSubplotFlags_NoLegend = 1 << 1, // the legend will not be displayed (only applicable if ImPlotSubplotFlags_ShareItems is enabled)
  96. ImPlotSubplotFlags_NoMenus = 1 << 2, // the user will not be able to open context menus with right-click
  97. ImPlotSubplotFlags_NoResize = 1 << 3, // resize splitters between subplot cells will be not be provided
  98. ImPlotSubplotFlags_NoAlign = 1 << 4, // subplot edges will not be aligned vertically or horizontally
  99. ImPlotSubplotFlags_ShareItems = 1 << 5, // items across all subplots will be shared and rendered into a single legend entry
  100. ImPlotSubplotFlags_LinkRows = 1 << 6, // link the y-axis limits of all plots in each row (does not apply auxiliary y-axes)
  101. ImPlotSubplotFlags_LinkCols = 1 << 7, // link the x-axis limits of all plots in each column
  102. ImPlotSubplotFlags_LinkAllX = 1 << 8, // link the x-axis limits in every plot in the subplot
  103. ImPlotSubplotFlags_LinkAllY = 1 << 9 , // link the y-axis limits in every plot in the subplot (does not apply to auxiliary y-axes)
  104. ImPlotSubplotFlags_ColMajor = 1 << 10 // subplots are added in column major order instead of the default row major order
  105. };
  106. // Plot styling colors.
  107. enum ImPlotCol_ {
  108. // item styling colors
  109. ImPlotCol_Line, // plot line/outline color (defaults to next unused color in current colormap)
  110. ImPlotCol_Fill, // plot fill color for bars (defaults to the current line color)
  111. ImPlotCol_MarkerOutline, // marker outline color (defaults to the current line color)
  112. ImPlotCol_MarkerFill, // marker fill color (defaults to the current line color)
  113. ImPlotCol_ErrorBar, // error bar color (defaults to ImGuiCol_Text)
  114. // plot styling colors
  115. ImPlotCol_FrameBg, // plot frame background color (defaults to ImGuiCol_FrameBg)
  116. ImPlotCol_PlotBg, // plot area background color (defaults to ImGuiCol_WindowBg)
  117. ImPlotCol_PlotBorder, // plot area border color (defaults to ImGuiCol_Border)
  118. ImPlotCol_LegendBg, // legend background color (defaults to ImGuiCol_PopupBg)
  119. ImPlotCol_LegendBorder, // legend border color (defaults to ImPlotCol_PlotBorder)
  120. ImPlotCol_LegendText, // legend text color (defaults to ImPlotCol_InlayText)
  121. ImPlotCol_TitleText, // plot title text color (defaults to ImGuiCol_Text)
  122. ImPlotCol_InlayText, // color of text appearing inside of plots (defaults to ImGuiCol_Text)
  123. ImPlotCol_XAxis, // x-axis label and tick lables color (defaults to ImGuiCol_Text)
  124. ImPlotCol_XAxisGrid, // x-axis grid color (defaults to 25% ImPlotCol_XAxis)
  125. ImPlotCol_YAxis, // y-axis label and tick labels color (defaults to ImGuiCol_Text)
  126. ImPlotCol_YAxisGrid, // y-axis grid color (defaults to 25% ImPlotCol_YAxis)
  127. ImPlotCol_YAxis2, // 2nd y-axis label and tick labels color (defaults to ImGuiCol_Text)
  128. ImPlotCol_YAxisGrid2, // 2nd y-axis grid/label color (defaults to 25% ImPlotCol_YAxis2)
  129. ImPlotCol_YAxis3, // 3rd y-axis label and tick labels color (defaults to ImGuiCol_Text)
  130. ImPlotCol_YAxisGrid3, // 3rd y-axis grid/label color (defaults to 25% ImPlotCol_YAxis3)
  131. ImPlotCol_Selection, // box-selection color (defaults to yellow)
  132. ImPlotCol_Query, // box-query color (defaults to green)
  133. ImPlotCol_Crosshairs, // crosshairs color (defaults to ImPlotCol_PlotBorder)
  134. ImPlotCol_COUNT
  135. };
  136. // Plot styling variables.
  137. enum ImPlotStyleVar_ {
  138. // item styling variables
  139. ImPlotStyleVar_LineWeight, // float, plot item line weight in pixels
  140. ImPlotStyleVar_Marker, // int, marker specification
  141. ImPlotStyleVar_MarkerSize, // float, marker size in pixels (roughly the marker's "radius")
  142. ImPlotStyleVar_MarkerWeight, // float, plot outline weight of markers in pixels
  143. ImPlotStyleVar_FillAlpha, // float, alpha modifier applied to all plot item fills
  144. ImPlotStyleVar_ErrorBarSize, // float, error bar whisker width in pixels
  145. ImPlotStyleVar_ErrorBarWeight, // float, error bar whisker weight in pixels
  146. ImPlotStyleVar_DigitalBitHeight, // float, digital channels bit height (at 1) in pixels
  147. ImPlotStyleVar_DigitalBitGap, // float, digital channels bit padding gap in pixels
  148. // plot styling variables
  149. ImPlotStyleVar_PlotBorderSize, // float, thickness of border around plot area
  150. ImPlotStyleVar_MinorAlpha, // float, alpha multiplier applied to minor axis grid lines
  151. ImPlotStyleVar_MajorTickLen, // ImVec2, major tick lengths for X and Y axes
  152. ImPlotStyleVar_MinorTickLen, // ImVec2, minor tick lengths for X and Y axes
  153. ImPlotStyleVar_MajorTickSize, // ImVec2, line thickness of major ticks
  154. ImPlotStyleVar_MinorTickSize, // ImVec2, line thickness of minor ticks
  155. ImPlotStyleVar_MajorGridSize, // ImVec2, line thickness of major grid lines
  156. ImPlotStyleVar_MinorGridSize, // ImVec2, line thickness of minor grid lines
  157. ImPlotStyleVar_PlotPadding, // ImVec2, padding between widget frame and plot area, labels, or outside legends (i.e. main padding)
  158. ImPlotStyleVar_LabelPadding, // ImVec2, padding between axes labels, tick labels, and plot edge
  159. ImPlotStyleVar_LegendPadding, // ImVec2, legend padding from plot edges
  160. ImPlotStyleVar_LegendInnerPadding, // ImVec2, legend inner padding from legend edges
  161. ImPlotStyleVar_LegendSpacing, // ImVec2, spacing between legend entries
  162. ImPlotStyleVar_MousePosPadding, // ImVec2, padding between plot edge and interior info text
  163. ImPlotStyleVar_AnnotationPadding, // ImVec2, text padding around annotation labels
  164. ImPlotStyleVar_FitPadding, // ImVec2, additional fit padding as a percentage of the fit extents (e.g. ImVec2(0.1f,0.1f) adds 10% to the fit extents of X and Y)
  165. ImPlotStyleVar_PlotDefaultSize, // ImVec2, default size used when ImVec2(0,0) is passed to BeginPlot
  166. ImPlotStyleVar_PlotMinSize, // ImVec2, minimum size plot frame can be when shrunk
  167. ImPlotStyleVar_COUNT
  168. };
  169. // Marker specifications.
  170. enum ImPlotMarker_ {
  171. ImPlotMarker_None = -1, // no marker
  172. ImPlotMarker_Circle, // a circle marker
  173. ImPlotMarker_Square, // a square maker
  174. ImPlotMarker_Diamond, // a diamond marker
  175. ImPlotMarker_Up, // an upward-pointing triangle marker
  176. ImPlotMarker_Down, // an downward-pointing triangle marker
  177. ImPlotMarker_Left, // an leftward-pointing triangle marker
  178. ImPlotMarker_Right, // an rightward-pointing triangle marker
  179. ImPlotMarker_Cross, // a cross marker (not fillable)
  180. ImPlotMarker_Plus, // a plus marker (not fillable)
  181. ImPlotMarker_Asterisk, // a asterisk marker (not fillable)
  182. ImPlotMarker_COUNT
  183. };
  184. // Built-in colormaps
  185. enum ImPlotColormap_ {
  186. ImPlotColormap_Deep = 0, // a.k.a. seaborn deep (qual=true, n=10) (default)
  187. ImPlotColormap_Dark = 1, // a.k.a. matplotlib "Set1" (qual=true, n=9 )
  188. ImPlotColormap_Pastel = 2, // a.k.a. matplotlib "Pastel1" (qual=true, n=9 )
  189. ImPlotColormap_Paired = 3, // a.k.a. matplotlib "Paired" (qual=true, n=12)
  190. ImPlotColormap_Viridis = 4, // a.k.a. matplotlib "viridis" (qual=false, n=11)
  191. ImPlotColormap_Plasma = 5, // a.k.a. matplotlib "plasma" (qual=false, n=11)
  192. ImPlotColormap_Hot = 6, // a.k.a. matplotlib/MATLAB "hot" (qual=false, n=11)
  193. ImPlotColormap_Cool = 7, // a.k.a. matplotlib/MATLAB "cool" (qual=false, n=11)
  194. ImPlotColormap_Pink = 8, // a.k.a. matplotlib/MATLAB "pink" (qual=false, n=11)
  195. ImPlotColormap_Jet = 9, // a.k.a. MATLAB "jet" (qual=false, n=11)
  196. ImPlotColormap_Twilight = 10, // a.k.a. matplotlib "twilight" (qual=false, n=11)
  197. ImPlotColormap_RdBu = 11, // red/blue, Color Brewer (qual=false, n=11)
  198. ImPlotColormap_BrBG = 12, // brown/blue-green, Color Brewer (qual=false, n=11)
  199. ImPlotColormap_PiYG = 13, // pink/yellow-green, Color Brewer (qual=false, n=11)
  200. ImPlotColormap_Spectral = 14, // color spectrum, Color Brewer (qual=false, n=11)
  201. ImPlotColormap_Greys = 15, // white/black (qual=false, n=2 )
  202. };
  203. // Used to position items on a plot (e.g. legends, labels, etc.)
  204. enum ImPlotLocation_ {
  205. ImPlotLocation_Center = 0, // center-center
  206. ImPlotLocation_North = 1 << 0, // top-center
  207. ImPlotLocation_South = 1 << 1, // bottom-center
  208. ImPlotLocation_West = 1 << 2, // center-left
  209. ImPlotLocation_East = 1 << 3, // center-right
  210. ImPlotLocation_NorthWest = ImPlotLocation_North | ImPlotLocation_West, // top-left
  211. ImPlotLocation_NorthEast = ImPlotLocation_North | ImPlotLocation_East, // top-right
  212. ImPlotLocation_SouthWest = ImPlotLocation_South | ImPlotLocation_West, // bottom-left
  213. ImPlotLocation_SouthEast = ImPlotLocation_South | ImPlotLocation_East // bottom-right
  214. };
  215. // Used to orient items on a plot (e.g. legends, labels, etc.)
  216. enum ImPlotOrientation_ {
  217. ImPlotOrientation_Horizontal, // left/right
  218. ImPlotOrientation_Vertical // up/down
  219. };
  220. // Enums for different y-axes.
  221. enum ImPlotYAxis_ {
  222. ImPlotYAxis_1 = 0, // left (default)
  223. ImPlotYAxis_2 = 1, // first on right side
  224. ImPlotYAxis_3 = 2 // second on right side
  225. };
  226. // Enums for different automatic histogram binning methods (k = bin count or w = bin width)
  227. enum ImPlotBin_ {
  228. ImPlotBin_Sqrt = -1, // k = sqrt(n)
  229. ImPlotBin_Sturges = -2, // k = 1 + log2(n)
  230. ImPlotBin_Rice = -3, // k = 2 * cbrt(n)
  231. ImPlotBin_Scott = -4, // w = 3.49 * sigma / cbrt(n)
  232. };
  233. // Double precision version of ImVec2 used by ImPlot. Extensible by end users.
  234. struct ImPlotPoint {
  235. double x, y;
  236. ImPlotPoint() { x = y = 0.0; }
  237. ImPlotPoint(double _x, double _y) { x = _x; y = _y; }
  238. ImPlotPoint(const ImVec2& p) { x = p.x; y = p.y; }
  239. double operator[] (size_t idx) const { return (&x)[idx]; }
  240. double& operator[] (size_t idx) { return (&x)[idx]; }
  241. #ifdef IMPLOT_POINT_CLASS_EXTRA
  242. IMPLOT_POINT_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h
  243. // to convert back and forth between your math types and ImPlotPoint.
  244. #endif
  245. };
  246. // A range defined by a min/max value. Used for plot axes ranges.
  247. struct ImPlotRange {
  248. double Min, Max;
  249. ImPlotRange() { Min = 0; Max = 0; }
  250. ImPlotRange(double _min, double _max) { Min = _min; Max = _max; }
  251. bool Contains(double value) const { return value >= Min && value <= Max; };
  252. double Size() const { return Max - Min; };
  253. };
  254. // Combination of two ranges for X and Y axes.
  255. struct ImPlotLimits {
  256. ImPlotRange X, Y;
  257. ImPlotLimits() { }
  258. ImPlotLimits(double x_min, double x_max, double y_min, double y_max) { X.Min = x_min; X.Max = x_max; Y.Min = y_min; Y.Max = y_max; }
  259. bool Contains(const ImPlotPoint& p) const { return Contains(p.x, p.y); }
  260. bool Contains(double x, double y) const { return X.Contains(x) && Y.Contains(y); }
  261. ImPlotPoint Min() const { return ImPlotPoint(X.Min, Y.Min); }
  262. ImPlotPoint Max() const { return ImPlotPoint(X.Max, Y.Max); }
  263. };
  264. // Plot style structure
  265. struct ImPlotStyle {
  266. // item styling variables
  267. float LineWeight; // = 1, item line weight in pixels
  268. int Marker; // = ImPlotMarker_None, marker specification
  269. float MarkerSize; // = 4, marker size in pixels (roughly the marker's "radius")
  270. float MarkerWeight; // = 1, outline weight of markers in pixels
  271. float FillAlpha; // = 1, alpha modifier applied to plot fills
  272. float ErrorBarSize; // = 5, error bar whisker width in pixels
  273. float ErrorBarWeight; // = 1.5, error bar whisker weight in pixels
  274. float DigitalBitHeight; // = 8, digital channels bit height (at y = 1.0f) in pixels
  275. float DigitalBitGap; // = 4, digital channels bit padding gap in pixels
  276. // plot styling variables
  277. float PlotBorderSize; // = 1, line thickness of border around plot area
  278. float MinorAlpha; // = 0.25 alpha multiplier applied to minor axis grid lines
  279. ImVec2 MajorTickLen; // = 10,10 major tick lengths for X and Y axes
  280. ImVec2 MinorTickLen; // = 5,5 minor tick lengths for X and Y axes
  281. ImVec2 MajorTickSize; // = 1,1 line thickness of major ticks
  282. ImVec2 MinorTickSize; // = 1,1 line thickness of minor ticks
  283. ImVec2 MajorGridSize; // = 1,1 line thickness of major grid lines
  284. ImVec2 MinorGridSize; // = 1,1 line thickness of minor grid lines
  285. ImVec2 PlotPadding; // = 10,10 padding between widget frame and plot area, labels, or outside legends (i.e. main padding)
  286. ImVec2 LabelPadding; // = 5,5 padding between axes labels, tick labels, and plot edge
  287. ImVec2 LegendPadding; // = 10,10 legend padding from plot edges
  288. ImVec2 LegendInnerPadding; // = 5,5 legend inner padding from legend edges
  289. ImVec2 LegendSpacing; // = 5,0 spacing between legend entries
  290. ImVec2 MousePosPadding; // = 10,10 padding between plot edge and interior mouse location text
  291. ImVec2 AnnotationPadding; // = 2,2 text padding around annotation labels
  292. ImVec2 FitPadding; // = 0,0 additional fit padding as a percentage of the fit extents (e.g. ImVec2(0.1f,0.1f) adds 10% to the fit extents of X and Y)
  293. ImVec2 PlotDefaultSize; // = 400,300 default size used when ImVec2(0,0) is passed to BeginPlot
  294. ImVec2 PlotMinSize; // = 200,150 minimum size plot frame can be when shrunk
  295. // style colors
  296. ImVec4 Colors[ImPlotCol_COUNT]; // Array of styling colors. Indexable with ImPlotCol_ enums.
  297. // colormap
  298. ImPlotColormap Colormap; // The current colormap. Set this to either an ImPlotColormap_ enum or an index returned by AddColormap.
  299. // settings/flags
  300. bool AntiAliasedLines; // = false, enable global anti-aliasing on plot lines (overrides ImPlotFlags_AntiAliased)
  301. bool UseLocalTime; // = false, axis labels will be formatted for your timezone when ImPlotAxisFlag_Time is enabled
  302. bool UseISO8601; // = false, dates will be formatted according to ISO 8601 where applicable (e.g. YYYY-MM-DD, YYYY-MM, --MM-DD, etc.)
  303. bool Use24HourClock; // = false, times will be formatted using a 24 hour clock
  304. IMPLOT_API ImPlotStyle();
  305. };
  306. //-----------------------------------------------------------------------------
  307. // ImPlot End-User API
  308. //-----------------------------------------------------------------------------
  309. namespace ImPlot {
  310. //-----------------------------------------------------------------------------
  311. // ImPlot Context
  312. //-----------------------------------------------------------------------------
  313. // Creates a new ImPlot context. Call this after ImGui::CreateContext.
  314. IMPLOT_API ImPlotContext* CreateContext();
  315. // Destroys an ImPlot context. Call this before ImGui::DestroyContext. NULL = destroy current context.
  316. IMPLOT_API void DestroyContext(ImPlotContext* ctx = NULL);
  317. // Returns the current ImPlot context. NULL if no context has ben set.
  318. IMPLOT_API ImPlotContext* GetCurrentContext();
  319. // Sets the current ImPlot context.
  320. IMPLOT_API void SetCurrentContext(ImPlotContext* ctx);
  321. // Sets the current **ImGui** context. This is ONLY necessary if you are compiling
  322. // ImPlot as a DLL (not recommended) separate from your ImGui compilation. It
  323. // sets the global variable GImGui, which is not shared across DLL boundaries.
  324. // See GImGui documentation in imgui.cpp for more details.
  325. IMPLOT_API void SetImGuiContext(ImGuiContext* ctx);
  326. //-----------------------------------------------------------------------------
  327. // Begin/End Plot
  328. //-----------------------------------------------------------------------------
  329. // Starts a 2D plotting context. If this function returns true, EndPlot() MUST
  330. // be called! You are encouraged to use the following convention:
  331. //
  332. // if (BeginPlot(...)) {
  333. // ImPlot::PlotLine(...);
  334. // ...
  335. // EndPlot();
  336. // }
  337. //
  338. // Important notes:
  339. //
  340. // - #title_id must be unique to the current ImGui ID scope. If you need to avoid ID
  341. // collisions or don't want to display a title in the plot, use double hashes
  342. // (e.g. "MyPlot##HiddenIdText" or "##NoTitle").
  343. // - If #x_label and/or #y_label are provided, axes labels will be displayed.
  344. // - #size is the **frame** size of the plot widget, not the plot area. The default
  345. // size of plots (i.e. when ImVec2(0,0)) can be modified in your ImPlotStyle
  346. // (default is 400x300 px).
  347. // - Auxiliary y-axes must be enabled with ImPlotFlags_YAxis2/3 to be displayed.
  348. // - See ImPlotFlags and ImPlotAxisFlags for more available options.
  349. IMPLOT_API bool BeginPlot(const char* title_id,
  350. const char* x_label = NULL,
  351. const char* y_label = NULL,
  352. const ImVec2& size = ImVec2(-1,0),
  353. ImPlotFlags flags = ImPlotFlags_None,
  354. ImPlotAxisFlags x_flags = ImPlotAxisFlags_None,
  355. ImPlotAxisFlags y_flags = ImPlotAxisFlags_None,
  356. ImPlotAxisFlags y2_flags = ImPlotAxisFlags_NoGridLines,
  357. ImPlotAxisFlags y3_flags = ImPlotAxisFlags_NoGridLines,
  358. const char* y2_label = NULL,
  359. const char* y3_label = NULL);
  360. // Only call EndPlot() if BeginPlot() returns true! Typically called at the end
  361. // of an if statement conditioned on BeginPlot(). See example above.
  362. IMPLOT_API void EndPlot();
  363. //-----------------------------------------------------------------------------
  364. // Begin/EndSubplots
  365. //-----------------------------------------------------------------------------
  366. // Starts a subdivided plotting context. If the function returns true,
  367. // EndSubplots() MUST be called! Call BeginPlot/EndPlot AT MOST [rows*cols]
  368. // times in between the begining and end of the subplot context. Plots are
  369. // added in row major order.
  370. //
  371. // Example:
  372. //
  373. // if (BeginSubplots("My Subplot",2,3,ImVec2(800,400)) {
  374. // for (int i = 0; i < 6; ++i) {
  375. // if (BeginPlot(...)) {
  376. // ImPlot::PlotLine(...);
  377. // ...
  378. // EndPlot();
  379. // }
  380. // }
  381. // EndSubplots();
  382. // }
  383. //
  384. // Procudes:
  385. //
  386. // [0][1][2]
  387. // [3][4][5]
  388. //
  389. // Important notes:
  390. //
  391. // - #title_id must be unique to the current ImGui ID scope. If you need to avoid ID
  392. // collisions or don't want to display a title in the plot, use double hashes
  393. // (e.g. "MyPlot##HiddenIdText" or "##NoTitle").
  394. // - #rows and #cols must be greater than 0.
  395. // - #size is the size of the entire grid of subplots, not the individual plots
  396. // - #row_ratios and #col_ratios must have AT LEAST #rows and #cols elements,
  397. // respectively. These are the sizes of the rows and columns expressed in ratios.
  398. // If the user adjusts the dimensions, the arrays are updated with new ratios.
  399. //
  400. // Important notes regarding BeginPlot from inside of BeginSubplots:
  401. //
  402. // - The #title_id parameter of _BeginPlot_ (see above) does NOT have to be
  403. // unique when called inside of a subplot context. Subplot IDs are hashed
  404. // for your convenience so you don't have call PushID or generate unique title
  405. // strings. Simply pass an empty string to BeginPlot unless you want to title
  406. // each subplot.
  407. // - The #size parameter of _BeginPlot_ (see above) is ignored when inside of a
  408. // subplot context. The actual size of the subplot will be based on the
  409. // #size value you pass to _BeginSubplots_ and #row/#col_ratios if provided.
  410. IMPLOT_API bool BeginSubplots(const char* title_id,
  411. int rows,
  412. int cols,
  413. const ImVec2& size,
  414. ImPlotSubplotFlags flags = ImPlotSubplotFlags_None,
  415. float* row_ratios = NULL,
  416. float* col_ratios = NULL);
  417. // Only call EndSubplots() if BeginSubplots() returns true! Typically called at the end
  418. // of an if statement conditioned on BeginSublots(). See example above.
  419. IMPLOT_API void EndSubplots();
  420. //-----------------------------------------------------------------------------
  421. // Plot Items
  422. //-----------------------------------------------------------------------------
  423. // The template functions below are explicitly instantiated in implot_items.cpp.
  424. // They are not intended to be used generically with custom types. You will get
  425. // a linker error if you try! All functions support the following scalar types:
  426. //
  427. // float, double, ImS8, ImU8, ImS16, ImU16, ImS32, ImU32, ImS64, ImU64
  428. //
  429. //
  430. // If you need to plot custom or non-homogenous data you have a few options:
  431. //
  432. // 1. If your data is a simple struct/class (e.g. Vector2f), you can use striding.
  433. // This is the most performant option if applicable.
  434. //
  435. // struct Vector2f { float X, Y; };
  436. // ...
  437. // Vector2f data[42];
  438. // ImPlot::PlotLine("line", &data[0].x, &data[0].y, 42, 0, sizeof(Vector2f)); // or sizeof(float)*2
  439. //
  440. // 2. Write a custom getter C function or C++ lambda and pass it and optionally your data to
  441. // an ImPlot function post-fixed with a G (e.g. PlotScatterG). This has a slight performance
  442. // cost, but probably not enough to worry about unless your data is very large. Examples:
  443. //
  444. // ImPlotPoint MyDataGetter(void* data, int idx) {
  445. // MyData* my_data = (MyData*)data;
  446. // ImPlotPoint p;
  447. // p.x = my_data->GetTime(idx);
  448. // p.y = my_data->GetValue(idx);
  449. // return p
  450. // }
  451. // ...
  452. // auto my_lambda = [](void*, int idx) {
  453. // double t = idx / 999.0;
  454. // return ImPlotPoint(t, 0.5+0.5*std::sin(2*PI*10*t));
  455. // };
  456. // ...
  457. // if (ImPlot::BeginPlot("MyPlot")) {
  458. // MyData my_data;
  459. // ImPlot::PlotScatterG("scatter", MyDataGetter, &my_data, my_data.Size());
  460. // ImPlot::PlotLineG("line", my_lambda, nullptr, 1000);
  461. // ImPlot::EndPlot();
  462. // }
  463. //
  464. // NB: All types are converted to double before plotting. You may lose information
  465. // if you try plotting extremely large 64-bit integral types. Proceed with caution!
  466. // Plots a standard 2D line plot.
  467. template <typename T> IMPLOT_API void PlotLine(const char* label_id, const T* values, int count, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T));
  468. template <typename T> IMPLOT_API void PlotLine(const char* label_id, const T* xs, const T* ys, int count, int offset=0, int stride=sizeof(T));
  469. IMPLOT_API void PlotLineG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset=0);
  470. // Plots a standard 2D scatter plot. Default marker is ImPlotMarker_Circle.
  471. template <typename T> IMPLOT_API void PlotScatter(const char* label_id, const T* values, int count, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T));
  472. template <typename T> IMPLOT_API void PlotScatter(const char* label_id, const T* xs, const T* ys, int count, int offset=0, int stride=sizeof(T));
  473. IMPLOT_API void PlotScatterG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset=0);
  474. // Plots a a stairstep graph. The y value is continued constantly from every x position, i.e. the interval [x[i], x[i+1]) has the value y[i].
  475. template <typename T> IMPLOT_API void PlotStairs(const char* label_id, const T* values, int count, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T));
  476. template <typename T> IMPLOT_API void PlotStairs(const char* label_id, const T* xs, const T* ys, int count, int offset=0, int stride=sizeof(T));
  477. IMPLOT_API void PlotStairsG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset=0);
  478. // Plots a shaded (filled) region between two lines, or a line and a horizontal reference. Set y_ref to +/-INFINITY for infinite fill extents.
  479. template <typename T> IMPLOT_API void PlotShaded(const char* label_id, const T* values, int count, double y_ref=0, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T));
  480. template <typename T> IMPLOT_API void PlotShaded(const char* label_id, const T* xs, const T* ys, int count, double y_ref=0, int offset=0, int stride=sizeof(T));
  481. template <typename T> IMPLOT_API void PlotShaded(const char* label_id, const T* xs, const T* ys1, const T* ys2, int count, int offset=0, int stride=sizeof(T));
  482. IMPLOT_API void PlotShadedG(const char* label_id, ImPlotPoint (*getter1)(void* data, int idx), void* data1, ImPlotPoint (*getter2)(void* data, int idx), void* data2, int count, int offset=0);
  483. // Plots a vertical bar graph. #width and #shift are in X units.
  484. template <typename T> IMPLOT_API void PlotBars(const char* label_id, const T* values, int count, double width=0.67, double shift=0, int offset=0, int stride=sizeof(T));
  485. template <typename T> IMPLOT_API void PlotBars(const char* label_id, const T* xs, const T* ys, int count, double width, int offset=0, int stride=sizeof(T));
  486. IMPLOT_API void PlotBarsG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, double width, int offset=0);
  487. // Plots a horizontal bar graph. #height and #shift are in Y units.
  488. template <typename T> IMPLOT_API void PlotBarsH(const char* label_id, const T* values, int count, double height=0.67, double shift=0, int offset=0, int stride=sizeof(T));
  489. template <typename T> IMPLOT_API void PlotBarsH(const char* label_id, const T* xs, const T* ys, int count, double height, int offset=0, int stride=sizeof(T));
  490. IMPLOT_API void PlotBarsHG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, double height, int offset=0);
  491. // Plots vertical error bar. The label_id should be the same as the label_id of the associated line or bar plot.
  492. template <typename T> IMPLOT_API void PlotErrorBars(const char* label_id, const T* xs, const T* ys, const T* err, int count, int offset=0, int stride=sizeof(T));
  493. template <typename T> IMPLOT_API void PlotErrorBars(const char* label_id, const T* xs, const T* ys, const T* neg, const T* pos, int count, int offset=0, int stride=sizeof(T));
  494. // Plots horizontal error bars. The label_id should be the same as the label_id of the associated line or bar plot.
  495. template <typename T> IMPLOT_API void PlotErrorBarsH(const char* label_id, const T* xs, const T* ys, const T* err, int count, int offset=0, int stride=sizeof(T));
  496. template <typename T> IMPLOT_API void PlotErrorBarsH(const char* label_id, const T* xs, const T* ys, const T* neg, const T* pos, int count, int offset=0, int stride=sizeof(T));
  497. /// Plots vertical stems.
  498. template <typename T> IMPLOT_API void PlotStems(const char* label_id, const T* values, int count, double y_ref=0, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T));
  499. template <typename T> IMPLOT_API void PlotStems(const char* label_id, const T* xs, const T* ys, int count, double y_ref=0, int offset=0, int stride=sizeof(T));
  500. /// Plots infinite vertical or horizontal lines (e.g. for references or asymptotes).
  501. template <typename T> IMPLOT_API void PlotVLines(const char* label_id, const T* xs, int count, int offset=0, int stride=sizeof(T));
  502. template <typename T> IMPLOT_API void PlotHLines(const char* label_id, const T* ys, int count, int offset=0, int stride=sizeof(T));
  503. // Plots a pie chart. If the sum of values > 1 or normalize is true, each value will be normalized. Center and radius are in plot units. #label_fmt can be set to NULL for no labels.
  504. template <typename T> IMPLOT_API void PlotPieChart(const char* const label_ids[], const T* values, int count, double x, double y, double radius, bool normalize=false, const char* label_fmt="%.1f", double angle0=90);
  505. // Plots a 2D heatmap chart. Values are expected to be in row-major order. Leave #scale_min and scale_max both at 0 for automatic color scaling, or set them to a predefined range. #label_fmt can be set to NULL for no labels.
  506. template <typename T> IMPLOT_API void PlotHeatmap(const char* label_id, const T* values, int rows, int cols, double scale_min=0, double scale_max=0, const char* label_fmt="%.1f", const ImPlotPoint& bounds_min=ImPlotPoint(0,0), const ImPlotPoint& bounds_max=ImPlotPoint(1,1));
  507. // Plots a horizontal histogram. #bins can be a positive integer or an ImPlotBin_ method. If #cumulative is true, each bin contains its count plus the counts of all previous bins.
  508. // If #density is true, the PDF is visualized. If both are true, the CDF is visualized. If #range is left unspecified, the min/max of #values will be used as the range.
  509. // If #range is specified, outlier values outside of the range are not binned. However, outliers still count toward normalizing and cumulative counts unless #outliers is false. The largest bin count or density is returned.
  510. template <typename T> IMPLOT_API double PlotHistogram(const char* label_id, const T* values, int count, int bins=ImPlotBin_Sturges, bool cumulative=false, bool density=false, ImPlotRange range=ImPlotRange(), bool outliers=true, double bar_scale=1.0);
  511. // Plots two dimensional, bivariate histogram as a heatmap. #x_bins and #y_bins can be a positive integer or an ImPlotBin. If #density is true, the PDF is visualized.
  512. // If #range is left unspecified, the min/max of #xs an #ys will be used as the ranges. If #range is specified, outlier values outside of range are not binned.
  513. // However, outliers still count toward the normalizing count for density plots unless #outliers is false. The largest bin count or density is returned.
  514. template <typename T> IMPLOT_API double PlotHistogram2D(const char* label_id, const T* xs, const T* ys, int count, int x_bins=ImPlotBin_Sturges, int y_bins=ImPlotBin_Sturges, bool density=false, ImPlotLimits range=ImPlotLimits(), bool outliers=true);
  515. // Plots digital data. Digital plots do not respond to y drag or zoom, and are always referenced to the bottom of the plot.
  516. template <typename T> IMPLOT_API void PlotDigital(const char* label_id, const T* xs, const T* ys, int count, int offset=0, int stride=sizeof(T));
  517. IMPLOT_API void PlotDigitalG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset=0);
  518. // Plots an axis-aligned image. #bounds_min/bounds_max are in plot coordinates (y-up) and #uv0/uv1 are in texture coordinates (y-down).
  519. IMPLOT_API void PlotImage(const char* label_id, ImTextureID user_texture_id, const ImPlotPoint& bounds_min, const ImPlotPoint& bounds_max, const ImVec2& uv0=ImVec2(0,0), const ImVec2& uv1=ImVec2(1,1), const ImVec4& tint_col=ImVec4(1,1,1,1));
  520. // Plots a centered text label at point x,y with an optional pixel offset. Text color can be changed with ImPlot::PushStyleColor(ImPlotCol_InlayText, ...).
  521. IMPLOT_API void PlotText(const char* text, double x, double y, bool vertical=false, const ImVec2& pix_offset=ImVec2(0,0));
  522. // Plots a dummy item (i.e. adds a legend entry colored by ImPlotCol_Line)
  523. IMPLOT_API void PlotDummy(const char* label_id);
  524. //-----------------------------------------------------------------------------
  525. // Plot Utils
  526. //-----------------------------------------------------------------------------
  527. // The following functions MUST be called BEFORE BeginPlot!
  528. // Set the axes range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axes limits will be locked.
  529. IMPLOT_API void SetNextPlotLimits(double xmin, double xmax, double ymin, double ymax, ImGuiCond cond = ImGuiCond_Once);
  530. // Set the X axis range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the X axis limits will be locked.
  531. IMPLOT_API void SetNextPlotLimitsX(double xmin, double xmax, ImGuiCond cond = ImGuiCond_Once);
  532. // Set the Y axis range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the Y axis limits will be locked.
  533. IMPLOT_API void SetNextPlotLimitsY(double ymin, double ymax, ImGuiCond cond = ImGuiCond_Once, ImPlotYAxis y_axis = ImPlotYAxis_1);
  534. // Links the next plot limits to external values. Set to NULL for no linkage. The pointer data must remain valid until the matching call to EndPlot.
  535. IMPLOT_API void LinkNextPlotLimits(double* xmin, double* xmax, double* ymin, double* ymax, double* ymin2 = NULL, double* ymax2 = NULL, double* ymin3 = NULL, double* ymax3 = NULL);
  536. // Fits the next plot axes to all plotted data if they are unlocked (equivalent to double-clicks).
  537. IMPLOT_API void FitNextPlotAxes(bool x = true, bool y = true, bool y2 = true, bool y3 = true);
  538. // Set the X axis ticks and optionally the labels for the next plot. To keep the default ticks, set #keep_default=true.
  539. IMPLOT_API void SetNextPlotTicksX(const double* values, int n_ticks, const char* const labels[] = NULL, bool keep_default = false);
  540. IMPLOT_API void SetNextPlotTicksX(double x_min, double x_max, int n_ticks, const char* const labels[] = NULL, bool keep_default = false);
  541. // Set the Y axis ticks and optionally the labels for the next plot. To keep the default ticks, set #keep_default=true.
  542. IMPLOT_API void SetNextPlotTicksY(const double* values, int n_ticks, const char* const labels[] = NULL, bool keep_default = false, ImPlotYAxis y_axis = ImPlotYAxis_1);
  543. IMPLOT_API void SetNextPlotTicksY(double y_min, double y_max, int n_ticks, const char* const labels[] = NULL, bool keep_default = false, ImPlotYAxis y_axis = ImPlotYAxis_1);
  544. // Set the format for numeric X axis labels (default="%g"). Formated values will be doubles (i.e. don't supply %d, %i, etc.). Not applicable if ImPlotAxisFlags_Time enabled.
  545. IMPLOT_API void SetNextPlotFormatX(const char* fmt);
  546. // Set the format for numeric Y axis labels (default="%g"). Formated values will be doubles (i.e. don't supply %d, %i, etc.).
  547. IMPLOT_API void SetNextPlotFormatY(const char* fmt, ImPlotYAxis y_axis=ImPlotYAxis_1);
  548. // The following functions MUST be called BETWEEN Begin/EndPlot!
  549. // Select which Y axis will be used for subsequent plot elements. The default is ImPlotYAxis_1, or the first (left) Y axis. Enable 2nd and 3rd axes with ImPlotFlags_YAxisX.
  550. IMPLOT_API void SetPlotYAxis(ImPlotYAxis y_axis);
  551. // Hides or shows the next plot item (i.e. as if it were toggled from the legend). Use ImGuiCond_Always if you need to forcefully set this every frame.
  552. IMPLOT_API void HideNextItem(bool hidden = true, ImGuiCond cond = ImGuiCond_Once);
  553. // Convert pixels to a position in the current plot's coordinate system. A negative y_axis uses the current value of SetPlotYAxis (ImPlotYAxis_1 initially).
  554. IMPLOT_API ImPlotPoint PixelsToPlot(const ImVec2& pix, ImPlotYAxis y_axis = IMPLOT_AUTO);
  555. IMPLOT_API ImPlotPoint PixelsToPlot(float x, float y, ImPlotYAxis y_axis = IMPLOT_AUTO);
  556. // Convert a position in the current plot's coordinate system to pixels. A negative y_axis uses the current value of SetPlotYAxis (ImPlotYAxis_1 initially).
  557. IMPLOT_API ImVec2 PlotToPixels(const ImPlotPoint& plt, ImPlotYAxis y_axis = IMPLOT_AUTO);
  558. IMPLOT_API ImVec2 PlotToPixels(double x, double y, ImPlotYAxis y_axis = IMPLOT_AUTO);
  559. // Get the current Plot position (top-left) in pixels.
  560. IMPLOT_API ImVec2 GetPlotPos();
  561. // Get the curent Plot size in pixels.
  562. IMPLOT_API ImVec2 GetPlotSize();
  563. // Returns true if the plot area in the current plot is hovered.
  564. IMPLOT_API bool IsPlotHovered();
  565. // Returns true if the XAxis plot area in the current plot is hovered.
  566. IMPLOT_API bool IsPlotXAxisHovered();
  567. // Returns true if the YAxis[n] plot area in the current plot is hovered.
  568. IMPLOT_API bool IsPlotYAxisHovered(ImPlotYAxis y_axis = 0);
  569. // Returns the mouse position in x,y coordinates of the current plot. A negative y_axis uses the current value of SetPlotYAxis (ImPlotYAxis_1 initially).
  570. IMPLOT_API ImPlotPoint GetPlotMousePos(ImPlotYAxis y_axis = IMPLOT_AUTO);
  571. // Returns the current plot axis range. A negative y_axis uses the current value of SetPlotYAxis (ImPlotYAxis_1 initially).
  572. IMPLOT_API ImPlotLimits GetPlotLimits(ImPlotYAxis y_axis = IMPLOT_AUTO);
  573. // Returns true if the current plot is being box selected.
  574. IMPLOT_API bool IsPlotSelected();
  575. // Returns the current plot box selection bounds.
  576. IMPLOT_API ImPlotLimits GetPlotSelection(ImPlotYAxis y_axis = IMPLOT_AUTO);
  577. // Returns true if the current plot is being queried or has an active query. Query must be enabled with ImPlotFlags_Query.
  578. IMPLOT_API bool IsPlotQueried();
  579. // Returns the current plot query bounds. Query must be enabled with ImPlotFlags_Query.
  580. IMPLOT_API ImPlotLimits GetPlotQuery(ImPlotYAxis y_axis = IMPLOT_AUTO);
  581. // Set the current plot query bounds. Query must be enabled with ImPlotFlags_Query.
  582. IMPLOT_API void SetPlotQuery(const ImPlotLimits& query, ImPlotYAxis y_axis = IMPLOT_AUTO);
  583. //-----------------------------------------------------------------------------
  584. // Algined Plots
  585. //-----------------------------------------------------------------------------
  586. // Consider using Begin/EndSubplots first. They are more feature rich and
  587. // accomplish the same behaviour by default. The functions below offer lower
  588. // level control of plot alignment.
  589. // Align axis padding over multiple plots in a single row or column. If this function returns true, EndAlignedPlots() must be called. #group_id must be unique.
  590. IMPLOT_API bool BeginAlignedPlots(const char* group_id, ImPlotOrientation orientation = ImPlotOrientation_Vertical);
  591. // Only call EndAlignedPlots() if BeginAlignedPlots() returns true!
  592. IMPLOT_API void EndAlignedPlots();
  593. //-----------------------------------------------------------------------------
  594. // Plot Tools
  595. //-----------------------------------------------------------------------------
  596. // The following functions MUST be called BETWEEN Begin/EndPlot!
  597. // Shows an annotation callout at a chosen point.
  598. IMPLOT_API void Annotate(double x, double y, const ImVec2& pix_offset, const char* fmt, ...) IM_FMTARGS(4);
  599. IMPLOT_API void Annotate(double x, double y, const ImVec2& pix_offset, const ImVec4& color, const char* fmt, ...) IM_FMTARGS(5);
  600. IMPLOT_API void AnnotateV(double x, double y, const ImVec2& pix_offset, const char* fmt, va_list args) IM_FMTLIST(4);
  601. IMPLOT_API void AnnotateV(double x, double y, const ImVec2& pix_offset, const ImVec4& color, const char* fmt, va_list args) IM_FMTLIST(5);
  602. // Same as above, but the annotation will always be clamped to stay inside the plot area.
  603. IMPLOT_API void AnnotateClamped(double x, double y, const ImVec2& pix_offset, const char* fmt, ...) IM_FMTARGS(4);
  604. IMPLOT_API void AnnotateClamped(double x, double y, const ImVec2& pix_offset, const ImVec4& color, const char* fmt, ...) IM_FMTARGS(5);
  605. IMPLOT_API void AnnotateClampedV(double x, double y, const ImVec2& pix_offset, const char* fmt, va_list args) IM_FMTLIST(4);
  606. IMPLOT_API void AnnotateClampedV(double x, double y, const ImVec2& pix_offset, const ImVec4& color, const char* fmt, va_list args) IM_FMTLIST(5);
  607. // Shows a draggable vertical guide line at an x-value. #col defaults to ImGuiCol_Text.
  608. IMPLOT_API bool DragLineX(const char* id, double* x_value, bool show_label = true, const ImVec4& col = IMPLOT_AUTO_COL, float thickness = 1);
  609. // Shows a draggable horizontal guide line at a y-value. #col defaults to ImGuiCol_Text.
  610. IMPLOT_API bool DragLineY(const char* id, double* y_value, bool show_label = true, const ImVec4& col = IMPLOT_AUTO_COL, float thickness = 1);
  611. // Shows a draggable point at x,y. #col defaults to ImGuiCol_Text.
  612. IMPLOT_API bool DragPoint(const char* id, double* x, double* y, bool show_label = true, const ImVec4& col = IMPLOT_AUTO_COL, float radius = 4);
  613. //-----------------------------------------------------------------------------
  614. // Legend Utils and Tools
  615. //-----------------------------------------------------------------------------
  616. // The following functions MUST be called BETWEEN Begin/EndPlot!
  617. // Set the location of the current plot's (or subplot's) legend.
  618. IMPLOT_API void SetLegendLocation(ImPlotLocation location, ImPlotOrientation orientation = ImPlotOrientation_Vertical, bool outside = false);
  619. // Set the location of the current plot's mouse position text (default = South|East).
  620. IMPLOT_API void SetMousePosLocation(ImPlotLocation location);
  621. // Returns true if a plot item legend entry is hovered.
  622. IMPLOT_API bool IsLegendEntryHovered(const char* label_id);
  623. // Begin a popup for a legend entry.
  624. IMPLOT_API bool BeginLegendPopup(const char* label_id, ImGuiMouseButton mouse_button = 1);
  625. // End a popup for a legend entry.
  626. IMPLOT_API void EndLegendPopup();
  627. //-----------------------------------------------------------------------------
  628. // Drag and Drop Utils
  629. //-----------------------------------------------------------------------------
  630. // The following functions MUST be called BETWEEN Begin/EndPlot!
  631. // Turns the current plot's plotting area into a drag and drop target. Don't forget to call EndDragDropTarget!
  632. IMPLOT_API bool BeginDragDropTarget();
  633. // Turns the current plot's X-axis into a drag and drop target. Don't forget to call EndDragDropTarget!
  634. IMPLOT_API bool BeginDragDropTargetX();
  635. // Turns the current plot's Y-Axis into a drag and drop target. Don't forget to call EndDragDropTarget!
  636. IMPLOT_API bool BeginDragDropTargetY(ImPlotYAxis axis = ImPlotYAxis_1);
  637. // Turns the current plot's legend into a drag and drop target. Don't forget to call EndDragDropTarget!
  638. IMPLOT_API bool BeginDragDropTargetLegend();
  639. // Ends a drag and drop target (currently just an alias for ImGui::EndDragDropTarget).
  640. IMPLOT_API void EndDragDropTarget();
  641. // NB: By default, plot and axes drag and drop *sources* require holding the Ctrl modifier to initiate the drag.
  642. // You can change the modifier if desired. If ImGuiKeyModFlags_None is provided, the axes will be locked from panning.
  643. // Turns the current plot's plotting area into a drag and drop source. Don't forget to call EndDragDropSource!
  644. IMPLOT_API bool BeginDragDropSource(ImGuiKeyModFlags key_mods = ImGuiKeyModFlags_Ctrl, ImGuiDragDropFlags flags = 0);
  645. // Turns the current plot's X-axis into a drag and drop source. Don't forget to call EndDragDropSource!
  646. IMPLOT_API bool BeginDragDropSourceX(ImGuiKeyModFlags key_mods = ImGuiKeyModFlags_Ctrl, ImGuiDragDropFlags flags = 0);
  647. // Turns the current plot's Y-axis into a drag and drop source. Don't forget to call EndDragDropSource!
  648. IMPLOT_API bool BeginDragDropSourceY(ImPlotYAxis axis = ImPlotYAxis_1, ImGuiKeyModFlags key_mods = ImGuiKeyModFlags_Ctrl, ImGuiDragDropFlags flags = 0);
  649. // Turns an item in the current plot's legend into drag and drop source. Don't forget to call EndDragDropSource!
  650. IMPLOT_API bool BeginDragDropSourceItem(const char* label_id, ImGuiDragDropFlags flags = 0);
  651. // Ends a drag and drop source (currently just an alias for ImGui::EndDragDropSource).
  652. IMPLOT_API void EndDragDropSource();
  653. //-----------------------------------------------------------------------------
  654. // Plot and Item Styling
  655. //-----------------------------------------------------------------------------
  656. // Styling colors in ImPlot works similarly to styling colors in ImGui, but
  657. // with one important difference. Like ImGui, all style colors are stored in an
  658. // indexable array in ImPlotStyle. You can permanently modify these values through
  659. // GetStyle().Colors, or temporarily modify them with Push/Pop functions below.
  660. // However, by default all style colors in ImPlot default to a special color
  661. // IMPLOT_AUTO_COL. The behavior of this color depends upon the style color to
  662. // which it as applied:
  663. //
  664. // 1) For style colors associated with plot items (e.g. ImPlotCol_Line),
  665. // IMPLOT_AUTO_COL tells ImPlot to color the item with the next unused
  666. // color in the current colormap. Thus, every item will have a different
  667. // color up to the number of colors in the colormap, at which point the
  668. // colormap will roll over. For most use cases, you should not need to
  669. // set these style colors to anything but IMPLOT_COL_AUTO; you are
  670. // probably better off changing the current colormap. However, if you
  671. // need to explicitly color a particular item you may either Push/Pop
  672. // the style color around the item in question, or use the SetNextXXXStyle
  673. // API below. If you permanently set one of these style colors to a specific
  674. // color, or forget to call Pop, then all subsequent items will be styled
  675. // with the color you set.
  676. //
  677. // 2) For style colors associated with plot styling (e.g. ImPlotCol_PlotBg),
  678. // IMPLOT_AUTO_COL tells ImPlot to set that color from color data in your
  679. // **ImGuiStyle**. The ImGuiCol_ that these style colors default to are
  680. // detailed above, and in general have been mapped to produce plots visually
  681. // consistent with your current ImGui style. Of course, you are free to
  682. // manually set these colors to whatever you like, and further can Push/Pop
  683. // them around individual plots for plot-specific styling (e.g. coloring axes).
  684. // Provides access to plot style structure for permanant modifications to colors, sizes, etc.
  685. IMPLOT_API ImPlotStyle& GetStyle();
  686. // Style plot colors for current ImGui style (default).
  687. IMPLOT_API void StyleColorsAuto(ImPlotStyle* dst = NULL);
  688. // Style plot colors for ImGui "Classic".
  689. IMPLOT_API void StyleColorsClassic(ImPlotStyle* dst = NULL);
  690. // Style plot colors for ImGui "Dark".
  691. IMPLOT_API void StyleColorsDark(ImPlotStyle* dst = NULL);
  692. // Style plot colors for ImGui "Light".
  693. IMPLOT_API void StyleColorsLight(ImPlotStyle* dst = NULL);
  694. // Use PushStyleX to temporarily modify your ImPlotStyle. The modification
  695. // will last until the matching call to PopStyleX. You MUST call a pop for
  696. // every push, otherwise you will leak memory! This behaves just like ImGui.
  697. // Temporarily modify a style color. Don't forget to call PopStyleColor!
  698. IMPLOT_API void PushStyleColor(ImPlotCol idx, ImU32 col);
  699. IMPLOT_API void PushStyleColor(ImPlotCol idx, const ImVec4& col);
  700. // Undo temporary style color modification(s). Undo multiple pushes at once by increasing count.
  701. IMPLOT_API void PopStyleColor(int count = 1);
  702. // Temporarily modify a style variable of float type. Don't forget to call PopStyleVar!
  703. IMPLOT_API void PushStyleVar(ImPlotStyleVar idx, float val);
  704. // Temporarily modify a style variable of int type. Don't forget to call PopStyleVar!
  705. IMPLOT_API void PushStyleVar(ImPlotStyleVar idx, int val);
  706. // Temporarily modify a style variable of ImVec2 type. Don't forget to call PopStyleVar!
  707. IMPLOT_API void PushStyleVar(ImPlotStyleVar idx, const ImVec2& val);
  708. // Undo temporary style variable modification(s). Undo multiple pushes at once by increasing count.
  709. IMPLOT_API void PopStyleVar(int count = 1);
  710. // The following can be used to modify the style of the next plot item ONLY. They do
  711. // NOT require calls to PopStyleX. Leave style attributes you don't want modified to
  712. // IMPLOT_AUTO or IMPLOT_AUTO_COL. Automatic styles will be deduced from the current
  713. // values in your ImPlotStyle or from Colormap data.
  714. // Set the line color and weight for the next item only.
  715. IMPLOT_API void SetNextLineStyle(const ImVec4& col = IMPLOT_AUTO_COL, float weight = IMPLOT_AUTO);
  716. // Set the fill color for the next item only.
  717. IMPLOT_API void SetNextFillStyle(const ImVec4& col = IMPLOT_AUTO_COL, float alpha_mod = IMPLOT_AUTO);
  718. // Set the marker style for the next item only.
  719. IMPLOT_API void SetNextMarkerStyle(ImPlotMarker marker = IMPLOT_AUTO, float size = IMPLOT_AUTO, const ImVec4& fill = IMPLOT_AUTO_COL, float weight = IMPLOT_AUTO, const ImVec4& outline = IMPLOT_AUTO_COL);
  720. // Set the error bar style for the next item only.
  721. IMPLOT_API void SetNextErrorBarStyle(const ImVec4& col = IMPLOT_AUTO_COL, float size = IMPLOT_AUTO, float weight = IMPLOT_AUTO);
  722. // Gets the last item primary color (i.e. its legend icon color)
  723. IMPLOT_API ImVec4 GetLastItemColor();
  724. // Returns the null terminated string name for an ImPlotCol.
  725. IMPLOT_API const char* GetStyleColorName(ImPlotCol idx);
  726. // Returns the null terminated string name for an ImPlotMarker.
  727. IMPLOT_API const char* GetMarkerName(ImPlotMarker idx);
  728. //-----------------------------------------------------------------------------
  729. // Colormaps
  730. //-----------------------------------------------------------------------------
  731. // Item styling is based on colormaps when the relevant ImPlotCol_XXX is set to
  732. // IMPLOT_AUTO_COL (default). Several built-in colormaps are available. You can
  733. // add and then push/pop your own colormaps as well. To permanently set a colormap,
  734. // modify the Colormap index member of your ImPlotStyle.
  735. // Colormap data will be ignored and a custom color will be used if you have done one of the following:
  736. // 1) Modified an item style color in your ImPlotStyle to anything other than IMPLOT_AUTO_COL.
  737. // 2) Pushed an item style color using PushStyleColor().
  738. // 3) Set the next item style with a SetNextXXXStyle function.
  739. // Add a new colormap. The color data will be copied. The colormap can be used by pushing either the returned index or the
  740. // string name with PushColormap. The colormap name must be unique and the size must be greater than 1. You will receive
  741. // an assert otherwise! By default colormaps are considered to be qualitative (i.e. discrete). If you want to create a
  742. // continuous colormap, set #qual=false. This will treat the colors you provide as keys, and ImPlot will build a linearly
  743. // interpolated lookup table. The memory footprint of this table will be exactly ((size-1)*255+1)*4 bytes.
  744. IMPLOT_API ImPlotColormap AddColormap(const char* name, const ImVec4* cols, int size, bool qual=true);
  745. IMPLOT_API ImPlotColormap AddColormap(const char* name, const ImU32* cols, int size, bool qual=true);
  746. // Returns the number of available colormaps (i.e. the built-in + user-added count).
  747. IMPLOT_API int GetColormapCount();
  748. // Returns a null terminated string name for a colormap given an index. Returns NULL if index is invalid.
  749. IMPLOT_API const char* GetColormapName(ImPlotColormap cmap);
  750. // Returns an index number for a colormap given a valid string name. Returns -1 if name is invalid.
  751. IMPLOT_API ImPlotColormap GetColormapIndex(const char* name);
  752. // Temporarily switch to one of the built-in (i.e. ImPlotColormap_XXX) or user-added colormaps (i.e. a return value of AddColormap). Don't forget to call PopColormap!
  753. IMPLOT_API void PushColormap(ImPlotColormap cmap);
  754. // Push a colormap by string name. Use built-in names such as "Default", "Deep", "Jet", etc. or a string you provided to AddColormap. Don't forget to call PopColormap!
  755. IMPLOT_API void PushColormap(const char* name);
  756. // Undo temporary colormap modification(s). Undo multiple pushes at once by increasing count.
  757. IMPLOT_API void PopColormap(int count = 1);
  758. // Returns the next color from the current colormap and advances the colormap for the current plot.
  759. // Can also be used with no return value to skip colors if desired. You need to call this between Begin/EndPlot!
  760. IMPLOT_API ImVec4 NextColormapColor();
  761. // Colormap utils. If cmap = IMPLOT_AUTO (default), the current colormap is assumed.
  762. // Pass an explicit colormap index (built-in or user-added) to specify otherwise.
  763. // Returns the size of a colormap.
  764. IMPLOT_API int GetColormapSize(ImPlotColormap cmap = IMPLOT_AUTO);
  765. // Returns a color from a colormap given an index >= 0 (modulo will be performed).
  766. IMPLOT_API ImVec4 GetColormapColor(int idx, ImPlotColormap cmap = IMPLOT_AUTO);
  767. // Sample a color from the current colormap given t between 0 and 1.
  768. IMPLOT_API ImVec4 SampleColormap(float t, ImPlotColormap cmap = IMPLOT_AUTO);
  769. // Shows a vertical color scale with linear spaced ticks using the specified color map. Use double hashes to hide label (e.g. "##NoLabel").
  770. IMPLOT_API void ColormapScale(const char* label, double scale_min, double scale_max, const ImVec2& size = ImVec2(0,0), ImPlotColormap cmap = IMPLOT_AUTO, const char* fmt = "%g");
  771. // Shows a horizontal slider with a colormap gradient background. Optionally returns the color sampled at t in [0 1].
  772. IMPLOT_API bool ColormapSlider(const char* label, float* t, ImVec4* out = NULL, const char* format = "", ImPlotColormap cmap = IMPLOT_AUTO);
  773. // Shows a button with a colormap gradient brackground.
  774. IMPLOT_API bool ColormapButton(const char* label, const ImVec2& size = ImVec2(0,0), ImPlotColormap cmap = IMPLOT_AUTO);
  775. // When items in a plot sample their color from a colormap, the color is cached and does not change
  776. // unless explicitly overriden. Therefore, if you change the colormap after the item has already been plotted,
  777. // item colors will NOT update. If you need item colors to resample the new colormap, then use this
  778. // function to bust the cached colors. If #plot_title_id is NULL, then every item in EVERY existing plot
  779. // will be cache busted. Otherwise only the plot specified by #plot_title_id will be busted. For the
  780. // latter, this function must be called in the same ImGui ID scope that the plot is in. You should rarely if ever
  781. // need this function, but it is available for applications that require runtime colormap swaps (e.g. Heatmaps demo).
  782. IMPLOT_API void BustColorCache(const char* plot_title_id = NULL);
  783. //-----------------------------------------------------------------------------
  784. // Miscellaneous
  785. //-----------------------------------------------------------------------------
  786. // Render icons similar to those that appear in legends (nifty for data lists).
  787. IMPLOT_API void ItemIcon(const ImVec4& col);
  788. IMPLOT_API void ItemIcon(ImU32 col);
  789. IMPLOT_API void ColormapIcon(ImPlotColormap cmap);
  790. // Get the plot draw list for custom rendering to the current plot area. Call between Begin/EndPlot.
  791. IMPLOT_API ImDrawList* GetPlotDrawList();
  792. // Push clip rect for rendering to current plot area. The rect can be expanded or contracted by #expand pixels. Call between Begin/EndPlot.
  793. IMPLOT_API void PushPlotClipRect(float expand=0);
  794. // Pop plot clip rect. Call between Begin/EndPlot.
  795. IMPLOT_API void PopPlotClipRect();
  796. // Shows ImPlot style selector dropdown menu.
  797. IMPLOT_API bool ShowStyleSelector(const char* label);
  798. // Shows ImPlot colormap selector dropdown menu.
  799. IMPLOT_API bool ShowColormapSelector(const char* label);
  800. // Shows ImPlot style editor block (not a window).
  801. IMPLOT_API void ShowStyleEditor(ImPlotStyle* ref = NULL);
  802. // Add basic help/info block for end users (not a window).
  803. IMPLOT_API void ShowUserGuide();
  804. // Shows ImPlot metrics/debug information window.
  805. IMPLOT_API void ShowMetricsWindow(bool* p_popen = NULL);
  806. //-----------------------------------------------------------------------------
  807. // Demo (add implot_demo.cpp to your sources!)
  808. //-----------------------------------------------------------------------------
  809. // Shows the ImPlot demo window.
  810. IMPLOT_API void ShowDemoWindow(bool* p_open = NULL);
  811. } // namespace ImPlot