mirror of
https://github.com/gwm17/implot.git
synced 2024-11-26 20:28:50 -05:00
fix bug in FormatTime
This commit is contained in:
parent
5f77a9bb58
commit
e5f1cf4bdf
|
@ -517,11 +517,11 @@ void LabelTickScientific(ImPlotTick& tick, ImGuiTextBuffer& buffer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LabelTickTime(ImPlotTick& tick, ImGuiTextBuffer& buffer, ImPlotTimeFmt fmt) {
|
void LabelTickTime(ImPlotTick& tick, ImGuiTextBuffer& buffer, ImPlotTimeUnit unit) {
|
||||||
char temp[16];
|
char temp[16];
|
||||||
if (tick.ShowLabel) {
|
if (tick.ShowLabel) {
|
||||||
tick.BufferOffset = buffer.size();
|
tick.BufferOffset = buffer.size();
|
||||||
FormatTime(tick.PlotPos, temp, 16, fmt);
|
FormatTime(tick.PlotPos, temp, 16, unit);
|
||||||
buffer.append(temp, temp + strlen(temp) + 1);
|
buffer.append(temp, temp + strlen(temp) + 1);
|
||||||
tick.LabelSize = ImGui::CalcTextSize(buffer.Buf.Data + tick.BufferOffset);
|
tick.LabelSize = ImGui::CalcTextSize(buffer.Buf.Data + tick.BufferOffset);
|
||||||
}
|
}
|
||||||
|
@ -578,6 +578,7 @@ void AddTicksLogarithmic(const ImPlotRange& range, int nMajor, ImPlotTickCollect
|
||||||
void AddTicksTime(const ImPlotRange& range, ImPlotTickCollection& ticks) {
|
void AddTicksTime(const ImPlotRange& range, ImPlotTickCollection& ticks) {
|
||||||
ImPlotTimeUnit unit_range = GetUnitForRange(range.Min, range.Max);
|
ImPlotTimeUnit unit_range = GetUnitForRange(range.Min, range.Max);
|
||||||
ImPlotTimeUnit unit_ticks = unit_range == 0 ? ImPlotTimeUnit_Us : unit_range - 1;
|
ImPlotTimeUnit unit_ticks = unit_range == 0 ? ImPlotTimeUnit_Us : unit_range - 1;
|
||||||
|
printf("%d\n",(int)unit_ticks);
|
||||||
double t = FloorTime(range.Min, unit_range);
|
double t = FloorTime(range.Min, unit_range);
|
||||||
while (t < range.Max) {
|
while (t < range.Max) {
|
||||||
t = AddTime(t, unit_ticks, 1);
|
t = AddTime(t, unit_ticks, 1);
|
||||||
|
|
|
@ -150,7 +150,7 @@ struct ImPlotPointArray {
|
||||||
|
|
||||||
typedef int ImPlotScale; // -> enum ImPlotScale_
|
typedef int ImPlotScale; // -> enum ImPlotScale_
|
||||||
typedef int ImPlotTimeUnit; // -> enum ImPlotTimeUnit_
|
typedef int ImPlotTimeUnit; // -> enum ImPlotTimeUnit_
|
||||||
typedef int ImPlotTimeFmt; // -> enum ImPlotTimeFmt_
|
typedef int ImPlotTimeUnit; // -> enum ImPlotTimeUnit_
|
||||||
|
|
||||||
// XY axes scaling combinations
|
// XY axes scaling combinations
|
||||||
enum ImPlotScale_ {
|
enum ImPlotScale_ {
|
||||||
|
@ -161,28 +161,17 @@ enum ImPlotScale_ {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ImPlotTimeUnit_ {
|
enum ImPlotTimeUnit_ {
|
||||||
ImPlotTimeUnit_Us, // microsecond
|
ImPlotTimeUnit_Us, // microsecond (:29.428 552)
|
||||||
ImPlotTimeUnit_Ms, // millisecond
|
ImPlotTimeUnit_Ms, // millisecond (:29.428)
|
||||||
ImPlotTimeUnit_S, // second
|
ImPlotTimeUnit_S, // second (:29)
|
||||||
ImPlotTimeUnit_Min, // minute
|
ImPlotTimeUnit_Min, // minute (7:21pm)
|
||||||
ImPlotTimeUnit_Hr, // hour
|
ImPlotTimeUnit_Hr, // hour (7pm)
|
||||||
ImPlotTimeUnit_Day, // day
|
ImPlotTimeUnit_Day, // day (10/3)
|
||||||
ImPlotTimeUnit_Mo, // month
|
ImPlotTimeUnit_Mo, // month (Oct)
|
||||||
ImPlotTimeUnit_Yr, // year
|
ImPlotTimeUnit_Yr, // year (1991)
|
||||||
ImPlotTimeUnit_COUNT
|
ImPlotTimeUnit_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ImPlotTimeFmt_ {
|
|
||||||
ImPlotTimeFmt_SUs, // :29.428 552
|
|
||||||
ImPlotTimeFmt_SMs, // :29.428
|
|
||||||
ImPlotTimeFmt_S, // :29
|
|
||||||
ImPlotTimeFmt_HrMin, // 7:21pm
|
|
||||||
ImPlotTimeFmt_Hr, // 7pm
|
|
||||||
ImPlotTimeFmt_MoDay, // 10/3
|
|
||||||
ImPlotTimeFmt_Mo, // Oct
|
|
||||||
ImPlotTimeFmt_Yr // 1991
|
|
||||||
};
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// [SECTION] ImPlot Structs
|
// [SECTION] ImPlot Structs
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -596,7 +585,7 @@ void LabelTickDefault(ImPlotTick& tick, ImGuiTextBuffer& buffer);
|
||||||
// Label a tick with scientific formating.
|
// Label a tick with scientific formating.
|
||||||
void LabelTickScientific(ImPlotTick& tick, ImGuiTextBuffer& buffer);
|
void LabelTickScientific(ImPlotTick& tick, ImGuiTextBuffer& buffer);
|
||||||
// Label a tick with time formatting.
|
// Label a tick with time formatting.
|
||||||
void LabelTickTime(ImPlotTick& tick, ImGuiTextBuffer& buffer, ImPlotTimeFmt fmt);
|
void LabelTickTime(ImPlotTick& tick, ImGuiTextBuffer& buffer, ImPlotTimeUnit fmt);
|
||||||
|
|
||||||
// Populates a list of ImPlotTicks with normal spaced and formatted ticks
|
// Populates a list of ImPlotTicks with normal spaced and formatted ticks
|
||||||
void AddTicksDefault(const ImPlotRange& range, int nMajor, int nMinor, ImPlotTickCollection& ticks);
|
void AddTicksDefault(const ImPlotRange& range, int nMajor, int nMinor, ImPlotTickCollection& ticks);
|
||||||
|
@ -785,17 +774,17 @@ inline double CeilTime(double t, ImPlotTimeUnit unit) {
|
||||||
return AddTime(FloorTime(t, unit), unit, 1);
|
return AddTime(FloorTime(t, unit), unit, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void FormatTime(double t, char* buffer, int size, ImPlotTimeFmt fmt) {
|
inline void FormatTime(double t, char* buffer, int size, ImPlotTimeUnit unit) {
|
||||||
time_t s = (time_t)t;
|
time_t s = (time_t)t;
|
||||||
int ms = (int)(t * 1000 - floor(t) * 1000);
|
int ms = (int)(t * 1000 - floor(t) * 1000);
|
||||||
int us = (int)(t * 1000000 - floor(t) * 1000000);
|
int us = (int)(t * 1000000 - floor(t) * 1000000);
|
||||||
tm& Tm = GImPlot->Tm;
|
tm& Tm = GImPlot->Tm;
|
||||||
GmTime(&s, &Tm);
|
GmTime(&s, &Tm);
|
||||||
switch(fmt) {
|
switch(unit) {
|
||||||
case ImPlotTimeFmt_Yr: strftime(buffer, size, "%Y", &Tm); break;
|
case ImPlotTimeUnit_Yr: strftime(buffer, size, "%Y", &Tm); break;
|
||||||
case ImPlotTimeFmt_Mo: strftime(buffer, size, "%b", &Tm); break;
|
case ImPlotTimeUnit_Mo: strftime(buffer, size, "%b", &Tm); break;
|
||||||
case ImPlotTimeFmt_MoDay: strftime(buffer, size, "%m/%d", &Tm); break;
|
case ImPlotTimeUnit_Day: strftime(buffer, size, "%m/%d", &Tm); break;
|
||||||
case ImPlotTimeFmt_Hr:
|
case ImPlotTimeUnit_Hr:
|
||||||
if (Tm.tm_hour == 0)
|
if (Tm.tm_hour == 0)
|
||||||
snprintf(buffer, size, "12am");
|
snprintf(buffer, size, "12am");
|
||||||
else if (Tm.tm_hour == 12)
|
else if (Tm.tm_hour == 12)
|
||||||
|
@ -805,7 +794,7 @@ inline void FormatTime(double t, char* buffer, int size, ImPlotTimeFmt fmt) {
|
||||||
else if (Tm.tm_hour > 12)
|
else if (Tm.tm_hour > 12)
|
||||||
snprintf(buffer, size, "%upm", Tm.tm_hour - 12);
|
snprintf(buffer, size, "%upm", Tm.tm_hour - 12);
|
||||||
break;
|
break;
|
||||||
case ImPlotTimeFmt_HrMin:
|
case ImPlotTimeUnit_Min:
|
||||||
if (Tm.tm_hour == 0)
|
if (Tm.tm_hour == 0)
|
||||||
snprintf(buffer, size, "12:%02dam", Tm.tm_min);
|
snprintf(buffer, size, "12:%02dam", Tm.tm_min);
|
||||||
else if (Tm.tm_hour == 12)
|
else if (Tm.tm_hour == 12)
|
||||||
|
@ -815,9 +804,9 @@ inline void FormatTime(double t, char* buffer, int size, ImPlotTimeFmt fmt) {
|
||||||
else if (Tm.tm_hour > 12)
|
else if (Tm.tm_hour > 12)
|
||||||
snprintf(buffer, size, "%u:%02dpm", Tm.tm_hour - 12, Tm.tm_min);
|
snprintf(buffer, size, "%u:%02dpm", Tm.tm_hour - 12, Tm.tm_min);
|
||||||
break;
|
break;
|
||||||
case ImPlotTimeFmt_S: strftime(buffer, size, ":%S", &Tm);
|
case ImPlotTimeUnit_S: snprintf(buffer, size, ":%02d", Tm.tm_sec); break;
|
||||||
case ImPlotTimeFmt_SMs: snprintf(buffer, size, ":%02d.%d", Tm.tm_sec, ms);
|
case ImPlotTimeUnit_Ms: snprintf(buffer, size, ":%02d.%03d", Tm.tm_sec, ms); break;
|
||||||
case ImPlotTimeFmt_SUs: snprintf(buffer, size, ":%02d.%d", Tm.tm_sec, us);
|
case ImPlotTimeUnit_Us: snprintf(buffer, size, ":%02d.%06d", Tm.tm_sec, us); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user