implot.h 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. // MIT License
  2. // Copyright (c) 2023 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.17
  19. // Table of Contents:
  20. //
  21. // [SECTION] Macros and Defines
  22. // [SECTION] Enums and Types
  23. // [SECTION] Callbacks
  24. // [SECTION] Contexts
  25. // [SECTION] Begin/End Plot
  26. // [SECTION] Begin/End Subplot
  27. // [SECTION] Setup
  28. // [SECTION] SetNext
  29. // [SECTION] Plot Items
  30. // [SECTION] Plot Tools
  31. // [SECTION] Plot Utils
  32. // [SECTION] Legend Utils
  33. // [SECTION] Drag and Drop
  34. // [SECTION] Styling
  35. // [SECTION] Colormaps
  36. // [SECTION] Input Mapping
  37. // [SECTION] Miscellaneous
  38. // [SECTION] Demo
  39. // [SECTION] Obsolete API
  40. #pragma once
  41. #include "imgui.h"
  42. #ifndef IMGUI_DISABLE
  43. //-----------------------------------------------------------------------------
  44. // [SECTION] Macros and Defines
  45. //-----------------------------------------------------------------------------
  46. // Define attributes of all API symbols declarations (e.g. for DLL under Windows)
  47. // Using ImPlot via a shared library is not recommended, because we don't guarantee
  48. // backward nor forward ABI compatibility and also function call overhead. If you
  49. // do use ImPlot as a DLL, be sure to call SetImGuiContext (see Miscellanous section).
  50. #ifndef IMPLOT_API
  51. #define IMPLOT_API
  52. #endif
  53. // ImPlot version string.
  54. #define IMPLOT_VERSION "0.17"
  55. // Indicates variable should deduced automatically.
  56. #define IMPLOT_AUTO -1
  57. // Special color used to indicate that a color should be deduced automatically.
  58. #define IMPLOT_AUTO_COL ImVec4(0,0,0,-1)
  59. // Macro for templated plotting functions; keeps header clean.
  60. #define IMPLOT_TMP template <typename T> IMPLOT_API
  61. //-----------------------------------------------------------------------------
  62. // [SECTION] Enums and Types
  63. //-----------------------------------------------------------------------------
  64. // Forward declarations
  65. struct ImPlotContext; // ImPlot context (opaque struct, see implot_internal.h)
  66. // Enums/Flags
  67. typedef int ImAxis; // -> enum ImAxis_
  68. typedef int ImPlotFlags; // -> enum ImPlotFlags_
  69. typedef int ImPlotAxisFlags; // -> enum ImPlotAxisFlags_
  70. typedef int ImPlotSubplotFlags; // -> enum ImPlotSubplotFlags_
  71. typedef int ImPlotLegendFlags; // -> enum ImPlotLegendFlags_
  72. typedef int ImPlotMouseTextFlags; // -> enum ImPlotMouseTextFlags_
  73. typedef int ImPlotDragToolFlags; // -> ImPlotDragToolFlags_
  74. typedef int ImPlotColormapScaleFlags; // -> ImPlotColormapScaleFlags_
  75. typedef int ImPlotItemFlags; // -> ImPlotItemFlags_
  76. typedef int ImPlotLineFlags; // -> ImPlotLineFlags_
  77. typedef int ImPlotScatterFlags; // -> ImPlotScatterFlags
  78. typedef int ImPlotStairsFlags; // -> ImPlotStairsFlags_
  79. typedef int ImPlotShadedFlags; // -> ImPlotShadedFlags_
  80. typedef int ImPlotBarsFlags; // -> ImPlotBarsFlags_
  81. typedef int ImPlotBarGroupsFlags; // -> ImPlotBarGroupsFlags_
  82. typedef int ImPlotErrorBarsFlags; // -> ImPlotErrorBarsFlags_
  83. typedef int ImPlotStemsFlags; // -> ImPlotStemsFlags_
  84. typedef int ImPlotInfLinesFlags; // -> ImPlotInfLinesFlags_
  85. typedef int ImPlotPieChartFlags; // -> ImPlotPieChartFlags_
  86. typedef int ImPlotHeatmapFlags; // -> ImPlotHeatmapFlags_
  87. typedef int ImPlotHistogramFlags; // -> ImPlotHistogramFlags_
  88. typedef int ImPlotDigitalFlags; // -> ImPlotDigitalFlags_
  89. typedef int ImPlotImageFlags; // -> ImPlotImageFlags_
  90. typedef int ImPlotTextFlags; // -> ImPlotTextFlags_
  91. typedef int ImPlotDummyFlags; // -> ImPlotDummyFlags_
  92. typedef int ImPlotCond; // -> enum ImPlotCond_
  93. typedef int ImPlotCol; // -> enum ImPlotCol_
  94. typedef int ImPlotStyleVar; // -> enum ImPlotStyleVar_
  95. typedef int ImPlotScale; // -> enum ImPlotScale_
  96. typedef int ImPlotMarker; // -> enum ImPlotMarker_
  97. typedef int ImPlotColormap; // -> enum ImPlotColormap_
  98. typedef int ImPlotLocation; // -> enum ImPlotLocation_
  99. typedef int ImPlotBin; // -> enum ImPlotBin_
  100. // Axis indices. The values assigned may change; NEVER hardcode these.
  101. enum ImAxis_ {
  102. // horizontal axes
  103. ImAxis_X1 = 0, // enabled by default
  104. ImAxis_X2, // disabled by default
  105. ImAxis_X3, // disabled by default
  106. // vertical axes
  107. ImAxis_Y1, // enabled by default
  108. ImAxis_Y2, // disabled by default
  109. ImAxis_Y3, // disabled by default
  110. // bookeeping
  111. ImAxis_COUNT
  112. };
  113. // Options for plots (see BeginPlot).
  114. enum ImPlotFlags_ {
  115. ImPlotFlags_None = 0, // default
  116. ImPlotFlags_NoTitle = 1 << 0, // the plot title will not be displayed (titles are also hidden if preceeded by double hashes, e.g. "##MyPlot")
  117. ImPlotFlags_NoLegend = 1 << 1, // the legend will not be displayed
  118. ImPlotFlags_NoMouseText = 1 << 2, // the mouse position, in plot coordinates, will not be displayed inside of the plot
  119. ImPlotFlags_NoInputs = 1 << 3, // the user will not be able to interact with the plot
  120. ImPlotFlags_NoMenus = 1 << 4, // the user will not be able to open context menus
  121. ImPlotFlags_NoBoxSelect = 1 << 5, // the user will not be able to box-select
  122. ImPlotFlags_NoFrame = 1 << 6, // the ImGui frame will not be rendered
  123. ImPlotFlags_Equal = 1 << 7, // x and y axes pairs will be constrained to have the same units/pixel
  124. ImPlotFlags_Crosshairs = 1 << 8, // the default mouse cursor will be replaced with a crosshair when hovered
  125. ImPlotFlags_CanvasOnly = ImPlotFlags_NoTitle | ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText
  126. };
  127. // Options for plot axes (see SetupAxis).
  128. enum ImPlotAxisFlags_ {
  129. ImPlotAxisFlags_None = 0, // default
  130. ImPlotAxisFlags_NoLabel = 1 << 0, // the axis label will not be displayed (axis labels are also hidden if the supplied string name is nullptr)
  131. ImPlotAxisFlags_NoGridLines = 1 << 1, // no grid lines will be displayed
  132. ImPlotAxisFlags_NoTickMarks = 1 << 2, // no tick marks will be displayed
  133. ImPlotAxisFlags_NoTickLabels = 1 << 3, // no text labels will be displayed
  134. ImPlotAxisFlags_NoInitialFit = 1 << 4, // axis will not be initially fit to data extents on the first rendered frame
  135. ImPlotAxisFlags_NoMenus = 1 << 5, // the user will not be able to open context menus with right-click
  136. ImPlotAxisFlags_NoSideSwitch = 1 << 6, // the user will not be able to switch the axis side by dragging it
  137. ImPlotAxisFlags_NoHighlight = 1 << 7, // the axis will not have its background highlighted when hovered or held
  138. ImPlotAxisFlags_Opposite = 1 << 8, // axis ticks and labels will be rendered on the conventionally opposite side (i.e, right or top)
  139. ImPlotAxisFlags_Foreground = 1 << 9, // grid lines will be displayed in the foreground (i.e. on top of data) instead of the background
  140. ImPlotAxisFlags_Invert = 1 << 10, // the axis will be inverted
  141. ImPlotAxisFlags_AutoFit = 1 << 11, // axis will be auto-fitting to data extents
  142. ImPlotAxisFlags_RangeFit = 1 << 12, // axis will only fit points if the point is in the visible range of the **orthogonal** axis
  143. ImPlotAxisFlags_PanStretch = 1 << 13, // panning in a locked or constrained state will cause the axis to stretch if possible
  144. ImPlotAxisFlags_LockMin = 1 << 14, // the axis minimum value will be locked when panning/zooming
  145. ImPlotAxisFlags_LockMax = 1 << 15, // the axis maximum value will be locked when panning/zooming
  146. ImPlotAxisFlags_Lock = ImPlotAxisFlags_LockMin | ImPlotAxisFlags_LockMax,
  147. ImPlotAxisFlags_NoDecorations = ImPlotAxisFlags_NoLabel | ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_NoTickMarks | ImPlotAxisFlags_NoTickLabels,
  148. ImPlotAxisFlags_AuxDefault = ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_Opposite
  149. };
  150. // Options for subplots (see BeginSubplot)
  151. enum ImPlotSubplotFlags_ {
  152. ImPlotSubplotFlags_None = 0, // default
  153. ImPlotSubplotFlags_NoTitle = 1 << 0, // the subplot title will not be displayed (titles are also hidden if preceeded by double hashes, e.g. "##MySubplot")
  154. ImPlotSubplotFlags_NoLegend = 1 << 1, // the legend will not be displayed (only applicable if ImPlotSubplotFlags_ShareItems is enabled)
  155. ImPlotSubplotFlags_NoMenus = 1 << 2, // the user will not be able to open context menus with right-click
  156. ImPlotSubplotFlags_NoResize = 1 << 3, // resize splitters between subplot cells will be not be provided
  157. ImPlotSubplotFlags_NoAlign = 1 << 4, // subplot edges will not be aligned vertically or horizontally
  158. ImPlotSubplotFlags_ShareItems = 1 << 5, // items across all subplots will be shared and rendered into a single legend entry
  159. ImPlotSubplotFlags_LinkRows = 1 << 6, // link the y-axis limits of all plots in each row (does not apply to auxiliary axes)
  160. ImPlotSubplotFlags_LinkCols = 1 << 7, // link the x-axis limits of all plots in each column (does not apply to auxiliary axes)
  161. ImPlotSubplotFlags_LinkAllX = 1 << 8, // link the x-axis limits in every plot in the subplot (does not apply to auxiliary axes)
  162. ImPlotSubplotFlags_LinkAllY = 1 << 9, // link the y-axis limits in every plot in the subplot (does not apply to auxiliary axes)
  163. ImPlotSubplotFlags_ColMajor = 1 << 10 // subplots are added in column major order instead of the default row major order
  164. };
  165. // Options for legends (see SetupLegend)
  166. enum ImPlotLegendFlags_ {
  167. ImPlotLegendFlags_None = 0, // default
  168. ImPlotLegendFlags_NoButtons = 1 << 0, // legend icons will not function as hide/show buttons
  169. ImPlotLegendFlags_NoHighlightItem = 1 << 1, // plot items will not be highlighted when their legend entry is hovered
  170. ImPlotLegendFlags_NoHighlightAxis = 1 << 2, // axes will not be highlighted when legend entries are hovered (only relevant if x/y-axis count > 1)
  171. ImPlotLegendFlags_NoMenus = 1 << 3, // the user will not be able to open context menus with right-click
  172. ImPlotLegendFlags_Outside = 1 << 4, // legend will be rendered outside of the plot area
  173. ImPlotLegendFlags_Horizontal = 1 << 5, // legend entries will be displayed horizontally
  174. ImPlotLegendFlags_Sort = 1 << 6, // legend entries will be displayed in alphabetical order
  175. };
  176. // Options for mouse hover text (see SetupMouseText)
  177. enum ImPlotMouseTextFlags_ {
  178. ImPlotMouseTextFlags_None = 0, // default
  179. ImPlotMouseTextFlags_NoAuxAxes = 1 << 0, // only show the mouse position for primary axes
  180. ImPlotMouseTextFlags_NoFormat = 1 << 1, // axes label formatters won't be used to render text
  181. ImPlotMouseTextFlags_ShowAlways = 1 << 2, // always display mouse position even if plot not hovered
  182. };
  183. // Options for DragPoint, DragLine, DragRect
  184. enum ImPlotDragToolFlags_ {
  185. ImPlotDragToolFlags_None = 0, // default
  186. ImPlotDragToolFlags_NoCursors = 1 << 0, // drag tools won't change cursor icons when hovered or held
  187. ImPlotDragToolFlags_NoFit = 1 << 1, // the drag tool won't be considered for plot fits
  188. ImPlotDragToolFlags_NoInputs = 1 << 2, // lock the tool from user inputs
  189. ImPlotDragToolFlags_Delayed = 1 << 3, // tool rendering will be delayed one frame; useful when applying position-constraints
  190. };
  191. // Flags for ColormapScale
  192. enum ImPlotColormapScaleFlags_ {
  193. ImPlotColormapScaleFlags_None = 0, // default
  194. ImPlotColormapScaleFlags_NoLabel = 1 << 0, // the colormap axis label will not be displayed
  195. ImPlotColormapScaleFlags_Opposite = 1 << 1, // render the colormap label and tick labels on the opposite side
  196. ImPlotColormapScaleFlags_Invert = 1 << 2, // invert the colormap bar and axis scale (this only affects rendering; if you only want to reverse the scale mapping, make scale_min > scale_max)
  197. };
  198. // Flags for ANY PlotX function
  199. enum ImPlotItemFlags_ {
  200. ImPlotItemFlags_None = 0,
  201. ImPlotItemFlags_NoLegend = 1 << 0, // the item won't have a legend entry displayed
  202. ImPlotItemFlags_NoFit = 1 << 1, // the item won't be considered for plot fits
  203. };
  204. // Flags for PlotLine
  205. enum ImPlotLineFlags_ {
  206. ImPlotLineFlags_None = 0, // default
  207. ImPlotLineFlags_Segments = 1 << 10, // a line segment will be rendered from every two consecutive points
  208. ImPlotLineFlags_Loop = 1 << 11, // the last and first point will be connected to form a closed loop
  209. ImPlotLineFlags_SkipNaN = 1 << 12, // NaNs values will be skipped instead of rendered as missing data
  210. ImPlotLineFlags_NoClip = 1 << 13, // markers (if displayed) on the edge of a plot will not be clipped
  211. ImPlotLineFlags_Shaded = 1 << 14, // a filled region between the line and horizontal origin will be rendered; use PlotShaded for more advanced cases
  212. };
  213. // Flags for PlotScatter
  214. enum ImPlotScatterFlags_ {
  215. ImPlotScatterFlags_None = 0, // default
  216. ImPlotScatterFlags_NoClip = 1 << 10, // markers on the edge of a plot will not be clipped
  217. };
  218. // Flags for PlotStairs
  219. enum ImPlotStairsFlags_ {
  220. ImPlotStairsFlags_None = 0, // default
  221. ImPlotStairsFlags_PreStep = 1 << 10, // the y value is continued constantly to the left from every x position, i.e. the interval (x[i-1], x[i]] has the value y[i]
  222. ImPlotStairsFlags_Shaded = 1 << 11 // a filled region between the stairs and horizontal origin will be rendered; use PlotShaded for more advanced cases
  223. };
  224. // Flags for PlotShaded (placeholder)
  225. enum ImPlotShadedFlags_ {
  226. ImPlotShadedFlags_None = 0 // default
  227. };
  228. // Flags for PlotBars
  229. enum ImPlotBarsFlags_ {
  230. ImPlotBarsFlags_None = 0, // default
  231. ImPlotBarsFlags_Horizontal = 1 << 10, // bars will be rendered horizontally on the current y-axis
  232. };
  233. // Flags for PlotBarGroups
  234. enum ImPlotBarGroupsFlags_ {
  235. ImPlotBarGroupsFlags_None = 0, // default
  236. ImPlotBarGroupsFlags_Horizontal = 1 << 10, // bar groups will be rendered horizontally on the current y-axis
  237. ImPlotBarGroupsFlags_Stacked = 1 << 11, // items in a group will be stacked on top of each other
  238. };
  239. // Flags for PlotErrorBars
  240. enum ImPlotErrorBarsFlags_ {
  241. ImPlotErrorBarsFlags_None = 0, // default
  242. ImPlotErrorBarsFlags_Horizontal = 1 << 10, // error bars will be rendered horizontally on the current y-axis
  243. };
  244. // Flags for PlotStems
  245. enum ImPlotStemsFlags_ {
  246. ImPlotStemsFlags_None = 0, // default
  247. ImPlotStemsFlags_Horizontal = 1 << 10, // stems will be rendered horizontally on the current y-axis
  248. };
  249. // Flags for PlotInfLines
  250. enum ImPlotInfLinesFlags_ {
  251. ImPlotInfLinesFlags_None = 0, // default
  252. ImPlotInfLinesFlags_Horizontal = 1 << 10 // lines will be rendered horizontally on the current y-axis
  253. };
  254. // Flags for PlotPieChart
  255. enum ImPlotPieChartFlags_ {
  256. ImPlotPieChartFlags_None = 0, // default
  257. ImPlotPieChartFlags_Normalize = 1 << 10, // force normalization of pie chart values (i.e. always make a full circle if sum < 0)
  258. ImPlotPieChartFlags_IgnoreHidden = 1 << 11, // ignore hidden slices when drawing the pie chart (as if they were not there)
  259. ImPlotPieChartFlags_Exploding = 1 << 12 // Explode legend-hovered slice
  260. };
  261. // Flags for PlotHeatmap
  262. enum ImPlotHeatmapFlags_ {
  263. ImPlotHeatmapFlags_None = 0, // default
  264. ImPlotHeatmapFlags_ColMajor = 1 << 10, // data will be read in column major order
  265. };
  266. // Flags for PlotHistogram and PlotHistogram2D
  267. enum ImPlotHistogramFlags_ {
  268. ImPlotHistogramFlags_None = 0, // default
  269. ImPlotHistogramFlags_Horizontal = 1 << 10, // histogram bars will be rendered horizontally (not supported by PlotHistogram2D)
  270. ImPlotHistogramFlags_Cumulative = 1 << 11, // each bin will contain its count plus the counts of all previous bins (not supported by PlotHistogram2D)
  271. ImPlotHistogramFlags_Density = 1 << 12, // counts will be normalized, i.e. the PDF will be visualized, or the CDF will be visualized if Cumulative is also set
  272. ImPlotHistogramFlags_NoOutliers = 1 << 13, // exclude values outside the specifed histogram range from the count toward normalizing and cumulative counts
  273. ImPlotHistogramFlags_ColMajor = 1 << 14 // data will be read in column major order (not supported by PlotHistogram)
  274. };
  275. // Flags for PlotDigital (placeholder)
  276. enum ImPlotDigitalFlags_ {
  277. ImPlotDigitalFlags_None = 0 // default
  278. };
  279. // Flags for PlotImage (placeholder)
  280. enum ImPlotImageFlags_ {
  281. ImPlotImageFlags_None = 0 // default
  282. };
  283. // Flags for PlotText
  284. enum ImPlotTextFlags_ {
  285. ImPlotTextFlags_None = 0, // default
  286. ImPlotTextFlags_Vertical = 1 << 10 // text will be rendered vertically
  287. };
  288. // Flags for PlotDummy (placeholder)
  289. enum ImPlotDummyFlags_ {
  290. ImPlotDummyFlags_None = 0 // default
  291. };
  292. // Represents a condition for SetupAxisLimits etc. (same as ImGuiCond, but we only support a subset of those enums)
  293. enum ImPlotCond_
  294. {
  295. ImPlotCond_None = ImGuiCond_None, // No condition (always set the variable), same as _Always
  296. ImPlotCond_Always = ImGuiCond_Always, // No condition (always set the variable)
  297. ImPlotCond_Once = ImGuiCond_Once, // Set the variable once per runtime session (only the first call will succeed)
  298. };
  299. // Plot styling colors.
  300. enum ImPlotCol_ {
  301. // item styling colors
  302. ImPlotCol_Line, // plot line/outline color (defaults to next unused color in current colormap)
  303. ImPlotCol_Fill, // plot fill color for bars (defaults to the current line color)
  304. ImPlotCol_MarkerOutline, // marker outline color (defaults to the current line color)
  305. ImPlotCol_MarkerFill, // marker fill color (defaults to the current line color)
  306. ImPlotCol_ErrorBar, // error bar color (defaults to ImGuiCol_Text)
  307. // plot styling colors
  308. ImPlotCol_FrameBg, // plot frame background color (defaults to ImGuiCol_FrameBg)
  309. ImPlotCol_PlotBg, // plot area background color (defaults to ImGuiCol_WindowBg)
  310. ImPlotCol_PlotBorder, // plot area border color (defaults to ImGuiCol_Border)
  311. ImPlotCol_LegendBg, // legend background color (defaults to ImGuiCol_PopupBg)
  312. ImPlotCol_LegendBorder, // legend border color (defaults to ImPlotCol_PlotBorder)
  313. ImPlotCol_LegendText, // legend text color (defaults to ImPlotCol_InlayText)
  314. ImPlotCol_TitleText, // plot title text color (defaults to ImGuiCol_Text)
  315. ImPlotCol_InlayText, // color of text appearing inside of plots (defaults to ImGuiCol_Text)
  316. ImPlotCol_AxisText, // axis label and tick lables color (defaults to ImGuiCol_Text)
  317. ImPlotCol_AxisGrid, // axis grid color (defaults to 25% ImPlotCol_AxisText)
  318. ImPlotCol_AxisTick, // axis tick color (defaults to AxisGrid)
  319. ImPlotCol_AxisBg, // background color of axis hover region (defaults to transparent)
  320. ImPlotCol_AxisBgHovered, // axis hover color (defaults to ImGuiCol_ButtonHovered)
  321. ImPlotCol_AxisBgActive, // axis active color (defaults to ImGuiCol_ButtonActive)
  322. ImPlotCol_Selection, // box-selection color (defaults to yellow)
  323. ImPlotCol_Crosshairs, // crosshairs color (defaults to ImPlotCol_PlotBorder)
  324. ImPlotCol_COUNT
  325. };
  326. // Plot styling variables.
  327. enum ImPlotStyleVar_ {
  328. // item styling variables
  329. ImPlotStyleVar_LineWeight, // float, plot item line weight in pixels
  330. ImPlotStyleVar_Marker, // int, marker specification
  331. ImPlotStyleVar_MarkerSize, // float, marker size in pixels (roughly the marker's "radius")
  332. ImPlotStyleVar_MarkerWeight, // float, plot outline weight of markers in pixels
  333. ImPlotStyleVar_FillAlpha, // float, alpha modifier applied to all plot item fills
  334. ImPlotStyleVar_ErrorBarSize, // float, error bar whisker width in pixels
  335. ImPlotStyleVar_ErrorBarWeight, // float, error bar whisker weight in pixels
  336. ImPlotStyleVar_DigitalBitHeight, // float, digital channels bit height (at 1) in pixels
  337. ImPlotStyleVar_DigitalBitGap, // float, digital channels bit padding gap in pixels
  338. // plot styling variables
  339. ImPlotStyleVar_PlotBorderSize, // float, thickness of border around plot area
  340. ImPlotStyleVar_MinorAlpha, // float, alpha multiplier applied to minor axis grid lines
  341. ImPlotStyleVar_MajorTickLen, // ImVec2, major tick lengths for X and Y axes
  342. ImPlotStyleVar_MinorTickLen, // ImVec2, minor tick lengths for X and Y axes
  343. ImPlotStyleVar_MajorTickSize, // ImVec2, line thickness of major ticks
  344. ImPlotStyleVar_MinorTickSize, // ImVec2, line thickness of minor ticks
  345. ImPlotStyleVar_MajorGridSize, // ImVec2, line thickness of major grid lines
  346. ImPlotStyleVar_MinorGridSize, // ImVec2, line thickness of minor grid lines
  347. ImPlotStyleVar_PlotPadding, // ImVec2, padding between widget frame and plot area, labels, or outside legends (i.e. main padding)
  348. ImPlotStyleVar_LabelPadding, // ImVec2, padding between axes labels, tick labels, and plot edge
  349. ImPlotStyleVar_LegendPadding, // ImVec2, legend padding from plot edges
  350. ImPlotStyleVar_LegendInnerPadding, // ImVec2, legend inner padding from legend edges
  351. ImPlotStyleVar_LegendSpacing, // ImVec2, spacing between legend entries
  352. ImPlotStyleVar_MousePosPadding, // ImVec2, padding between plot edge and interior info text
  353. ImPlotStyleVar_AnnotationPadding, // ImVec2, text padding around annotation labels
  354. 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)
  355. ImPlotStyleVar_PlotDefaultSize, // ImVec2, default size used when ImVec2(0,0) is passed to BeginPlot
  356. ImPlotStyleVar_PlotMinSize, // ImVec2, minimum size plot frame can be when shrunk
  357. ImPlotStyleVar_COUNT
  358. };
  359. // Axis scale
  360. enum ImPlotScale_ {
  361. ImPlotScale_Linear = 0, // default linear scale
  362. ImPlotScale_Time, // date/time scale
  363. ImPlotScale_Log10, // base 10 logartithmic scale
  364. ImPlotScale_SymLog, // symmetric log scale
  365. };
  366. // Marker specifications.
  367. enum ImPlotMarker_ {
  368. ImPlotMarker_None = -1, // no marker
  369. ImPlotMarker_Circle, // a circle marker (default)
  370. ImPlotMarker_Square, // a square maker
  371. ImPlotMarker_Diamond, // a diamond marker
  372. ImPlotMarker_Up, // an upward-pointing triangle marker
  373. ImPlotMarker_Down, // an downward-pointing triangle marker
  374. ImPlotMarker_Left, // an leftward-pointing triangle marker
  375. ImPlotMarker_Right, // an rightward-pointing triangle marker
  376. ImPlotMarker_Cross, // a cross marker (not fillable)
  377. ImPlotMarker_Plus, // a plus marker (not fillable)
  378. ImPlotMarker_Asterisk, // a asterisk marker (not fillable)
  379. ImPlotMarker_COUNT
  380. };
  381. // Built-in colormaps
  382. enum ImPlotColormap_ {
  383. ImPlotColormap_Deep = 0, // a.k.a. seaborn deep (qual=true, n=10) (default)
  384. ImPlotColormap_Dark = 1, // a.k.a. matplotlib "Set1" (qual=true, n=9 )
  385. ImPlotColormap_Pastel = 2, // a.k.a. matplotlib "Pastel1" (qual=true, n=9 )
  386. ImPlotColormap_Paired = 3, // a.k.a. matplotlib "Paired" (qual=true, n=12)
  387. ImPlotColormap_Viridis = 4, // a.k.a. matplotlib "viridis" (qual=false, n=11)
  388. ImPlotColormap_Plasma = 5, // a.k.a. matplotlib "plasma" (qual=false, n=11)
  389. ImPlotColormap_Hot = 6, // a.k.a. matplotlib/MATLAB "hot" (qual=false, n=11)
  390. ImPlotColormap_Cool = 7, // a.k.a. matplotlib/MATLAB "cool" (qual=false, n=11)
  391. ImPlotColormap_Pink = 8, // a.k.a. matplotlib/MATLAB "pink" (qual=false, n=11)
  392. ImPlotColormap_Jet = 9, // a.k.a. MATLAB "jet" (qual=false, n=11)
  393. ImPlotColormap_Twilight = 10, // a.k.a. matplotlib "twilight" (qual=false, n=11)
  394. ImPlotColormap_RdBu = 11, // red/blue, Color Brewer (qual=false, n=11)
  395. ImPlotColormap_BrBG = 12, // brown/blue-green, Color Brewer (qual=false, n=11)
  396. ImPlotColormap_PiYG = 13, // pink/yellow-green, Color Brewer (qual=false, n=11)
  397. ImPlotColormap_Spectral = 14, // color spectrum, Color Brewer (qual=false, n=11)
  398. ImPlotColormap_Greys = 15, // white/black (qual=false, n=2 )
  399. };
  400. // Used to position items on a plot (e.g. legends, labels, etc.)
  401. enum ImPlotLocation_ {
  402. ImPlotLocation_Center = 0, // center-center
  403. ImPlotLocation_North = 1 << 0, // top-center
  404. ImPlotLocation_South = 1 << 1, // bottom-center
  405. ImPlotLocation_West = 1 << 2, // center-left
  406. ImPlotLocation_East = 1 << 3, // center-right
  407. ImPlotLocation_NorthWest = ImPlotLocation_North | ImPlotLocation_West, // top-left
  408. ImPlotLocation_NorthEast = ImPlotLocation_North | ImPlotLocation_East, // top-right
  409. ImPlotLocation_SouthWest = ImPlotLocation_South | ImPlotLocation_West, // bottom-left
  410. ImPlotLocation_SouthEast = ImPlotLocation_South | ImPlotLocation_East // bottom-right
  411. };
  412. // Enums for different automatic histogram binning methods (k = bin count or w = bin width)
  413. enum ImPlotBin_ {
  414. ImPlotBin_Sqrt = -1, // k = sqrt(n)
  415. ImPlotBin_Sturges = -2, // k = 1 + log2(n)
  416. ImPlotBin_Rice = -3, // k = 2 * cbrt(n)
  417. ImPlotBin_Scott = -4, // w = 3.49 * sigma / cbrt(n)
  418. };
  419. // Double precision version of ImVec2 used by ImPlot. Extensible by end users.
  420. IM_MSVC_RUNTIME_CHECKS_OFF
  421. struct ImPlotPoint {
  422. double x, y;
  423. constexpr ImPlotPoint() : x(0.0), y(0.0) { }
  424. constexpr ImPlotPoint(double _x, double _y) : x(_x), y(_y) { }
  425. constexpr ImPlotPoint(const ImVec2& p) : x((double)p.x), y((double)p.y) { }
  426. double& operator[] (size_t idx) { IM_ASSERT(idx == 0 || idx == 1); return ((double*)(void*)(char*)this)[idx]; }
  427. double operator[] (size_t idx) const { IM_ASSERT(idx == 0 || idx == 1); return ((const double*)(const void*)(const char*)this)[idx]; }
  428. #ifdef IMPLOT_POINT_CLASS_EXTRA
  429. IMPLOT_POINT_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h
  430. // to convert back and forth between your math types and ImPlotPoint.
  431. #endif
  432. };
  433. IM_MSVC_RUNTIME_CHECKS_RESTORE
  434. // Range defined by a min/max value.
  435. struct ImPlotRange {
  436. double Min, Max;
  437. constexpr ImPlotRange() : Min(0.0), Max(0.0) { }
  438. constexpr ImPlotRange(double _min, double _max) : Min(_min), Max(_max) { }
  439. bool Contains(double value) const { return value >= Min && value <= Max; }
  440. double Size() const { return Max - Min; }
  441. double Clamp(double value) const { return (value < Min) ? Min : (value > Max) ? Max : value; }
  442. };
  443. // Combination of two range limits for X and Y axes. Also an AABB defined by Min()/Max().
  444. struct ImPlotRect {
  445. ImPlotRange X, Y;
  446. constexpr ImPlotRect() : X(0.0,0.0), Y(0.0,0.0) { }
  447. constexpr ImPlotRect(double x_min, double x_max, double y_min, double y_max) : X(x_min, x_max), Y(y_min, y_max) { }
  448. bool Contains(const ImPlotPoint& p) const { return Contains(p.x, p.y); }
  449. bool Contains(double x, double y) const { return X.Contains(x) && Y.Contains(y); }
  450. ImPlotPoint Size() const { return ImPlotPoint(X.Size(), Y.Size()); }
  451. ImPlotPoint Clamp(const ImPlotPoint& p) { return Clamp(p.x, p.y); }
  452. ImPlotPoint Clamp(double x, double y) { return ImPlotPoint(X.Clamp(x),Y.Clamp(y)); }
  453. ImPlotPoint Min() const { return ImPlotPoint(X.Min, Y.Min); }
  454. ImPlotPoint Max() const { return ImPlotPoint(X.Max, Y.Max); }
  455. };
  456. // Plot style structure
  457. struct ImPlotStyle {
  458. // item styling variables
  459. float LineWeight; // = 1, item line weight in pixels
  460. int Marker; // = ImPlotMarker_None, marker specification
  461. float MarkerSize; // = 4, marker size in pixels (roughly the marker's "radius")
  462. float MarkerWeight; // = 1, outline weight of markers in pixels
  463. float FillAlpha; // = 1, alpha modifier applied to plot fills
  464. float ErrorBarSize; // = 5, error bar whisker width in pixels
  465. float ErrorBarWeight; // = 1.5, error bar whisker weight in pixels
  466. float DigitalBitHeight; // = 8, digital channels bit height (at y = 1.0f) in pixels
  467. float DigitalBitGap; // = 4, digital channels bit padding gap in pixels
  468. // plot styling variables
  469. float PlotBorderSize; // = 1, line thickness of border around plot area
  470. float MinorAlpha; // = 0.25 alpha multiplier applied to minor axis grid lines
  471. ImVec2 MajorTickLen; // = 10,10 major tick lengths for X and Y axes
  472. ImVec2 MinorTickLen; // = 5,5 minor tick lengths for X and Y axes
  473. ImVec2 MajorTickSize; // = 1,1 line thickness of major ticks
  474. ImVec2 MinorTickSize; // = 1,1 line thickness of minor ticks
  475. ImVec2 MajorGridSize; // = 1,1 line thickness of major grid lines
  476. ImVec2 MinorGridSize; // = 1,1 line thickness of minor grid lines
  477. ImVec2 PlotPadding; // = 10,10 padding between widget frame and plot area, labels, or outside legends (i.e. main padding)
  478. ImVec2 LabelPadding; // = 5,5 padding between axes labels, tick labels, and plot edge
  479. ImVec2 LegendPadding; // = 10,10 legend padding from plot edges
  480. ImVec2 LegendInnerPadding; // = 5,5 legend inner padding from legend edges
  481. ImVec2 LegendSpacing; // = 5,0 spacing between legend entries
  482. ImVec2 MousePosPadding; // = 10,10 padding between plot edge and interior mouse location text
  483. ImVec2 AnnotationPadding; // = 2,2 text padding around annotation labels
  484. 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)
  485. ImVec2 PlotDefaultSize; // = 400,300 default size used when ImVec2(0,0) is passed to BeginPlot
  486. ImVec2 PlotMinSize; // = 200,150 minimum size plot frame can be when shrunk
  487. // style colors
  488. ImVec4 Colors[ImPlotCol_COUNT]; // Array of styling colors. Indexable with ImPlotCol_ enums.
  489. // colormap
  490. ImPlotColormap Colormap; // The current colormap. Set this to either an ImPlotColormap_ enum or an index returned by AddColormap.
  491. // settings/flags
  492. bool UseLocalTime; // = false, axis labels will be formatted for your timezone when ImPlotAxisFlag_Time is enabled
  493. bool UseISO8601; // = false, dates will be formatted according to ISO 8601 where applicable (e.g. YYYY-MM-DD, YYYY-MM, --MM-DD, etc.)
  494. bool Use24HourClock; // = false, times will be formatted using a 24 hour clock
  495. IMPLOT_API ImPlotStyle();
  496. };
  497. // Support for legacy versions
  498. #if (IMGUI_VERSION_NUM < 18716) // Renamed in 1.88
  499. #define ImGuiMod_None 0
  500. #define ImGuiMod_Ctrl ImGuiKeyModFlags_Ctrl
  501. #define ImGuiMod_Shift ImGuiKeyModFlags_Shift
  502. #define ImGuiMod_Alt ImGuiKeyModFlags_Alt
  503. #define ImGuiMod_Super ImGuiKeyModFlags_Super
  504. #elif (IMGUI_VERSION_NUM < 18823) // Renamed in 1.89, sorry
  505. #define ImGuiMod_None 0
  506. #define ImGuiMod_Ctrl ImGuiModFlags_Ctrl
  507. #define ImGuiMod_Shift ImGuiModFlags_Shift
  508. #define ImGuiMod_Alt ImGuiModFlags_Alt
  509. #define ImGuiMod_Super ImGuiModFlags_Super
  510. #endif
  511. // Input mapping structure. Default values listed. See also MapInputDefault, MapInputReverse.
  512. struct ImPlotInputMap {
  513. ImGuiMouseButton Pan; // LMB enables panning when held,
  514. int PanMod; // none optional modifier that must be held for panning/fitting
  515. ImGuiMouseButton Fit; // LMB initiates fit when double clicked
  516. ImGuiMouseButton Select; // RMB begins box selection when pressed and confirms selection when released
  517. ImGuiMouseButton SelectCancel; // LMB cancels active box selection when pressed; cannot be same as Select
  518. int SelectMod; // none optional modifier that must be held for box selection
  519. int SelectHorzMod; // Alt expands active box selection horizontally to plot edge when held
  520. int SelectVertMod; // Shift expands active box selection vertically to plot edge when held
  521. ImGuiMouseButton Menu; // RMB opens context menus (if enabled) when clicked
  522. int OverrideMod; // Ctrl when held, all input is ignored; used to enable axis/plots as DND sources
  523. int ZoomMod; // none optional modifier that must be held for scroll wheel zooming
  524. float ZoomRate; // 0.1f zoom rate for scroll (e.g. 0.1f = 10% plot range every scroll click); make negative to invert
  525. IMPLOT_API ImPlotInputMap();
  526. };
  527. //-----------------------------------------------------------------------------
  528. // [SECTION] Callbacks
  529. //-----------------------------------------------------------------------------
  530. // Callback signature for axis tick label formatter.
  531. typedef int (*ImPlotFormatter)(double value, char* buff, int size, void* user_data);
  532. // Callback signature for data getter.
  533. typedef ImPlotPoint (*ImPlotGetter)(int idx, void* user_data);
  534. // Callback signature for axis transform.
  535. typedef double (*ImPlotTransform)(double value, void* user_data);
  536. namespace ImPlot {
  537. //-----------------------------------------------------------------------------
  538. // [SECTION] Contexts
  539. //-----------------------------------------------------------------------------
  540. // Creates a new ImPlot context. Call this after ImGui::CreateContext.
  541. IMPLOT_API ImPlotContext* CreateContext();
  542. // Destroys an ImPlot context. Call this before ImGui::DestroyContext. nullptr = destroy current context.
  543. IMPLOT_API void DestroyContext(ImPlotContext* ctx = nullptr);
  544. // Returns the current ImPlot context. nullptr if no context has ben set.
  545. IMPLOT_API ImPlotContext* GetCurrentContext();
  546. // Sets the current ImPlot context.
  547. IMPLOT_API void SetCurrentContext(ImPlotContext* ctx);
  548. // Sets the current **ImGui** context. This is ONLY necessary if you are compiling
  549. // ImPlot as a DLL (not recommended) separate from your ImGui compilation. It
  550. // sets the global variable GImGui, which is not shared across DLL boundaries.
  551. // See GImGui documentation in imgui.cpp for more details.
  552. IMPLOT_API void SetImGuiContext(ImGuiContext* ctx);
  553. //-----------------------------------------------------------------------------
  554. // [SECTION] Begin/End Plot
  555. //-----------------------------------------------------------------------------
  556. // Starts a 2D plotting context. If this function returns true, EndPlot() MUST
  557. // be called! You are encouraged to use the following convention:
  558. //
  559. // if (BeginPlot(...)) {
  560. // PlotLine(...);
  561. // ...
  562. // EndPlot();
  563. // }
  564. //
  565. // Important notes:
  566. //
  567. // - #title_id must be unique to the current ImGui ID scope. If you need to avoid ID
  568. // collisions or don't want to display a title in the plot, use double hashes
  569. // (e.g. "MyPlot##HiddenIdText" or "##NoTitle").
  570. // - #size is the **frame** size of the plot widget, not the plot area. The default
  571. // size of plots (i.e. when ImVec2(0,0)) can be modified in your ImPlotStyle.
  572. IMPLOT_API bool BeginPlot(const char* title_id, const ImVec2& size=ImVec2(-1,0), ImPlotFlags flags=0);
  573. // Only call EndPlot() if BeginPlot() returns true! Typically called at the end
  574. // of an if statement conditioned on BeginPlot(). See example above.
  575. IMPLOT_API void EndPlot();
  576. //-----------------------------------------------------------------------------
  577. // [SECTION] Begin/End Subplots
  578. //-----------------------------------------------------------------------------
  579. // Starts a subdivided plotting context. If the function returns true,
  580. // EndSubplots() MUST be called! Call BeginPlot/EndPlot AT MOST [rows*cols]
  581. // times in between the begining and end of the subplot context. Plots are
  582. // added in row major order.
  583. //
  584. // Example:
  585. //
  586. // if (BeginSubplots("My Subplot",2,3,ImVec2(800,400)) {
  587. // for (int i = 0; i < 6; ++i) {
  588. // if (BeginPlot(...)) {
  589. // ImPlot::PlotLine(...);
  590. // ...
  591. // EndPlot();
  592. // }
  593. // }
  594. // EndSubplots();
  595. // }
  596. //
  597. // Produces:
  598. //
  599. // [0] | [1] | [2]
  600. // ----|-----|----
  601. // [3] | [4] | [5]
  602. //
  603. // Important notes:
  604. //
  605. // - #title_id must be unique to the current ImGui ID scope. If you need to avoid ID
  606. // collisions or don't want to display a title in the plot, use double hashes
  607. // (e.g. "MySubplot##HiddenIdText" or "##NoTitle").
  608. // - #rows and #cols must be greater than 0.
  609. // - #size is the size of the entire grid of subplots, not the individual plots
  610. // - #row_ratios and #col_ratios must have AT LEAST #rows and #cols elements,
  611. // respectively. These are the sizes of the rows and columns expressed in ratios.
  612. // If the user adjusts the dimensions, the arrays are updated with new ratios.
  613. //
  614. // Important notes regarding BeginPlot from inside of BeginSubplots:
  615. //
  616. // - The #title_id parameter of _BeginPlot_ (see above) does NOT have to be
  617. // unique when called inside of a subplot context. Subplot IDs are hashed
  618. // for your convenience so you don't have call PushID or generate unique title
  619. // strings. Simply pass an empty string to BeginPlot unless you want to title
  620. // each subplot.
  621. // - The #size parameter of _BeginPlot_ (see above) is ignored when inside of a
  622. // subplot context. The actual size of the subplot will be based on the
  623. // #size value you pass to _BeginSubplots_ and #row/#col_ratios if provided.
  624. IMPLOT_API bool BeginSubplots(const char* title_id,
  625. int rows,
  626. int cols,
  627. const ImVec2& size,
  628. ImPlotSubplotFlags flags = 0,
  629. float* row_ratios = nullptr,
  630. float* col_ratios = nullptr);
  631. // Only call EndSubplots() if BeginSubplots() returns true! Typically called at the end
  632. // of an if statement conditioned on BeginSublots(). See example above.
  633. IMPLOT_API void EndSubplots();
  634. //-----------------------------------------------------------------------------
  635. // [SECTION] Setup
  636. //-----------------------------------------------------------------------------
  637. // The following API allows you to setup and customize various aspects of the
  638. // current plot. The functions should be called immediately after BeginPlot
  639. // and before any other API calls. Typical usage is as follows:
  640. // if (BeginPlot(...)) { 1) begin a new plot
  641. // SetupAxis(ImAxis_X1, "My X-Axis"); 2) make Setup calls
  642. // SetupAxis(ImAxis_Y1, "My Y-Axis");
  643. // SetupLegend(ImPlotLocation_North);
  644. // ...
  645. // SetupFinish(); 3) [optional] explicitly finish setup
  646. // PlotLine(...); 4) plot items
  647. // ...
  648. // EndPlot(); 5) end the plot
  649. // }
  650. //
  651. // Important notes:
  652. //
  653. // - Always call Setup code at the top of your BeginPlot conditional statement.
  654. // - Setup is locked once you start plotting or explicitly call SetupFinish.
  655. // Do NOT call Setup code after you begin plotting or after you make
  656. // any non-Setup API calls (e.g. utils like PlotToPixels also lock Setup)
  657. // - Calling SetupFinish is OPTIONAL, but probably good practice. If you do not
  658. // call it yourself, then the first subsequent plotting or utility function will
  659. // call it for you.
  660. // Enables an axis or sets the label and/or flags for an existing axis. Leave #label = nullptr for no label.
  661. IMPLOT_API void SetupAxis(ImAxis axis, const char* label=nullptr, ImPlotAxisFlags flags=0);
  662. // Sets an axis range limits. If ImPlotCond_Always is used, the axes limits will be locked. Inversion with v_min > v_max is not supported; use SetupAxisLimits instead.
  663. IMPLOT_API void SetupAxisLimits(ImAxis axis, double v_min, double v_max, ImPlotCond cond = ImPlotCond_Once);
  664. // Links an axis range limits to external values. Set to nullptr for no linkage. The pointer data must remain valid until EndPlot.
  665. IMPLOT_API void SetupAxisLinks(ImAxis axis, double* link_min, double* link_max);
  666. // Sets the format of numeric axis labels via formater specifier (default="%g"). Formated values will be double (i.e. use %f).
  667. IMPLOT_API void SetupAxisFormat(ImAxis axis, const char* fmt);
  668. // Sets the format of numeric axis labels via formatter callback. Given #value, write a label into #buff. Optionally pass user data.
  669. IMPLOT_API void SetupAxisFormat(ImAxis axis, ImPlotFormatter formatter, void* data=nullptr);
  670. // Sets an axis' ticks and optionally the labels. To keep the default ticks, set #keep_default=true.
  671. IMPLOT_API void SetupAxisTicks(ImAxis axis, const double* values, int n_ticks, const char* const labels[]=nullptr, bool keep_default=false);
  672. // Sets an axis' ticks and optionally the labels for the next plot. To keep the default ticks, set #keep_default=true.
  673. IMPLOT_API void SetupAxisTicks(ImAxis axis, double v_min, double v_max, int n_ticks, const char* const labels[]=nullptr, bool keep_default=false);
  674. // Sets an axis' scale using built-in options.
  675. IMPLOT_API void SetupAxisScale(ImAxis axis, ImPlotScale scale);
  676. // Sets an axis' scale using user supplied forward and inverse transfroms.
  677. IMPLOT_API void SetupAxisScale(ImAxis axis, ImPlotTransform forward, ImPlotTransform inverse, void* data=nullptr);
  678. // Sets an axis' limits constraints.
  679. IMPLOT_API void SetupAxisLimitsConstraints(ImAxis axis, double v_min, double v_max);
  680. // Sets an axis' zoom constraints.
  681. IMPLOT_API void SetupAxisZoomConstraints(ImAxis axis, double z_min, double z_max);
  682. // Sets the label and/or flags for primary X and Y axes (shorthand for two calls to SetupAxis).
  683. IMPLOT_API void SetupAxes(const char* x_label, const char* y_label, ImPlotAxisFlags x_flags=0, ImPlotAxisFlags y_flags=0);
  684. // Sets the primary X and Y axes range limits. If ImPlotCond_Always is used, the axes limits will be locked (shorthand for two calls to SetupAxisLimits).
  685. IMPLOT_API void SetupAxesLimits(double x_min, double x_max, double y_min, double y_max, ImPlotCond cond = ImPlotCond_Once);
  686. // Sets up the plot legend. This can also be called immediately after BeginSubplots when using ImPlotSubplotFlags_ShareItems.
  687. IMPLOT_API void SetupLegend(ImPlotLocation location, ImPlotLegendFlags flags=0);
  688. // Set the location of the current plot's mouse position text (default = South|East).
  689. IMPLOT_API void SetupMouseText(ImPlotLocation location, ImPlotMouseTextFlags flags=0);
  690. // Explicitly finalize plot setup. Once you call this, you cannot make anymore Setup calls for the current plot!
  691. // Note that calling this function is OPTIONAL; it will be called by the first subsequent setup-locking API call.
  692. IMPLOT_API void SetupFinish();
  693. //-----------------------------------------------------------------------------
  694. // [SECTION] SetNext
  695. //-----------------------------------------------------------------------------
  696. // Though you should default to the `Setup` API above, there are some scenarios
  697. // where (re)configuring a plot or axis before `BeginPlot` is needed (e.g. if
  698. // using a preceding button or slider widget to change the plot limits). In
  699. // this case, you can use the `SetNext` API below. While this is not as feature
  700. // rich as the Setup API, most common needs are provided. These functions can be
  701. // called anwhere except for inside of `Begin/EndPlot`. For example:
  702. // if (ImGui::Button("Center Plot"))
  703. // ImPlot::SetNextPlotLimits(-1,1,-1,1);
  704. // if (ImPlot::BeginPlot(...)) {
  705. // ...
  706. // ImPlot::EndPlot();
  707. // }
  708. //
  709. // Important notes:
  710. //
  711. // - You must still enable non-default axes with SetupAxis for these functions
  712. // to work properly.
  713. // Sets an upcoming axis range limits. If ImPlotCond_Always is used, the axes limits will be locked.
  714. IMPLOT_API void SetNextAxisLimits(ImAxis axis, double v_min, double v_max, ImPlotCond cond = ImPlotCond_Once);
  715. // Links an upcoming axis range limits to external values. Set to nullptr for no linkage. The pointer data must remain valid until EndPlot!
  716. IMPLOT_API void SetNextAxisLinks(ImAxis axis, double* link_min, double* link_max);
  717. // Set an upcoming axis to auto fit to its data.
  718. IMPLOT_API void SetNextAxisToFit(ImAxis axis);
  719. // Sets the upcoming primary X and Y axes range limits. If ImPlotCond_Always is used, the axes limits will be locked (shorthand for two calls to SetupAxisLimits).
  720. IMPLOT_API void SetNextAxesLimits(double x_min, double x_max, double y_min, double y_max, ImPlotCond cond = ImPlotCond_Once);
  721. // Sets all upcoming axes to auto fit to their data.
  722. IMPLOT_API void SetNextAxesToFit();
  723. //-----------------------------------------------------------------------------
  724. // [SECTION] Plot Items
  725. //-----------------------------------------------------------------------------
  726. // The main plotting API is provied below. Call these functions between
  727. // Begin/EndPlot and after any Setup API calls. Each plots data on the current
  728. // x and y axes, which can be changed with `SetAxis/Axes`.
  729. //
  730. // The templated functions are explicitly instantiated in implot_items.cpp.
  731. // They are not intended to be used generically with custom types. You will get
  732. // a linker error if you try! All functions support the following scalar types:
  733. //
  734. // float, double, ImS8, ImU8, ImS16, ImU16, ImS32, ImU32, ImS64, ImU64
  735. //
  736. //
  737. // If you need to plot custom or non-homogenous data you have a few options:
  738. //
  739. // 1. If your data is a simple struct/class (e.g. Vector2f), you can use striding.
  740. // This is the most performant option if applicable.
  741. //
  742. // struct Vector2f { float X, Y; };
  743. // ...
  744. // Vector2f data[42];
  745. // ImPlot::PlotLine("line", &data[0].x, &data[0].y, 42, 0, 0, sizeof(Vector2f));
  746. //
  747. // 2. Write a custom getter C function or C++ lambda and pass it and optionally your data to
  748. // an ImPlot function post-fixed with a G (e.g. PlotScatterG). This has a slight performance
  749. // cost, but probably not enough to worry about unless your data is very large. Examples:
  750. //
  751. // ImPlotPoint MyDataGetter(int idx, void* data) {
  752. // MyData* my_data = (MyData*)data;
  753. // ImPlotPoint p;
  754. // p.x = my_data->GetTime(idx);
  755. // p.y = my_data->GetValue(idx);
  756. // return p
  757. // }
  758. // ...
  759. // auto my_lambda = [](int idx, void*) {
  760. // double t = idx / 999.0;
  761. // return ImPlotPoint(t, 0.5+0.5*std::sin(2*PI*10*t));
  762. // };
  763. // ...
  764. // if (ImPlot::BeginPlot("MyPlot")) {
  765. // MyData my_data;
  766. // ImPlot::PlotScatterG("scatter", MyDataGetter, &my_data, my_data.Size());
  767. // ImPlot::PlotLineG("line", my_lambda, nullptr, 1000);
  768. // ImPlot::EndPlot();
  769. // }
  770. //
  771. // NB: All types are converted to double before plotting. You may lose information
  772. // if you try plotting extremely large 64-bit integral types. Proceed with caution!
  773. // Plots a standard 2D line plot.
  774. IMPLOT_TMP void PlotLine(const char* label_id, const T* values, int count, double xscale=1, double xstart=0, ImPlotLineFlags flags=0, int offset=0, int stride=sizeof(T));
  775. IMPLOT_TMP void PlotLine(const char* label_id, const T* xs, const T* ys, int count, ImPlotLineFlags flags=0, int offset=0, int stride=sizeof(T));
  776. IMPLOT_API void PlotLineG(const char* label_id, ImPlotGetter getter, void* data, int count, ImPlotLineFlags flags=0);
  777. // Plots a standard 2D scatter plot. Default marker is ImPlotMarker_Circle.
  778. IMPLOT_TMP void PlotScatter(const char* label_id, const T* values, int count, double xscale=1, double xstart=0, ImPlotScatterFlags flags=0, int offset=0, int stride=sizeof(T));
  779. IMPLOT_TMP void PlotScatter(const char* label_id, const T* xs, const T* ys, int count, ImPlotScatterFlags flags=0, int offset=0, int stride=sizeof(T));
  780. IMPLOT_API void PlotScatterG(const char* label_id, ImPlotGetter getter, void* data, int count, ImPlotScatterFlags flags=0);
  781. // Plots a a stairstep graph. The y value is continued constantly to the right from every x position, i.e. the interval [x[i], x[i+1]) has the value y[i]
  782. IMPLOT_TMP void PlotStairs(const char* label_id, const T* values, int count, double xscale=1, double xstart=0, ImPlotStairsFlags flags=0, int offset=0, int stride=sizeof(T));
  783. IMPLOT_TMP void PlotStairs(const char* label_id, const T* xs, const T* ys, int count, ImPlotStairsFlags flags=0, int offset=0, int stride=sizeof(T));
  784. IMPLOT_API void PlotStairsG(const char* label_id, ImPlotGetter getter, void* data, int count, ImPlotStairsFlags flags=0);
  785. // Plots a shaded (filled) region between two lines, or a line and a horizontal reference. Set yref to +/-INFINITY for infinite fill extents.
  786. IMPLOT_TMP void PlotShaded(const char* label_id, const T* values, int count, double yref=0, double xscale=1, double xstart=0, ImPlotShadedFlags flags=0, int offset=0, int stride=sizeof(T));
  787. IMPLOT_TMP void PlotShaded(const char* label_id, const T* xs, const T* ys, int count, double yref=0, ImPlotShadedFlags flags=0, int offset=0, int stride=sizeof(T));
  788. IMPLOT_TMP void PlotShaded(const char* label_id, const T* xs, const T* ys1, const T* ys2, int count, ImPlotShadedFlags flags=0, int offset=0, int stride=sizeof(T));
  789. IMPLOT_API void PlotShadedG(const char* label_id, ImPlotGetter getter1, void* data1, ImPlotGetter getter2, void* data2, int count, ImPlotShadedFlags flags=0);
  790. // Plots a bar graph. Vertical by default. #bar_size and #shift are in plot units.
  791. IMPLOT_TMP void PlotBars(const char* label_id, const T* values, int count, double bar_size=0.67, double shift=0, ImPlotBarsFlags flags=0, int offset=0, int stride=sizeof(T));
  792. IMPLOT_TMP void PlotBars(const char* label_id, const T* xs, const T* ys, int count, double bar_size, ImPlotBarsFlags flags=0, int offset=0, int stride=sizeof(T));
  793. IMPLOT_API void PlotBarsG(const char* label_id, ImPlotGetter getter, void* data, int count, double bar_size, ImPlotBarsFlags flags=0);
  794. // Plots a group of bars. #values is a row-major matrix with #item_count rows and #group_count cols. #label_ids should have #item_count elements.
  795. IMPLOT_TMP void PlotBarGroups(const char* const label_ids[], const T* values, int item_count, int group_count, double group_size=0.67, double shift=0, ImPlotBarGroupsFlags flags=0);
  796. // Plots vertical error bar. The label_id should be the same as the label_id of the associated line or bar plot.
  797. IMPLOT_TMP void PlotErrorBars(const char* label_id, const T* xs, const T* ys, const T* err, int count, ImPlotErrorBarsFlags flags=0, int offset=0, int stride=sizeof(T));
  798. IMPLOT_TMP void PlotErrorBars(const char* label_id, const T* xs, const T* ys, const T* neg, const T* pos, int count, ImPlotErrorBarsFlags flags=0, int offset=0, int stride=sizeof(T));
  799. // Plots stems. Vertical by default.
  800. IMPLOT_TMP void PlotStems(const char* label_id, const T* values, int count, double ref=0, double scale=1, double start=0, ImPlotStemsFlags flags=0, int offset=0, int stride=sizeof(T));
  801. IMPLOT_TMP void PlotStems(const char* label_id, const T* xs, const T* ys, int count, double ref=0, ImPlotStemsFlags flags=0, int offset=0, int stride=sizeof(T));
  802. // Plots infinite vertical or horizontal lines (e.g. for references or asymptotes).
  803. IMPLOT_TMP void PlotInfLines(const char* label_id, const T* values, int count, ImPlotInfLinesFlags flags=0, int offset=0, int stride=sizeof(T));
  804. // Plots a pie chart. Center and radius are in plot units. #label_fmt can be set to nullptr for no labels.
  805. IMPLOT_TMP void PlotPieChart(const char* const label_ids[], const T* values, int count, double x, double y, double radius, ImPlotFormatter fmt, void* fmt_data=nullptr, double angle0=90, ImPlotPieChartFlags flags=0);
  806. IMPLOT_TMP void PlotPieChart(const char* const label_ids[], const T* values, int count, double x, double y, double radius, const char* label_fmt="%.1f", double angle0=90, ImPlotPieChartFlags flags=0);
  807. // Plots a 2D heatmap chart. Values are expected to be in row-major order by default. 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 nullptr for no labels.
  808. IMPLOT_TMP 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), ImPlotHeatmapFlags flags=0);
  809. // Plots a horizontal histogram. #bins can be a positive integer or an ImPlotBin_ method. If #range is left unspecified, the min/max of #values will be used as the range.
  810. // Otherwise, outlier values outside of the range are not binned. The largest bin count or density is returned.
  811. IMPLOT_TMP double PlotHistogram(const char* label_id, const T* values, int count, int bins=ImPlotBin_Sturges, double bar_scale=1.0, ImPlotRange range=ImPlotRange(), ImPlotHistogramFlags flags=0);
  812. // Plots two dimensional, bivariate histogram as a heatmap. #x_bins and #y_bins can be a positive integer or an ImPlotBin. If #range is left unspecified, the min/max of
  813. // #xs an #ys will be used as the ranges. Otherwise, outlier values outside of range are not binned. The largest bin count or density is returned.
  814. IMPLOT_TMP double PlotHistogram2D(const char* label_id, const T* xs, const T* ys, int count, int x_bins=ImPlotBin_Sturges, int y_bins=ImPlotBin_Sturges, ImPlotRect range=ImPlotRect(), ImPlotHistogramFlags flags=0);
  815. // Plots digital data. Digital plots do not respond to y drag or zoom, and are always referenced to the bottom of the plot.
  816. IMPLOT_TMP void PlotDigital(const char* label_id, const T* xs, const T* ys, int count, ImPlotDigitalFlags flags=0, int offset=0, int stride=sizeof(T));
  817. IMPLOT_API void PlotDigitalG(const char* label_id, ImPlotGetter getter, void* data, int count, ImPlotDigitalFlags flags=0);
  818. // Plots an axis-aligned image. #bounds_min/bounds_max are in plot coordinates (y-up) and #uv0/uv1 are in texture coordinates (y-down).
  819. #ifdef IMGUI_HAS_TEXTURES
  820. IMPLOT_API void PlotImage(const char* label_id, ImTextureRef tex_ref, 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), ImPlotImageFlags flags = 0);
  821. #else
  822. IMPLOT_API void PlotImage(const char* label_id, ImTextureID tex_ref, 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), ImPlotImageFlags flags=0);
  823. #endif
  824. // Plots a centered text label at point x,y with an optional pixel offset. Text color can be changed with ImPlot::PushStyleColor(ImPlotCol_InlayText, ...).
  825. IMPLOT_API void PlotText(const char* text, double x, double y, const ImVec2& pix_offset=ImVec2(0,0), ImPlotTextFlags flags=0);
  826. // Plots a dummy item (i.e. adds a legend entry colored by ImPlotCol_Line)
  827. IMPLOT_API void PlotDummy(const char* label_id, ImPlotDummyFlags flags=0);
  828. //-----------------------------------------------------------------------------
  829. // [SECTION] Plot Tools
  830. //-----------------------------------------------------------------------------
  831. // The following can be used to render interactive elements and/or annotations.
  832. // Like the item plotting functions above, they apply to the current x and y
  833. // axes, which can be changed with `SetAxis/SetAxes`. These functions return true
  834. // when user interaction causes the provided coordinates to change. Additional
  835. // user interactions can be retrieved through the optional output parameters.
  836. // Shows a draggable point at x,y. #col defaults to ImGuiCol_Text.
  837. IMPLOT_API bool DragPoint(int id, double* x, double* y, const ImVec4& col, float size = 4, ImPlotDragToolFlags flags = 0, bool* out_clicked = nullptr, bool* out_hovered = nullptr, bool* held = nullptr);
  838. // Shows a draggable vertical guide line at an x-value. #col defaults to ImGuiCol_Text.
  839. IMPLOT_API bool DragLineX(int id, double* x, const ImVec4& col, float thickness = 1, ImPlotDragToolFlags flags = 0, bool* out_clicked = nullptr, bool* out_hovered = nullptr, bool* held = nullptr);
  840. // Shows a draggable horizontal guide line at a y-value. #col defaults to ImGuiCol_Text.
  841. IMPLOT_API bool DragLineY(int id, double* y, const ImVec4& col, float thickness = 1, ImPlotDragToolFlags flags = 0, bool* out_clicked = nullptr, bool* out_hovered = nullptr, bool* held = nullptr);
  842. // Shows a draggable and resizeable rectangle.
  843. IMPLOT_API bool DragRect(int id, double* x1, double* y1, double* x2, double* y2, const ImVec4& col, ImPlotDragToolFlags flags = 0, bool* out_clicked = nullptr, bool* out_hovered = nullptr, bool* held = nullptr);
  844. // Shows an annotation callout at a chosen point. Clamping keeps annotations in the plot area. Annotations are always rendered on top.
  845. IMPLOT_API void Annotation(double x, double y, const ImVec4& col, const ImVec2& pix_offset, bool clamp, bool round = false);
  846. IMPLOT_API void Annotation(double x, double y, const ImVec4& col, const ImVec2& pix_offset, bool clamp, const char* fmt, ...) IM_FMTARGS(6);
  847. IMPLOT_API void AnnotationV(double x, double y, const ImVec4& col, const ImVec2& pix_offset, bool clamp, const char* fmt, va_list args) IM_FMTLIST(6);
  848. // Shows a x-axis tag at the specified coordinate value.
  849. IMPLOT_API void TagX(double x, const ImVec4& col, bool round = false);
  850. IMPLOT_API void TagX(double x, const ImVec4& col, const char* fmt, ...) IM_FMTARGS(3);
  851. IMPLOT_API void TagXV(double x, const ImVec4& col, const char* fmt, va_list args) IM_FMTLIST(3);
  852. // Shows a y-axis tag at the specified coordinate value.
  853. IMPLOT_API void TagY(double y, const ImVec4& col, bool round = false);
  854. IMPLOT_API void TagY(double y, const ImVec4& col, const char* fmt, ...) IM_FMTARGS(3);
  855. IMPLOT_API void TagYV(double y, const ImVec4& col, const char* fmt, va_list args) IM_FMTLIST(3);
  856. //-----------------------------------------------------------------------------
  857. // [SECTION] Plot Utils
  858. //-----------------------------------------------------------------------------
  859. // Select which axis/axes will be used for subsequent plot elements.
  860. IMPLOT_API void SetAxis(ImAxis axis);
  861. IMPLOT_API void SetAxes(ImAxis x_axis, ImAxis y_axis);
  862. // Convert pixels to a position in the current plot's coordinate system. Passing IMPLOT_AUTO uses the current axes.
  863. IMPLOT_API ImPlotPoint PixelsToPlot(const ImVec2& pix, ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis = IMPLOT_AUTO);
  864. IMPLOT_API ImPlotPoint PixelsToPlot(float x, float y, ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis = IMPLOT_AUTO);
  865. // Convert a position in the current plot's coordinate system to pixels. Passing IMPLOT_AUTO uses the current axes.
  866. IMPLOT_API ImVec2 PlotToPixels(const ImPlotPoint& plt, ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis = IMPLOT_AUTO);
  867. IMPLOT_API ImVec2 PlotToPixels(double x, double y, ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis = IMPLOT_AUTO);
  868. // Get the current Plot position (top-left) in pixels.
  869. IMPLOT_API ImVec2 GetPlotPos();
  870. // Get the curent Plot size in pixels.
  871. IMPLOT_API ImVec2 GetPlotSize();
  872. // Returns the mouse position in x,y coordinates of the current plot. Passing IMPLOT_AUTO uses the current axes.
  873. IMPLOT_API ImPlotPoint GetPlotMousePos(ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis = IMPLOT_AUTO);
  874. // Returns the current plot axis range.
  875. IMPLOT_API ImPlotRect GetPlotLimits(ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis = IMPLOT_AUTO);
  876. // Returns true if the plot area in the current plot is hovered.
  877. IMPLOT_API bool IsPlotHovered();
  878. // Returns true if the axis label area in the current plot is hovered.
  879. IMPLOT_API bool IsAxisHovered(ImAxis axis);
  880. // Returns true if the bounding frame of a subplot is hovered.
  881. IMPLOT_API bool IsSubplotsHovered();
  882. // Returns true if the current plot is being box selected.
  883. IMPLOT_API bool IsPlotSelected();
  884. // Returns the current plot box selection bounds. Passing IMPLOT_AUTO uses the current axes.
  885. IMPLOT_API ImPlotRect GetPlotSelection(ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis = IMPLOT_AUTO);
  886. // Cancels a the current plot box selection.
  887. IMPLOT_API void CancelPlotSelection();
  888. // Hides or shows the next plot item (i.e. as if it were toggled from the legend).
  889. // Use ImPlotCond_Always if you need to forcefully set this every frame.
  890. IMPLOT_API void HideNextItem(bool hidden = true, ImPlotCond cond = ImPlotCond_Once);
  891. // Use the following around calls to Begin/EndPlot to align l/r/t/b padding.
  892. // Consider using Begin/EndSubplots first. They are more feature rich and
  893. // accomplish the same behaviour by default. The functions below offer lower
  894. // level control of plot alignment.
  895. // Align axis padding over multiple plots in a single row or column. #group_id must
  896. // be unique. If this function returns true, EndAlignedPlots() must be called.
  897. IMPLOT_API bool BeginAlignedPlots(const char* group_id, bool vertical = true);
  898. // Only call EndAlignedPlots() if BeginAlignedPlots() returns true!
  899. IMPLOT_API void EndAlignedPlots();
  900. //-----------------------------------------------------------------------------
  901. // [SECTION] Legend Utils
  902. //-----------------------------------------------------------------------------
  903. // Begin a popup for a legend entry.
  904. IMPLOT_API bool BeginLegendPopup(const char* label_id, ImGuiMouseButton mouse_button=1);
  905. // End a popup for a legend entry.
  906. IMPLOT_API void EndLegendPopup();
  907. // Returns true if a plot item legend entry is hovered.
  908. IMPLOT_API bool IsLegendEntryHovered(const char* label_id);
  909. //-----------------------------------------------------------------------------
  910. // [SECTION] Drag and Drop
  911. //-----------------------------------------------------------------------------
  912. // Turns the current plot's plotting area into a drag and drop target. Don't forget to call EndDragDropTarget!
  913. IMPLOT_API bool BeginDragDropTargetPlot();
  914. // Turns the current plot's X-axis into a drag and drop target. Don't forget to call EndDragDropTarget!
  915. IMPLOT_API bool BeginDragDropTargetAxis(ImAxis axis);
  916. // Turns the current plot's legend into a drag and drop target. Don't forget to call EndDragDropTarget!
  917. IMPLOT_API bool BeginDragDropTargetLegend();
  918. // Ends a drag and drop target (currently just an alias for ImGui::EndDragDropTarget).
  919. IMPLOT_API void EndDragDropTarget();
  920. // NB: By default, plot and axes drag and drop *sources* require holding the Ctrl modifier to initiate the drag.
  921. // You can change the modifier if desired. If ImGuiMod_None is provided, the axes will be locked from panning.
  922. // Turns the current plot's plotting area into a drag and drop source. You must hold Ctrl. Don't forget to call EndDragDropSource!
  923. IMPLOT_API bool BeginDragDropSourcePlot(ImGuiDragDropFlags flags=0);
  924. // Turns the current plot's X-axis into a drag and drop source. You must hold Ctrl. Don't forget to call EndDragDropSource!
  925. IMPLOT_API bool BeginDragDropSourceAxis(ImAxis axis, ImGuiDragDropFlags flags=0);
  926. // Turns an item in the current plot's legend into drag and drop source. Don't forget to call EndDragDropSource!
  927. IMPLOT_API bool BeginDragDropSourceItem(const char* label_id, ImGuiDragDropFlags flags=0);
  928. // Ends a drag and drop source (currently just an alias for ImGui::EndDragDropSource).
  929. IMPLOT_API void EndDragDropSource();
  930. //-----------------------------------------------------------------------------
  931. // [SECTION] Styling
  932. //-----------------------------------------------------------------------------
  933. // Styling colors in ImPlot works similarly to styling colors in ImGui, but
  934. // with one important difference. Like ImGui, all style colors are stored in an
  935. // indexable array in ImPlotStyle. You can permanently modify these values through
  936. // GetStyle().Colors, or temporarily modify them with Push/Pop functions below.
  937. // However, by default all style colors in ImPlot default to a special color
  938. // IMPLOT_AUTO_COL. The behavior of this color depends upon the style color to
  939. // which it as applied:
  940. //
  941. // 1) For style colors associated with plot items (e.g. ImPlotCol_Line),
  942. // IMPLOT_AUTO_COL tells ImPlot to color the item with the next unused
  943. // color in the current colormap. Thus, every item will have a different
  944. // color up to the number of colors in the colormap, at which point the
  945. // colormap will roll over. For most use cases, you should not need to
  946. // set these style colors to anything but IMPLOT_COL_AUTO; you are
  947. // probably better off changing the current colormap. However, if you
  948. // need to explicitly color a particular item you may either Push/Pop
  949. // the style color around the item in question, or use the SetNextXXXStyle
  950. // API below. If you permanently set one of these style colors to a specific
  951. // color, or forget to call Pop, then all subsequent items will be styled
  952. // with the color you set.
  953. //
  954. // 2) For style colors associated with plot styling (e.g. ImPlotCol_PlotBg),
  955. // IMPLOT_AUTO_COL tells ImPlot to set that color from color data in your
  956. // **ImGuiStyle**. The ImGuiCol_ that these style colors default to are
  957. // detailed above, and in general have been mapped to produce plots visually
  958. // consistent with your current ImGui style. Of course, you are free to
  959. // manually set these colors to whatever you like, and further can Push/Pop
  960. // them around individual plots for plot-specific styling (e.g. coloring axes).
  961. // Provides access to plot style structure for permanant modifications to colors, sizes, etc.
  962. IMPLOT_API ImPlotStyle& GetStyle();
  963. // Style plot colors for current ImGui style (default).
  964. IMPLOT_API void StyleColorsAuto(ImPlotStyle* dst = nullptr);
  965. // Style plot colors for ImGui "Classic".
  966. IMPLOT_API void StyleColorsClassic(ImPlotStyle* dst = nullptr);
  967. // Style plot colors for ImGui "Dark".
  968. IMPLOT_API void StyleColorsDark(ImPlotStyle* dst = nullptr);
  969. // Style plot colors for ImGui "Light".
  970. IMPLOT_API void StyleColorsLight(ImPlotStyle* dst = nullptr);
  971. // Use PushStyleX to temporarily modify your ImPlotStyle. The modification
  972. // will last until the matching call to PopStyleX. You MUST call a pop for
  973. // every push, otherwise you will leak memory! This behaves just like ImGui.
  974. // Temporarily modify a style color. Don't forget to call PopStyleColor!
  975. IMPLOT_API void PushStyleColor(ImPlotCol idx, ImU32 col);
  976. IMPLOT_API void PushStyleColor(ImPlotCol idx, const ImVec4& col);
  977. // Undo temporary style color modification(s). Undo multiple pushes at once by increasing count.
  978. IMPLOT_API void PopStyleColor(int count = 1);
  979. // Temporarily modify a style variable of float type. Don't forget to call PopStyleVar!
  980. IMPLOT_API void PushStyleVar(ImPlotStyleVar idx, float val);
  981. // Temporarily modify a style variable of int type. Don't forget to call PopStyleVar!
  982. IMPLOT_API void PushStyleVar(ImPlotStyleVar idx, int val);
  983. // Temporarily modify a style variable of ImVec2 type. Don't forget to call PopStyleVar!
  984. IMPLOT_API void PushStyleVar(ImPlotStyleVar idx, const ImVec2& val);
  985. // Undo temporary style variable modification(s). Undo multiple pushes at once by increasing count.
  986. IMPLOT_API void PopStyleVar(int count = 1);
  987. // The following can be used to modify the style of the next plot item ONLY. They do
  988. // NOT require calls to PopStyleX. Leave style attributes you don't want modified to
  989. // IMPLOT_AUTO or IMPLOT_AUTO_COL. Automatic styles will be deduced from the current
  990. // values in your ImPlotStyle or from Colormap data.
  991. // Set the line color and weight for the next item only.
  992. IMPLOT_API void SetNextLineStyle(const ImVec4& col = IMPLOT_AUTO_COL, float weight = IMPLOT_AUTO);
  993. // Set the fill color for the next item only.
  994. IMPLOT_API void SetNextFillStyle(const ImVec4& col = IMPLOT_AUTO_COL, float alpha_mod = IMPLOT_AUTO);
  995. // Set the marker style for the next item only.
  996. 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);
  997. // Set the error bar style for the next item only.
  998. IMPLOT_API void SetNextErrorBarStyle(const ImVec4& col = IMPLOT_AUTO_COL, float size = IMPLOT_AUTO, float weight = IMPLOT_AUTO);
  999. // Gets the last item primary color (i.e. its legend icon color)
  1000. IMPLOT_API ImVec4 GetLastItemColor();
  1001. // Returns the null terminated string name for an ImPlotCol.
  1002. IMPLOT_API const char* GetStyleColorName(ImPlotCol idx);
  1003. // Returns the null terminated string name for an ImPlotMarker.
  1004. IMPLOT_API const char* GetMarkerName(ImPlotMarker idx);
  1005. //-----------------------------------------------------------------------------
  1006. // [SECTION] Colormaps
  1007. //-----------------------------------------------------------------------------
  1008. // Item styling is based on colormaps when the relevant ImPlotCol_XXX is set to
  1009. // IMPLOT_AUTO_COL (default). Several built-in colormaps are available. You can
  1010. // add and then push/pop your own colormaps as well. To permanently set a colormap,
  1011. // modify the Colormap index member of your ImPlotStyle.
  1012. // Colormap data will be ignored and a custom color will be used if you have done one of the following:
  1013. // 1) Modified an item style color in your ImPlotStyle to anything other than IMPLOT_AUTO_COL.
  1014. // 2) Pushed an item style color using PushStyleColor().
  1015. // 3) Set the next item style with a SetNextXXXStyle function.
  1016. // Add a new colormap. The color data will be copied. The colormap can be used by pushing either the returned index or the
  1017. // string name with PushColormap. The colormap name must be unique and the size must be greater than 1. You will receive
  1018. // an assert otherwise! By default colormaps are considered to be qualitative (i.e. discrete). If you want to create a
  1019. // continuous colormap, set #qual=false. This will treat the colors you provide as keys, and ImPlot will build a linearly
  1020. // interpolated lookup table. The memory footprint of this table will be exactly ((size-1)*255+1)*4 bytes.
  1021. IMPLOT_API ImPlotColormap AddColormap(const char* name, const ImVec4* cols, int size, bool qual=true);
  1022. IMPLOT_API ImPlotColormap AddColormap(const char* name, const ImU32* cols, int size, bool qual=true);
  1023. // Returns the number of available colormaps (i.e. the built-in + user-added count).
  1024. IMPLOT_API int GetColormapCount();
  1025. // Returns a null terminated string name for a colormap given an index. Returns nullptr if index is invalid.
  1026. IMPLOT_API const char* GetColormapName(ImPlotColormap cmap);
  1027. // Returns an index number for a colormap given a valid string name. Returns -1 if name is invalid.
  1028. IMPLOT_API ImPlotColormap GetColormapIndex(const char* name);
  1029. // 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!
  1030. IMPLOT_API void PushColormap(ImPlotColormap cmap);
  1031. // 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!
  1032. IMPLOT_API void PushColormap(const char* name);
  1033. // Undo temporary colormap modification(s). Undo multiple pushes at once by increasing count.
  1034. IMPLOT_API void PopColormap(int count = 1);
  1035. // Returns the next color from the current colormap and advances the colormap for the current plot.
  1036. // Can also be used with no return value to skip colors if desired. You need to call this between Begin/EndPlot!
  1037. IMPLOT_API ImVec4 NextColormapColor();
  1038. // Colormap utils. If cmap = IMPLOT_AUTO (default), the current colormap is assumed.
  1039. // Pass an explicit colormap index (built-in or user-added) to specify otherwise.
  1040. // Returns the size of a colormap.
  1041. IMPLOT_API int GetColormapSize(ImPlotColormap cmap = IMPLOT_AUTO);
  1042. // Returns a color from a colormap given an index >= 0 (modulo will be performed).
  1043. IMPLOT_API ImVec4 GetColormapColor(int idx, ImPlotColormap cmap = IMPLOT_AUTO);
  1044. // Sample a color from the current colormap given t between 0 and 1.
  1045. IMPLOT_API ImVec4 SampleColormap(float t, ImPlotColormap cmap = IMPLOT_AUTO);
  1046. // Shows a vertical color scale with linear spaced ticks using the specified color map. Use double hashes to hide label (e.g. "##NoLabel"). If scale_min > scale_max, the scale to color mapping will be reversed.
  1047. IMPLOT_API void ColormapScale(const char* label, double scale_min, double scale_max, const ImVec2& size = ImVec2(0,0), const char* format = "%g", ImPlotColormapScaleFlags flags = 0, ImPlotColormap cmap = IMPLOT_AUTO);
  1048. // Shows a horizontal slider with a colormap gradient background. Optionally returns the color sampled at t in [0 1].
  1049. IMPLOT_API bool ColormapSlider(const char* label, float* t, ImVec4* out = nullptr, const char* format = "", ImPlotColormap cmap = IMPLOT_AUTO);
  1050. // Shows a button with a colormap gradient brackground.
  1051. IMPLOT_API bool ColormapButton(const char* label, const ImVec2& size = ImVec2(0,0), ImPlotColormap cmap = IMPLOT_AUTO);
  1052. // When items in a plot sample their color from a colormap, the color is cached and does not change
  1053. // unless explicitly overriden. Therefore, if you change the colormap after the item has already been plotted,
  1054. // item colors will NOT update. If you need item colors to resample the new colormap, then use this
  1055. // function to bust the cached colors. If #plot_title_id is nullptr, then every item in EVERY existing plot
  1056. // will be cache busted. Otherwise only the plot specified by #plot_title_id will be busted. For the
  1057. // latter, this function must be called in the same ImGui ID scope that the plot is in. You should rarely if ever
  1058. // need this function, but it is available for applications that require runtime colormap swaps (e.g. Heatmaps demo).
  1059. IMPLOT_API void BustColorCache(const char* plot_title_id = nullptr);
  1060. //-----------------------------------------------------------------------------
  1061. // [SECTION] Input Mapping
  1062. //-----------------------------------------------------------------------------
  1063. // Provides access to input mapping structure for permanant modifications to controls for pan, select, etc.
  1064. IMPLOT_API ImPlotInputMap& GetInputMap();
  1065. // Default input mapping: pan = LMB drag, box select = RMB drag, fit = LMB double click, context menu = RMB click, zoom = scroll.
  1066. IMPLOT_API void MapInputDefault(ImPlotInputMap* dst = nullptr);
  1067. // Reverse input mapping: pan = RMB drag, box select = LMB drag, fit = LMB double click, context menu = RMB click, zoom = scroll.
  1068. IMPLOT_API void MapInputReverse(ImPlotInputMap* dst = nullptr);
  1069. //-----------------------------------------------------------------------------
  1070. // [SECTION] Miscellaneous
  1071. //-----------------------------------------------------------------------------
  1072. // Render icons similar to those that appear in legends (nifty for data lists).
  1073. IMPLOT_API void ItemIcon(const ImVec4& col);
  1074. IMPLOT_API void ItemIcon(ImU32 col);
  1075. IMPLOT_API void ColormapIcon(ImPlotColormap cmap);
  1076. // Get the plot draw list for custom rendering to the current plot area. Call between Begin/EndPlot.
  1077. IMPLOT_API ImDrawList* GetPlotDrawList();
  1078. // Push clip rect for rendering to current plot area. The rect can be expanded or contracted by #expand pixels. Call between Begin/EndPlot.
  1079. IMPLOT_API void PushPlotClipRect(float expand=0);
  1080. // Pop plot clip rect. Call between Begin/EndPlot.
  1081. IMPLOT_API void PopPlotClipRect();
  1082. // Shows ImPlot style selector dropdown menu.
  1083. IMPLOT_API bool ShowStyleSelector(const char* label);
  1084. // Shows ImPlot colormap selector dropdown menu.
  1085. IMPLOT_API bool ShowColormapSelector(const char* label);
  1086. // Shows ImPlot input map selector dropdown menu.
  1087. IMPLOT_API bool ShowInputMapSelector(const char* label);
  1088. // Shows ImPlot style editor block (not a window).
  1089. IMPLOT_API void ShowStyleEditor(ImPlotStyle* ref = nullptr);
  1090. // Add basic help/info block for end users (not a window).
  1091. IMPLOT_API void ShowUserGuide();
  1092. // Shows ImPlot metrics/debug information window.
  1093. IMPLOT_API void ShowMetricsWindow(bool* p_popen = nullptr);
  1094. //-----------------------------------------------------------------------------
  1095. // [SECTION] Demo
  1096. //-----------------------------------------------------------------------------
  1097. // Shows the ImPlot demo window (add implot_demo.cpp to your sources!)
  1098. IMPLOT_API void ShowDemoWindow(bool* p_open = nullptr);
  1099. } // namespace ImPlot
  1100. //-----------------------------------------------------------------------------
  1101. // [SECTION] Obsolete API
  1102. //-----------------------------------------------------------------------------
  1103. // The following functions will be removed! Keep your copy of implot up to date!
  1104. // Occasionally set '#define IMPLOT_DISABLE_OBSOLETE_FUNCTIONS' to stay ahead.
  1105. // If you absolutely must use these functions and do not want to receive compiler
  1106. // warnings, set '#define IMPLOT_DISABLE_OBSOLETE_WARNINGS'.
  1107. #ifndef IMPLOT_DISABLE_OBSOLETE_FUNCTIONS
  1108. #ifndef IMPLOT_DISABLE_DEPRECATED_WARNINGS
  1109. #if __cplusplus > 201402L
  1110. #define IMPLOT_DEPRECATED(method) [[deprecated]] method
  1111. #elif defined( __GNUC__ ) && !defined( __INTEL_COMPILER ) && ( __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) )
  1112. #define IMPLOT_DEPRECATED(method) method __attribute__( ( deprecated ) )
  1113. #elif defined( _MSC_VER )
  1114. #define IMPLOT_DEPRECATED(method) __declspec(deprecated) method
  1115. #else
  1116. #define IMPLOT_DEPRECATED(method) method
  1117. #endif
  1118. #else
  1119. #define IMPLOT_DEPRECATED(method) method
  1120. #endif
  1121. enum ImPlotFlagsObsolete_ {
  1122. ImPlotFlags_YAxis2 = 1 << 20,
  1123. ImPlotFlags_YAxis3 = 1 << 21,
  1124. };
  1125. namespace ImPlot {
  1126. // OBSOLETED in v0.13 -> PLANNED REMOVAL in v1.0
  1127. IMPLOT_DEPRECATED( IMPLOT_API bool BeginPlot(const char* title_id,
  1128. const char* x_label, // = nullptr,
  1129. const char* y_label, // = nullptr,
  1130. const ImVec2& size = ImVec2(-1,0),
  1131. ImPlotFlags flags = ImPlotFlags_None,
  1132. ImPlotAxisFlags x_flags = 0,
  1133. ImPlotAxisFlags y_flags = 0,
  1134. ImPlotAxisFlags y2_flags = ImPlotAxisFlags_AuxDefault,
  1135. ImPlotAxisFlags y3_flags = ImPlotAxisFlags_AuxDefault,
  1136. const char* y2_label = nullptr,
  1137. const char* y3_label = nullptr) );
  1138. } // namespace ImPlot
  1139. #endif // #ifndef IMPLOT_DISABLE_OBSOLETE_FUNCTIONS
  1140. #endif // #ifndef IMGUI_DISABLE