-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
implot_items.cpp
2311 lines (2120 loc) · 129 KB
/
implot_items.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// MIT License
// Copyright (c) 2020 Evan Pezent
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// ImPlot v0.10 WIP
#include "implot.h"
#include "implot_internal.h"
#ifdef _MSC_VER
#define sprintf sprintf_s
#endif
#define SQRT_1_2 0.70710678118f
#define SQRT_3_2 0.86602540378f
#define IMPLOT_NORMALIZE2F_OVER_ZERO(VX, VY) \
{ \
float d2 = VX * VX + VY * VY; \
if (d2 > 0.0f) { \
float inv_len = 1.0f / ImSqrt(d2); \
VX *= inv_len; \
VY *= inv_len; \
} \
}
// Support for pre-1.82 version. Users on 1.82+ can use 0 (default) flags to mean "all corners" but in order to support older versions we are more explicit.
#if (IMGUI_VERSION_NUM < 18102) && !defined(ImDrawFlags_RoundCornersAll)
#define ImDrawFlags_RoundCornersAll ImDrawCornerFlags_All
#endif
namespace ImPlot {
//-----------------------------------------------------------------------------
// Item Utils
//-----------------------------------------------------------------------------
ImPlotItem* RegisterOrGetItem(const char* label_id, bool* just_created) {
ImPlotContext& gp = *GImPlot;
ImGuiID id = ImGui::GetID(label_id);
if (just_created != NULL)
*just_created = gp.CurrentPlot->Items.GetByKey(id) == NULL;
ImPlotItem* item = gp.CurrentPlot->Items.GetOrAddByKey(id);
if (item->SeenThisFrame)
return item;
item->SeenThisFrame = true;
int idx = gp.CurrentPlot->Items.GetIndex(item);
item->ID = id;
if (ImGui::FindRenderedTextEnd(label_id, NULL) != label_id) {
gp.CurrentPlot->LegendData.Indices.push_back(idx);
item->NameOffset = gp.CurrentPlot->LegendData.Labels.size();
gp.CurrentPlot->LegendData.Labels.append(label_id, label_id + strlen(label_id) + 1);
}
else {
item->Show = true;
}
if (item->Show)
gp.VisibleItemCount++;
return item;
}
ImPlotItem* GetItem(const char* label_id) {
ImPlotContext& gp = *GImPlot;
ImGuiID id = ImGui::GetID(label_id);
return gp.CurrentPlot->Items.GetByKey(id);
}
ImPlotItem* GetCurrentItem() {
ImPlotContext& gp = *GImPlot;
return gp.CurrentItem;
}
void SetNextLineStyle(const ImVec4& col, float weight) {
ImPlotContext& gp = *GImPlot;
gp.NextItemData.Colors[ImPlotCol_Line] = col;
gp.NextItemData.LineWeight = weight;
}
void SetNextFillStyle(const ImVec4& col, float alpha) {
ImPlotContext& gp = *GImPlot;
gp.NextItemData.Colors[ImPlotCol_Fill] = col;
gp.NextItemData.FillAlpha = alpha;
}
void SetNextMarkerStyle(ImPlotMarker marker, float size, const ImVec4& fill, float weight, const ImVec4& outline) {
ImPlotContext& gp = *GImPlot;
gp.NextItemData.Marker = marker;
gp.NextItemData.Colors[ImPlotCol_MarkerFill] = fill;
gp.NextItemData.MarkerSize = size;
gp.NextItemData.Colors[ImPlotCol_MarkerOutline] = outline;
gp.NextItemData.MarkerWeight = weight;
}
void SetNextErrorBarStyle(const ImVec4& col, float size, float weight) {
ImPlotContext& gp = *GImPlot;
gp.NextItemData.Colors[ImPlotCol_ErrorBar] = col;
gp.NextItemData.ErrorBarSize = size;
gp.NextItemData.ErrorBarWeight = weight;
}
ImVec4 GetLastItemColor() {
ImPlotContext& gp = *GImPlot;
if (gp.PreviousItem)
return ImGui::ColorConvertU32ToFloat4(gp.PreviousItem->Color);
return ImVec4();
}
void HideNextItem(bool hidden, ImGuiCond cond) {
ImPlotContext& gp = *GImPlot;
gp.NextItemData.HasHidden = true;
gp.NextItemData.Hidden = hidden;
gp.NextItemData.HiddenCond = cond;
}
void BustItemCache() {
ImPlotContext& gp = *GImPlot;
for (int p = 0; p < gp.Plots.GetSize(); ++p) {
ImPlotPlot& plot = *gp.Plots.GetByIndex(p);
plot.ColormapIdx = 0;
plot.Items.Clear();
plot.LegendData.Reset();
}
}
void BustColorCache(const char* plot_title_id) {
ImPlotContext& gp = *GImPlot;
if (plot_title_id == NULL) {
BustItemCache();
}
else {
ImPlotPlot* plot = gp.Plots.GetByKey(ImGui::GetCurrentWindow()->GetID(plot_title_id));
if (plot == NULL)
return;
plot->ColormapIdx = 0;
plot->Items.Clear();
plot->LegendData.Reset();
}
}
//-----------------------------------------------------------------------------
// Begin/EndItem
//-----------------------------------------------------------------------------
// Begins a new item. Returns false if the item should not be plotted.
bool BeginItem(const char* label_id, ImPlotCol recolor_from) {
ImPlotContext& gp = *GImPlot;
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PlotX() needs to be called between BeginPlot() and EndPlot()!");
bool just_created;
ImPlotItem* item = RegisterOrGetItem(label_id, &just_created);
// set current item
gp.CurrentItem = item;
ImPlotNextItemData& s = gp.NextItemData;
// set/override item color
if (recolor_from != -1) {
if (!IsColorAuto(s.Colors[recolor_from]))
item->Color = ImGui::ColorConvertFloat4ToU32(s.Colors[recolor_from]);
else if (!IsColorAuto(gp.Style.Colors[recolor_from]))
item->Color = ImGui::ColorConvertFloat4ToU32(gp.Style.Colors[recolor_from]);
else if (just_created)
item->Color = NextColormapColorU32();
}
else if (just_created) {
item->Color = NextColormapColorU32();
}
// hide/show item
if (gp.NextItemData.HasHidden) {
if (just_created || gp.NextItemData.HiddenCond == ImGuiCond_Always)
item->Show = !gp.NextItemData.Hidden;
}
if (!item->Show) {
// reset next item data
gp.NextItemData.Reset();
gp.PreviousItem = item;
gp.CurrentItem = NULL;
return false;
}
else {
ImVec4 item_color = ImGui::ColorConvertU32ToFloat4(item->Color);
// stage next item colors
s.Colors[ImPlotCol_Line] = IsColorAuto(s.Colors[ImPlotCol_Line]) ? ( IsColorAuto(ImPlotCol_Line) ? item_color : gp.Style.Colors[ImPlotCol_Line] ) : s.Colors[ImPlotCol_Line];
s.Colors[ImPlotCol_Fill] = IsColorAuto(s.Colors[ImPlotCol_Fill]) ? ( IsColorAuto(ImPlotCol_Fill) ? item_color : gp.Style.Colors[ImPlotCol_Fill] ) : s.Colors[ImPlotCol_Fill];
s.Colors[ImPlotCol_MarkerOutline] = IsColorAuto(s.Colors[ImPlotCol_MarkerOutline]) ? ( IsColorAuto(ImPlotCol_MarkerOutline) ? s.Colors[ImPlotCol_Line] : gp.Style.Colors[ImPlotCol_MarkerOutline] ) : s.Colors[ImPlotCol_MarkerOutline];
s.Colors[ImPlotCol_MarkerFill] = IsColorAuto(s.Colors[ImPlotCol_MarkerFill]) ? ( IsColorAuto(ImPlotCol_MarkerFill) ? s.Colors[ImPlotCol_Line] : gp.Style.Colors[ImPlotCol_MarkerFill] ) : s.Colors[ImPlotCol_MarkerFill];
s.Colors[ImPlotCol_ErrorBar] = IsColorAuto(s.Colors[ImPlotCol_ErrorBar]) ? ( GetStyleColorVec4(ImPlotCol_ErrorBar) ) : s.Colors[ImPlotCol_ErrorBar];
// stage next item style vars
s.LineWeight = s.LineWeight < 0 ? gp.Style.LineWeight : s.LineWeight;
s.Marker = s.Marker < 0 ? gp.Style.Marker : s.Marker;
s.MarkerSize = s.MarkerSize < 0 ? gp.Style.MarkerSize : s.MarkerSize;
s.MarkerWeight = s.MarkerWeight < 0 ? gp.Style.MarkerWeight : s.MarkerWeight;
s.FillAlpha = s.FillAlpha < 0 ? gp.Style.FillAlpha : s.FillAlpha;
s.ErrorBarSize = s.ErrorBarSize < 0 ? gp.Style.ErrorBarSize : s.ErrorBarSize;
s.ErrorBarWeight = s.ErrorBarWeight < 0 ? gp.Style.ErrorBarWeight : s.ErrorBarWeight;
s.DigitalBitHeight = s.DigitalBitHeight < 0 ? gp.Style.DigitalBitHeight : s.DigitalBitHeight;
s.DigitalBitGap = s.DigitalBitGap < 0 ? gp.Style.DigitalBitGap : s.DigitalBitGap;
// apply alpha modifier(s)
s.Colors[ImPlotCol_Fill].w *= s.FillAlpha;
// s.Colors[ImPlotCol_MarkerFill].w *= s.FillAlpha; // TODO: this should be separate, if it at all
// apply highlight mods
if (item->LegendHovered && !ImHasFlag(gp.CurrentPlot->Flags, ImPlotFlags_NoHighlight)) {
s.LineWeight *= 2;
s.MarkerWeight *= 2;
// TODO: highlight fills?
}
// set render flags
s.RenderLine = s.Colors[ImPlotCol_Line].w > 0 && s.LineWeight > 0;
s.RenderFill = s.Colors[ImPlotCol_Fill].w > 0;
s.RenderMarkerLine = s.Colors[ImPlotCol_MarkerOutline].w > 0 && s.MarkerWeight > 0;
s.RenderMarkerFill = s.Colors[ImPlotCol_MarkerFill].w > 0;
// push rendering clip rect
PushPlotClipRect();
return true;
}
}
// Ends an item (call only if BeginItem returns true)
void EndItem() {
ImPlotContext& gp = *GImPlot;
// pop rendering clip rect
PopPlotClipRect();
// reset next item data
gp.NextItemData.Reset();
// set current item
gp.PreviousItem = gp.CurrentItem;
gp.CurrentItem = NULL;
}
//-----------------------------------------------------------------------------
// GETTERS
//-----------------------------------------------------------------------------
// Getters can be thought of as iterators that convert user data (e.g. raw arrays)
// to ImPlotPoints
// Interprets an array of Y points as ImPlotPoints where the X value is the index
template <typename T>
struct GetterYs {
GetterYs(const T* ys, int count, double xscale, double x0, int offset, int stride) :
Ys(ys),
Count(count),
XScale(xscale),
X0(x0),
Offset(count ? ImPosMod(offset, count) : 0),
Stride(stride)
{ }
inline ImPlotPoint operator()(int idx) const {
return ImPlotPoint(X0 + XScale * idx, (double)OffsetAndStride(Ys, idx, Count, Offset, Stride));
}
const T* const Ys;
const int Count;
const double XScale;
const double X0;
const int Offset;
const int Stride;
};
// Interprets separate arrays for X and Y points as ImPlotPoints
template <typename T>
struct GetterXsYs {
GetterXsYs(const T* xs, const T* ys, int count, int offset, int stride) :
Xs(xs),
Ys(ys),
Count(count),
Offset(count ? ImPosMod(offset, count) : 0),
Stride(stride)
{ }
inline ImPlotPoint operator()(int idx) const {
return ImPlotPoint((double)OffsetAndStride(Xs, idx, Count, Offset, Stride), (double)OffsetAndStride(Ys, idx, Count, Offset, Stride));
}
const T* const Xs;
const T* const Ys;
const int Count;
const int Offset;
const int Stride;
};
// Interprets separate arrays for X and Y points as ImPlotPoints
// template <typename T>
// struct GetterXsXsYs {
// GetterXsXsYsYs(const T* xs, const T* xa, const T* ys, int count, int offset, int stride) :
// Xs(xs),
// Xa(Xa),
// Ys(ys),
// Count(count),
// Offset(count ? ImPosMod(offset, count) : 0),
// Stride(stride)
// { }
// inline ImPlotPoint operator()(int idx) const {
// return ImPlotPoint((double)OffsetAndStride(Xs, idx, Count, Offset, Stride), (double)OffsetAndStride(Ys, idx, Count, Offset, Stride));
// }
// const T* const Xs;
// const T* const Ys;
// const int Count;
// const int Offset;
// const int Stride;
// };
// Always returns a constant Y reference value where the X value is the index
struct GetterYRef {
GetterYRef(double y_ref, int count, double xscale, double x0) :
YRef(y_ref),
Count(count),
XScale(xscale),
X0(x0)
{ }
inline ImPlotPoint operator()(int idx) const {
return ImPlotPoint(X0 + XScale*idx, YRef);
}
const double YRef;
const int Count;
const double XScale;
const double X0;
};
// Interprets an array of X points as ImPlotPoints where the Y value is a constant reference value
template <typename T>
struct GetterXsYRef {
GetterXsYRef(const T* xs, double y_ref, int count, int offset, int stride) :
Xs(xs),
YRef(y_ref),
Count(count),
Offset(count ? ImPosMod(offset, count) : 0),
Stride(stride)
{ }
inline ImPlotPoint operator()(int idx) const {
return ImPlotPoint((double)OffsetAndStride(Xs, idx, Count, Offset, Stride), YRef);
}
const T* const Xs;
const double YRef;
const int Count;
const int Offset;
const int Stride;
};
// Interprets an array of Y points as ImPlotPoints where the X value is a constant reference value
template <typename T>
struct GetterXRefYs {
GetterXRefYs(double x_ref, const T* ys, int count, int offset, int stride) :
XRef(x_ref),
Ys(ys),
Count(count),
Offset(count ? ImPosMod(offset, count) : 0),
Stride(stride)
{ }
inline ImPlotPoint operator()(int idx) const {
return ImPlotPoint(XRef, (double)OffsetAndStride(Ys, idx, Count, Offset, Stride));
}
const double XRef;
const T* const Ys;
const int Count;
const int Offset;
const int Stride;
};
/// Interprets a user's function pointer as ImPlotPoints
struct GetterFuncPtr {
GetterFuncPtr(ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset) :
Getter(getter),
Data(data),
Count(count),
Offset(count ? ImPosMod(offset, count) : 0)
{ }
inline ImPlotPoint operator()(int idx) const {
idx = ImPosMod(Offset + idx, Count);
return Getter(Data, idx);
}
ImPlotPoint (* const Getter)(void* data, int idx);
void* const Data;
const int Count;
const int Offset;
};
template <typename T>
struct GetterBarV {
const T* Ys; double XShift; int Count; int Offset; int Stride;
GetterBarV(const T* ys, double xshift, int count, int offset, int stride) { Ys = ys; XShift = xshift; Count = count; Offset = offset; Stride = stride; }
inline ImPlotPoint operator()(int idx) const { return ImPlotPoint((double)idx + (double)XShift, (double)OffsetAndStride(Ys, idx, Count, Offset, Stride)); }
};
template <typename T>
struct GetterBarH {
const T* Xs; double YShift; int Count; int Offset; int Stride;
GetterBarH(const T* xs, double yshift, int count, int offset, int stride) { Xs = xs; YShift = yshift; Count = count; Offset = offset; Stride = stride; }
inline ImPlotPoint operator()(int idx) const { return ImPlotPoint((double)OffsetAndStride(Xs, idx, Count, Offset, Stride), (double)idx + (double)YShift); }
};
template <typename T>
struct GetterError {
GetterError(const T* xs, const T* ys, const T* neg, const T* pos, int count, int offset, int stride) :
Xs(xs),
Ys(ys),
Neg(neg),
Pos(pos),
Count(count),
Offset(count ? ImPosMod(offset, count) : 0),
Stride(stride)
{ }
inline ImPlotPointError operator()(int idx) const {
return ImPlotPointError((double)OffsetAndStride(Xs, idx, Count, Offset, Stride),
(double)OffsetAndStride(Ys, idx, Count, Offset, Stride),
(double)OffsetAndStride(Neg, idx, Count, Offset, Stride),
(double)OffsetAndStride(Pos, idx, Count, Offset, Stride));
}
const T* const Xs;
const T* const Ys;
const T* const Neg;
const T* const Pos;
const int Count;
const int Offset;
const int Stride;
};
//-----------------------------------------------------------------------------
// TRANSFORMERS
//-----------------------------------------------------------------------------
// Transforms convert points in plot space (i.e. ImPlotPoint) to pixel space (i.e. ImVec2)
// Transforms points for linear x and linear y space
struct TransformerLinLin {
TransformerLinLin() : YAxis(GetCurrentYAxis()) {}
// inline ImVec2 operator()(const ImPlotPoint& plt) const { return (*this)(plt.x, plt.y); }
inline ImVec2 operator()(const ImPlotPoint& plt) const {
ImPlotContext& gp = *GImPlot;
return ImVec2( (float)(gp.PixelRange[YAxis].Min.x + gp.Mx * (plt.x - gp.CurrentPlot->XAxis.Range.Min)),
(float)(gp.PixelRange[YAxis].Min.y + gp.My[YAxis] * (plt.y - gp.CurrentPlot->YAxis[YAxis].Range.Min)) );
}
const int YAxis;
};
// Transforms points for log x and linear y space
struct TransformerLogLin {
TransformerLogLin() : YAxis(GetCurrentYAxis()) {}
inline ImVec2 operator()(const ImPlotPoint& plt) const {
ImPlotContext& gp = *GImPlot;
double t = ImLog10(plt.x / gp.CurrentPlot->XAxis.Range.Min) / gp.LogDenX;
double x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, (float)t);
return ImVec2( (float)(gp.PixelRange[YAxis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min)),
(float)(gp.PixelRange[YAxis].Min.y + gp.My[YAxis] * (plt.y - gp.CurrentPlot->YAxis[YAxis].Range.Min)) );
}
const int YAxis;
};
// Transforms points for linear x and log y space
struct TransformerLinLog {
TransformerLinLog() : YAxis(GetCurrentYAxis()) {}
inline ImVec2 operator()(const ImPlotPoint& plt) const {
ImPlotContext& gp = *GImPlot;
double t = ImLog10(plt.y / gp.CurrentPlot->YAxis[YAxis].Range.Min) / gp.LogDenY[YAxis];
double y = ImLerp(gp.CurrentPlot->YAxis[YAxis].Range.Min, gp.CurrentPlot->YAxis[YAxis].Range.Max, (float)t);
return ImVec2( (float)(gp.PixelRange[YAxis].Min.x + gp.Mx * (plt.x - gp.CurrentPlot->XAxis.Range.Min)),
(float)(gp.PixelRange[YAxis].Min.y + gp.My[YAxis] * (y - gp.CurrentPlot->YAxis[YAxis].Range.Min)) );
}
const int YAxis;
};
// Transforms points for log x and log y space
struct TransformerLogLog {
TransformerLogLog() : YAxis(GetCurrentYAxis()) {}
inline ImVec2 operator()(const ImPlotPoint& plt) const {
ImPlotContext& gp = *GImPlot;
double t = ImLog10(plt.x / gp.CurrentPlot->XAxis.Range.Min) / gp.LogDenX;
double x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, (float)t);
t = ImLog10(plt.y / gp.CurrentPlot->YAxis[YAxis].Range.Min) / gp.LogDenY[YAxis];
double y = ImLerp(gp.CurrentPlot->YAxis[YAxis].Range.Min, gp.CurrentPlot->YAxis[YAxis].Range.Max, (float)t);
return ImVec2( (float)(gp.PixelRange[YAxis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min)),
(float)(gp.PixelRange[YAxis].Min.y + gp.My[YAxis] * (y - gp.CurrentPlot->YAxis[YAxis].Range.Min)) );
}
const int YAxis;
};
//-----------------------------------------------------------------------------
// PRIMITIVE RENDERERS
//-----------------------------------------------------------------------------
inline void AddLine(const ImVec2& P1, const ImVec2& P2, float weight, ImU32 col, ImDrawList& DrawList, ImVec2 uv) {
float dx = P2.x - P1.x;
float dy = P2.y - P1.y;
IMPLOT_NORMALIZE2F_OVER_ZERO(dx, dy);
dx *= (weight * 0.5f);
dy *= (weight * 0.5f);
DrawList._VtxWritePtr[0].pos.x = P1.x + dy;
DrawList._VtxWritePtr[0].pos.y = P1.y - dx;
DrawList._VtxWritePtr[0].uv = uv;
DrawList._VtxWritePtr[0].col = col;
DrawList._VtxWritePtr[1].pos.x = P2.x + dy;
DrawList._VtxWritePtr[1].pos.y = P2.y - dx;
DrawList._VtxWritePtr[1].uv = uv;
DrawList._VtxWritePtr[1].col = col;
DrawList._VtxWritePtr[2].pos.x = P2.x - dy;
DrawList._VtxWritePtr[2].pos.y = P2.y + dx;
DrawList._VtxWritePtr[2].uv = uv;
DrawList._VtxWritePtr[2].col = col;
DrawList._VtxWritePtr[3].pos.x = P1.x - dy;
DrawList._VtxWritePtr[3].pos.y = P1.y + dx;
DrawList._VtxWritePtr[3].uv = uv;
DrawList._VtxWritePtr[3].col = col;
DrawList._VtxWritePtr += 4;
DrawList._IdxWritePtr[0] = (ImDrawIdx)(DrawList._VtxCurrentIdx);
DrawList._IdxWritePtr[1] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 1);
DrawList._IdxWritePtr[2] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 2);
DrawList._IdxWritePtr[3] = (ImDrawIdx)(DrawList._VtxCurrentIdx);
DrawList._IdxWritePtr[4] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 2);
DrawList._IdxWritePtr[5] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 3);
DrawList._IdxWritePtr += 6;
DrawList._VtxCurrentIdx += 4;
}
inline void AddRectFilled(const ImVec2& Pmin, const ImVec2& Pmax, ImU32 col, ImDrawList& DrawList, ImVec2 uv) {
DrawList._VtxWritePtr[0].pos = Pmin;
DrawList._VtxWritePtr[0].uv = uv;
DrawList._VtxWritePtr[0].col = col;
DrawList._VtxWritePtr[1].pos = Pmax;
DrawList._VtxWritePtr[1].uv = uv;
DrawList._VtxWritePtr[1].col = col;
DrawList._VtxWritePtr[2].pos.x = Pmin.x;
DrawList._VtxWritePtr[2].pos.y = Pmax.y;
DrawList._VtxWritePtr[2].uv = uv;
DrawList._VtxWritePtr[2].col = col;
DrawList._VtxWritePtr[3].pos.x = Pmax.x;
DrawList._VtxWritePtr[3].pos.y = Pmin.y;
DrawList._VtxWritePtr[3].uv = uv;
DrawList._VtxWritePtr[3].col = col;
DrawList._VtxWritePtr += 4;
DrawList._IdxWritePtr[0] = (ImDrawIdx)(DrawList._VtxCurrentIdx);
DrawList._IdxWritePtr[1] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 1);
DrawList._IdxWritePtr[2] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 2);
DrawList._IdxWritePtr[3] = (ImDrawIdx)(DrawList._VtxCurrentIdx);
DrawList._IdxWritePtr[4] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 1);
DrawList._IdxWritePtr[5] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 3);
DrawList._IdxWritePtr += 6;
DrawList._VtxCurrentIdx += 4;
}
template <typename TGetter, typename TTransformer>
struct LineStripRenderer {
inline LineStripRenderer(const TGetter& getter, const TTransformer& transformer, ImU32 col, float weight) :
Getter(getter),
Transformer(transformer),
Prims(Getter.Count - 1),
Col(col),
Weight(weight)
{
P1 = Transformer(Getter(0));
}
inline bool operator()(ImDrawList& DrawList, const ImRect& cull_rect, const ImVec2& uv, int prim) const {
ImVec2 P2 = Transformer(Getter(prim + 1));
if (!cull_rect.Overlaps(ImRect(ImMin(P1, P2), ImMax(P1, P2)))) {
P1 = P2;
return false;
}
AddLine(P1,P2,Weight,Col,DrawList,uv);
P1 = P2;
return true;
}
const TGetter& Getter;
const TTransformer& Transformer;
const int Prims;
const ImU32 Col;
const float Weight;
mutable ImVec2 P1;
static const int IdxConsumed = 6;
static const int VtxConsumed = 4;
};
template <typename TGetter, typename TTransformer>
struct StairsRenderer {
inline StairsRenderer(const TGetter& getter, const TTransformer& transformer, ImU32 col, float weight) :
Getter(getter),
Transformer(transformer),
Prims(Getter.Count - 1),
Col(col),
HalfWeight(weight * 0.5f)
{
P1 = Transformer(Getter(0));
}
inline bool operator()(ImDrawList& DrawList, const ImRect& cull_rect, const ImVec2& uv, int prim) const {
ImVec2 P2 = Transformer(Getter(prim + 1));
if (!cull_rect.Overlaps(ImRect(ImMin(P1, P2), ImMax(P1, P2)))) {
P1 = P2;
return false;
}
AddRectFilled(ImVec2(P1.x, P1.y + HalfWeight), ImVec2(P2.x, P1.y - HalfWeight), Col, DrawList, uv);
AddRectFilled(ImVec2(P2.x - HalfWeight, P2.y), ImVec2(P2.x + HalfWeight, P1.y), Col, DrawList, uv);
// AddLine(P1, P12, Weight, Col, DrawList, uv);
// AddLine(P12, P2, Weight, Col, DrawList, uv);
P1 = P2;
return true;
}
const TGetter& Getter;
const TTransformer& Transformer;
const int Prims;
const ImU32 Col;
const float HalfWeight;
mutable ImVec2 P1;
static const int IdxConsumed = 12;
static const int VtxConsumed = 8;
};
template <typename TGetter1, typename TGetter2, typename TTransformer>
struct LineSegmentsRenderer {
inline LineSegmentsRenderer(const TGetter1& getter1, const TGetter2& getter2, const TTransformer& transformer, ImU32 col, float weight) :
Getter1(getter1),
Getter2(getter2),
Transformer(transformer),
Prims(ImMin(Getter1.Count, Getter2.Count)),
Col(col),
Weight(weight)
{}
inline bool operator()(ImDrawList& DrawList, const ImRect& cull_rect, const ImVec2& uv, int prim) const {
ImVec2 P1 = Transformer(Getter1(prim));
ImVec2 P2 = Transformer(Getter2(prim));
if (!cull_rect.Overlaps(ImRect(ImMin(P1, P2), ImMax(P1, P2))))
return false;
AddLine(P1,P2,Weight,Col,DrawList,uv);
return true;
}
const TGetter1& Getter1;
const TGetter2& Getter2;
const TTransformer& Transformer;
const int Prims;
const ImU32 Col;
const float Weight;
static const int IdxConsumed = 6;
static const int VtxConsumed = 4;
};
template <typename TGetter1, typename TGetter2, typename TTransformer>
struct ShadedRenderer {
ShadedRenderer(const TGetter1& getter1, const TGetter2& getter2, const TTransformer& transformer, ImU32 col) :
Getter1(getter1),
Getter2(getter2),
Transformer(transformer),
Prims(ImMin(Getter1.Count, Getter2.Count) - 1),
Col(col)
{
P11 = Transformer(Getter1(0));
P12 = Transformer(Getter2(0));
}
inline bool operator()(ImDrawList& DrawList, const ImRect& cull_rect, const ImVec2& uv, int prim) const {
ImVec2 P21 = Transformer(Getter1(prim+1));
ImVec2 P22 = Transformer(Getter2(prim+1));
ImRect rect(ImMin(ImMin(ImMin(P11,P12),P21),P22), ImMax(ImMax(ImMax(P11,P12),P21),P22));
if (!cull_rect.Overlaps(rect)) {
P11 = P21;
P12 = P22;
return false;
}
const int intersect = (P11.y > P12.y && P22.y > P21.y) || (P12.y > P11.y && P21.y > P22.y);
ImVec2 intersection = Intersection(P11,P21,P12,P22);
DrawList._VtxWritePtr[0].pos = P11;
DrawList._VtxWritePtr[0].uv = uv;
DrawList._VtxWritePtr[0].col = Col;
DrawList._VtxWritePtr[1].pos = P21;
DrawList._VtxWritePtr[1].uv = uv;
DrawList._VtxWritePtr[1].col = Col;
DrawList._VtxWritePtr[2].pos = intersection;
DrawList._VtxWritePtr[2].uv = uv;
DrawList._VtxWritePtr[2].col = Col;
DrawList._VtxWritePtr[3].pos = P12;
DrawList._VtxWritePtr[3].uv = uv;
DrawList._VtxWritePtr[3].col = Col;
DrawList._VtxWritePtr[4].pos = P22;
DrawList._VtxWritePtr[4].uv = uv;
DrawList._VtxWritePtr[4].col = Col;
DrawList._VtxWritePtr += 5;
DrawList._IdxWritePtr[0] = (ImDrawIdx)(DrawList._VtxCurrentIdx);
DrawList._IdxWritePtr[1] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 1 + intersect);
DrawList._IdxWritePtr[2] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 3);
DrawList._IdxWritePtr[3] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 1);
DrawList._IdxWritePtr[4] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 3 - intersect);
DrawList._IdxWritePtr[5] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 4);
DrawList._IdxWritePtr += 6;
DrawList._VtxCurrentIdx += 5;
P11 = P21;
P12 = P22;
return true;
}
const TGetter1& Getter1;
const TGetter2& Getter2;
const TTransformer& Transformer;
const int Prims;
const ImU32 Col;
mutable ImVec2 P11;
mutable ImVec2 P12;
static const int IdxConsumed = 6;
static const int VtxConsumed = 5;
};
// Stupid way of calculating maximum index size of ImDrawIdx without integer overflow issues
template <typename T>
struct MaxIdx { static const unsigned int Value; };
template <> const unsigned int MaxIdx<unsigned short>::Value = 65535;
template <> const unsigned int MaxIdx<unsigned int>::Value = 4294967295;
/// Renders primitive shapes in bulk as efficiently as possible.
template <typename Renderer>
inline void RenderPrimitives(const Renderer& renderer, ImDrawList& DrawList, const ImRect& cull_rect) {
unsigned int prims = renderer.Prims;
unsigned int prims_culled = 0;
unsigned int idx = 0;
const ImVec2 uv = DrawList._Data->TexUvWhitePixel;
while (prims) {
// find how many can be reserved up to end of current draw command's limit
unsigned int cnt = ImMin(prims, (MaxIdx<ImDrawIdx>::Value - DrawList._VtxCurrentIdx) / Renderer::VtxConsumed);
// make sure at least this many elements can be rendered to avoid situations where at the end of buffer this slow path is not taken all the time
if (cnt >= ImMin(64u, prims)) {
if (prims_culled >= cnt)
prims_culled -= cnt; // reuse previous reservation
else {
DrawList.PrimReserve((cnt - prims_culled) * Renderer::IdxConsumed, (cnt - prims_culled) * Renderer::VtxConsumed); // add more elements to previous reservation
prims_culled = 0;
}
}
else
{
if (prims_culled > 0) {
DrawList.PrimUnreserve(prims_culled * Renderer::IdxConsumed, prims_culled * Renderer::VtxConsumed);
prims_culled = 0;
}
cnt = ImMin(prims, (MaxIdx<ImDrawIdx>::Value - 0/*DrawList._VtxCurrentIdx*/) / Renderer::VtxConsumed);
DrawList.PrimReserve(cnt * Renderer::IdxConsumed, cnt * Renderer::VtxConsumed); // reserve new draw command
}
prims -= cnt;
for (unsigned int ie = idx + cnt; idx != ie; ++idx) {
if (!renderer(DrawList, cull_rect, uv, idx))
prims_culled++;
}
}
if (prims_culled > 0)
DrawList.PrimUnreserve(prims_culled * Renderer::IdxConsumed, prims_culled * Renderer::VtxConsumed);
}
template <typename Getter, typename Transformer>
inline void RenderLineStrip(const Getter& getter, const Transformer& transformer, ImDrawList& DrawList, float line_weight, ImU32 col) {
ImPlotContext& gp = *GImPlot;
if (ImHasFlag(gp.CurrentPlot->Flags, ImPlotFlags_AntiAliased) || gp.Style.AntiAliasedLines) {
ImVec2 p1 = transformer(getter(0));
for (int i = 1; i < getter.Count; ++i) {
ImVec2 p2 = transformer(getter(i));
if (gp.CurrentPlot->PlotRect.Overlaps(ImRect(ImMin(p1, p2), ImMax(p1, p2))))
DrawList.AddLine(p1, p2, col, line_weight);
p1 = p2;
}
}
else {
RenderPrimitives(LineStripRenderer<Getter,Transformer>(getter, transformer, col, line_weight), DrawList, gp.CurrentPlot->PlotRect);
}
}
template <typename Getter1, typename Getter2, typename Transformer>
inline void RenderLineSegments(const Getter1& getter1, const Getter2& getter2, const Transformer& transformer, ImDrawList& DrawList, float line_weight, ImU32 col) {
ImPlotContext& gp = *GImPlot;
if (ImHasFlag(gp.CurrentPlot->Flags, ImPlotFlags_AntiAliased) || gp.Style.AntiAliasedLines) {
int I = ImMin(getter1.Count, getter2.Count);
for (int i = 0; i < I; ++i) {
ImVec2 p1 = transformer(getter1(i));
ImVec2 p2 = transformer(getter2(i));
if (gp.CurrentPlot->PlotRect.Overlaps(ImRect(ImMin(p1, p2), ImMax(p1, p2))))
DrawList.AddLine(p1, p2, col, line_weight);
}
}
else {
RenderPrimitives(LineSegmentsRenderer<Getter1,Getter2,Transformer>(getter1, getter2, transformer, col, line_weight), DrawList, gp.CurrentPlot->PlotRect);
}
}
template <typename Getter, typename Transformer>
inline void RenderStairs(const Getter& getter, const Transformer& transformer, ImDrawList& DrawList, float line_weight, ImU32 col) {
ImPlotContext& gp = *GImPlot;
if (ImHasFlag(gp.CurrentPlot->Flags, ImPlotFlags_AntiAliased) || gp.Style.AntiAliasedLines) {
ImVec2 p1 = transformer(getter(0));
for (int i = 1; i < getter.Count; ++i) {
ImVec2 p2 = transformer(getter(i));
if (gp.CurrentPlot->PlotRect.Overlaps(ImRect(ImMin(p1, p2), ImMax(p1, p2)))) {
ImVec2 p12(p2.x, p1.y);
DrawList.AddLine(p1, p12, col, line_weight);
DrawList.AddLine(p12, p2, col, line_weight);
}
p1 = p2;
}
}
else {
RenderPrimitives(StairsRenderer<Getter,Transformer>(getter, transformer, col, line_weight), DrawList, gp.CurrentPlot->PlotRect);
}
}
//-----------------------------------------------------------------------------
// MARKER RENDERERS
//-----------------------------------------------------------------------------
inline void TransformMarker(ImVec2* points, int n, const ImVec2& c, float s) {
for (int i = 0; i < n; ++i) {
points[i].x = c.x + points[i].x * s;
points[i].y = c.y + points[i].y * s;
}
}
inline void RenderMarkerGeneral(ImDrawList& DrawList, ImVec2* points, int n, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
TransformMarker(points, n, c, s);
if (fill)
DrawList.AddConvexPolyFilled(points, n, col_fill);
if (outline && !(fill && col_outline == col_fill)) {
for (int i = 0; i < n; ++i)
DrawList.AddLine(points[i], points[(i+1)%n], col_outline, weight);
}
}
inline void RenderMarkerCircle(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[10] = {ImVec2(1.0f, 0.0f),
ImVec2(0.809017f, 0.58778524f),
ImVec2(0.30901697f, 0.95105654f),
ImVec2(-0.30901703f, 0.9510565f),
ImVec2(-0.80901706f, 0.5877852f),
ImVec2(-1.0f, 0.0f),
ImVec2(-0.80901694f, -0.58778536f),
ImVec2(-0.3090171f, -0.9510565f),
ImVec2(0.30901712f, -0.9510565f),
ImVec2(0.80901694f, -0.5877853f)};
RenderMarkerGeneral(DrawList, marker, 10, c, s, outline, col_outline, fill, col_fill, weight);
}
inline void RenderMarkerDiamond(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[4] = {ImVec2(1, 0), ImVec2(0, -1), ImVec2(-1, 0), ImVec2(0, 1)};
RenderMarkerGeneral(DrawList, marker, 4, c, s, outline, col_outline, fill, col_fill, weight);
}
inline void RenderMarkerSquare(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[4] = {ImVec2(SQRT_1_2,SQRT_1_2),ImVec2(SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,SQRT_1_2)};
RenderMarkerGeneral(DrawList, marker, 4, c, s, outline, col_outline, fill, col_fill, weight);
}
inline void RenderMarkerUp(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[3] = {ImVec2(SQRT_3_2,0.5f),ImVec2(0,-1),ImVec2(-SQRT_3_2,0.5f)};
RenderMarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight);
}
inline void RenderMarkerDown(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[3] = {ImVec2(SQRT_3_2,-0.5f),ImVec2(0,1),ImVec2(-SQRT_3_2,-0.5f)};
RenderMarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight);
}
inline void RenderMarkerLeft(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[3] = {ImVec2(-1,0), ImVec2(0.5, SQRT_3_2), ImVec2(0.5, -SQRT_3_2)};
RenderMarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight);
}
inline void RenderMarkerRight(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[3] = {ImVec2(1,0), ImVec2(-0.5, SQRT_3_2), ImVec2(-0.5, -SQRT_3_2)};
RenderMarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight);
}
inline void RenderMarkerAsterisk(ImDrawList& DrawList, const ImVec2& c, float s, bool /*outline*/, ImU32 col_outline, bool /*fill*/, ImU32 /*col_fill*/, float weight) {
ImVec2 marker[6] = {ImVec2(SQRT_3_2, 0.5f), ImVec2(0, -1), ImVec2(-SQRT_3_2, 0.5f), ImVec2(SQRT_3_2, -0.5f), ImVec2(0, 1), ImVec2(-SQRT_3_2, -0.5f)};
TransformMarker(marker, 6, c, s);
DrawList.AddLine(marker[0], marker[5], col_outline, weight);
DrawList.AddLine(marker[1], marker[4], col_outline, weight);
DrawList.AddLine(marker[2], marker[3], col_outline, weight);
}
inline void RenderMarkerPlus(ImDrawList& DrawList, const ImVec2& c, float s, bool /*outline*/, ImU32 col_outline, bool /*fill*/, ImU32 /*col_fill*/, float weight) {
ImVec2 marker[4] = {ImVec2(1, 0), ImVec2(0, -1), ImVec2(-1, 0), ImVec2(0, 1)};
TransformMarker(marker, 4, c, s);
DrawList.AddLine(marker[0], marker[2], col_outline, weight);
DrawList.AddLine(marker[1], marker[3], col_outline, weight);
}
inline void RenderMarkerCross(ImDrawList& DrawList, const ImVec2& c, float s, bool /*outline*/, ImU32 col_outline, bool /*fill*/, ImU32 /*col_fill*/, float weight) {
ImVec2 marker[4] = {ImVec2(SQRT_1_2,SQRT_1_2),ImVec2(SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,SQRT_1_2)};
TransformMarker(marker, 4, c, s);
DrawList.AddLine(marker[0], marker[2], col_outline, weight);
DrawList.AddLine(marker[1], marker[3], col_outline, weight);
}
template <typename Transformer, typename Getter>
inline void RenderMarkers(Getter getter, Transformer transformer, ImDrawList& DrawList, ImPlotMarker marker, float size, bool rend_mk_line, ImU32 col_mk_line, float weight, bool rend_mk_fill, ImU32 col_mk_fill) {
static void (*marker_table[ImPlotMarker_COUNT])(ImDrawList&, const ImVec2&, float s, bool, ImU32, bool, ImU32, float) = {
RenderMarkerCircle,
RenderMarkerSquare,
RenderMarkerDiamond ,
RenderMarkerUp ,
RenderMarkerDown ,
RenderMarkerLeft,
RenderMarkerRight,
RenderMarkerCross,
RenderMarkerPlus,
RenderMarkerAsterisk
};
ImPlotContext& gp = *GImPlot;
for (int i = 0; i < getter.Count; ++i) {
ImVec2 c = transformer(getter(i));
if (gp.CurrentPlot->PlotRect.Contains(c))
marker_table[marker](DrawList, c, size, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill, weight);
}
}
//-----------------------------------------------------------------------------
// PLOT LINE
//-----------------------------------------------------------------------------
template <typename Getter>
inline void PlotLineEx(const char* label_id, const Getter& getter) {
if (BeginItem(label_id, ImPlotCol_Line)) {
if (FitThisFrame()) {
for (int i = 0; i < getter.Count; ++i) {
ImPlotPoint p = getter(i);
FitPoint(p);
}
}
const ImPlotNextItemData& s = GetItemData();
ImDrawList& DrawList = *GetPlotDrawList();
if (getter.Count > 1 && s.RenderLine) {
const ImU32 col_line = ImGui::GetColorU32(s.Colors[ImPlotCol_Line]);
switch (GetCurrentScale()) {
case ImPlotScale_LinLin: RenderLineStrip(getter, TransformerLinLin(), DrawList, s.LineWeight, col_line); break;
case ImPlotScale_LogLin: RenderLineStrip(getter, TransformerLogLin(), DrawList, s.LineWeight, col_line); break;
case ImPlotScale_LinLog: RenderLineStrip(getter, TransformerLinLog(), DrawList, s.LineWeight, col_line); break;
case ImPlotScale_LogLog: RenderLineStrip(getter, TransformerLogLog(), DrawList, s.LineWeight, col_line); break;
}
}
// render markers
if (s.Marker != ImPlotMarker_None) {
PopPlotClipRect();
PushPlotClipRect(s.MarkerSize);
const ImU32 col_line = ImGui::GetColorU32(s.Colors[ImPlotCol_MarkerOutline]);
const ImU32 col_fill = ImGui::GetColorU32(s.Colors[ImPlotCol_MarkerFill]);
switch (GetCurrentScale()) {
case ImPlotScale_LinLin: RenderMarkers(getter, TransformerLinLin(), DrawList, s.Marker, s.MarkerSize, s.RenderMarkerLine, col_line, s.MarkerWeight, s.RenderMarkerFill, col_fill); break;
case ImPlotScale_LogLin: RenderMarkers(getter, TransformerLogLin(), DrawList, s.Marker, s.MarkerSize, s.RenderMarkerLine, col_line, s.MarkerWeight, s.RenderMarkerFill, col_fill); break;
case ImPlotScale_LinLog: RenderMarkers(getter, TransformerLinLog(), DrawList, s.Marker, s.MarkerSize, s.RenderMarkerLine, col_line, s.MarkerWeight, s.RenderMarkerFill, col_fill); break;
case ImPlotScale_LogLog: RenderMarkers(getter, TransformerLogLog(), DrawList, s.Marker, s.MarkerSize, s.RenderMarkerLine, col_line, s.MarkerWeight, s.RenderMarkerFill, col_fill); break;
}
}
EndItem();
}
}
template <typename T>
void PlotLine(const char* label_id, const T* values, int count, double xscale, double x0, int offset, int stride) {
GetterYs<T> getter(values,count,xscale,x0,offset,stride);
PlotLineEx(label_id, getter);
}
template IMPLOT_API void PlotLine<ImS8> (const char* label_id, const ImS8* values, int count, double xscale, double x0, int offset, int stride);
template IMPLOT_API void PlotLine<ImU8> (const char* label_id, const ImU8* values, int count, double xscale, double x0, int offset, int stride);
template IMPLOT_API void PlotLine<ImS16>(const char* label_id, const ImS16* values, int count, double xscale, double x0, int offset, int stride);
template IMPLOT_API void PlotLine<ImU16>(const char* label_id, const ImU16* values, int count, double xscale, double x0, int offset, int stride);
template IMPLOT_API void PlotLine<ImS32>(const char* label_id, const ImS32* values, int count, double xscale, double x0, int offset, int stride);
template IMPLOT_API void PlotLine<ImU32>(const char* label_id, const ImU32* values, int count, double xscale, double x0, int offset, int stride);
template IMPLOT_API void PlotLine<ImS64>(const char* label_id, const ImS64* values, int count, double xscale, double x0, int offset, int stride);
template IMPLOT_API void PlotLine<ImU64>(const char* label_id, const ImU64* values, int count, double xscale, double x0, int offset, int stride);
template IMPLOT_API void PlotLine<float>(const char* label_id, const float* values, int count, double xscale, double x0, int offset, int stride);
template IMPLOT_API void PlotLine<double>(const char* label_id, const double* values, int count, double xscale, double x0, int offset, int stride);
template <typename T>
void PlotLine(const char* label_id, const T* xs, const T* ys, int count, int offset, int stride) {
GetterXsYs<T> getter(xs,ys,count,offset,stride);
return PlotLineEx(label_id, getter);
}
template IMPLOT_API void PlotLine<ImS8>(const char* label_id, const ImS8* xs, const ImS8* ys, int count, int offset, int stride);
template IMPLOT_API void PlotLine<ImU8>(const char* label_id, const ImU8* xs, const ImU8* ys, int count, int offset, int stride);
template IMPLOT_API void PlotLine<ImS16>(const char* label_id, const ImS16* xs, const ImS16* ys, int count, int offset, int stride);
template IMPLOT_API void PlotLine<ImU16>(const char* label_id, const ImU16* xs, const ImU16* ys, int count, int offset, int stride);
template IMPLOT_API void PlotLine<ImS32>(const char* label_id, const ImS32* xs, const ImS32* ys, int count, int offset, int stride);
template IMPLOT_API void PlotLine<ImU32>(const char* label_id, const ImU32* xs, const ImU32* ys, int count, int offset, int stride);
template IMPLOT_API void PlotLine<ImS64>(const char* label_id, const ImS64* xs, const ImS64* ys, int count, int offset, int stride);
template IMPLOT_API void PlotLine<ImU64>(const char* label_id, const ImU64* xs, const ImU64* ys, int count, int offset, int stride);
template IMPLOT_API void PlotLine<float>(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride);
template IMPLOT_API void PlotLine<double>(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride);
// custom
void PlotLineG(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, int offset) {
GetterFuncPtr getter(getter_func,data, count, offset);
return PlotLineEx(label_id, getter);
}
//-----------------------------------------------------------------------------
// PLOT SCATTER
//-----------------------------------------------------------------------------