| 1504 | //----------------------------------------------------------------------------- |
| 1505 | |
| 1506 | void Demo_TimeScale() { |
| 1507 | IMGUI_DEMO_MARKER("Axes/Time Scale"); |
| 1508 | |
| 1509 | static double t_min = 1609459200; // 01/01/2021 @ 12:00:00am (UTC) |
| 1510 | static double t_max = 1640995200; // 01/01/2022 @ 12:00:00am (UTC) |
| 1511 | |
| 1512 | ImGui::BulletText("When ImPlotAxisFlags_Time is enabled on the X-Axis, values are interpreted as\n" |
| 1513 | "UNIX timestamps in seconds and axis labels are formated as date/time."); |
| 1514 | ImGui::BulletText("By default, labels are in UTC time but can be set to use local time instead."); |
| 1515 | |
| 1516 | ImGui::Checkbox("Local Time",&ImPlot::GetStyle().UseLocalTime); |
| 1517 | ImGui::SameLine(); |
| 1518 | ImGui::Checkbox("ISO 8601",&ImPlot::GetStyle().UseISO8601); |
| 1519 | ImGui::SameLine(); |
| 1520 | ImGui::Checkbox("24 Hour Clock",&ImPlot::GetStyle().Use24HourClock); |
| 1521 | |
| 1522 | static HugeTimeData* data = nullptr; |
| 1523 | if (data == nullptr) { |
| 1524 | ImGui::SameLine(); |
| 1525 | if (ImGui::Button("Generate Huge Data (~500MB!)")) { |
| 1526 | static HugeTimeData sdata(t_min); |
| 1527 | data = &sdata; |
| 1528 | } |
| 1529 | } |
| 1530 | |
| 1531 | if (ImPlot::BeginPlot("##Time", ImVec2(-1,0))) { |
| 1532 | ImPlot::SetupAxisScale(ImAxis_X1, ImPlotScale_Time); |
| 1533 | ImPlot::SetupAxesLimits(t_min,t_max,0,1); |
| 1534 | if (data != nullptr) { |
| 1535 | // downsample our data |
| 1536 | int downsample = (int)ImPlot::GetPlotLimits().X.Size() / 1000 + 1; |
| 1537 | int start = (int)(ImPlot::GetPlotLimits().X.Min - t_min); |
| 1538 | start = start < 0 ? 0 : start > HugeTimeData::Size - 1 ? HugeTimeData::Size - 1 : start; |
| 1539 | int end = (int)(ImPlot::GetPlotLimits().X.Max - t_min) + 1000; |
| 1540 | end = end < 0 ? 0 : end > HugeTimeData::Size - 1 ? HugeTimeData::Size - 1 : end; |
| 1541 | int size = (end - start)/downsample; |
| 1542 | // plot it |
| 1543 | ImPlot::PlotLine("Time Series", &data->Ts[start], &data->Ys[start], size, {ImPlotProp_Stride, sizeof(double)*downsample}); |
| 1544 | } |
| 1545 | // plot time now |
| 1546 | double t_now = (double)time(nullptr); |
| 1547 | double y_now = HugeTimeData::GetY(t_now); |
| 1548 | ImPlot::PlotScatter("Now",&t_now,&y_now,1); |
| 1549 | ImPlot::Annotation(t_now,y_now,ImPlot::GetLastItemColor(),ImVec2(10,10),false,"Now"); |
| 1550 | ImPlot::EndPlot(); |
| 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | //----------------------------------------------------------------------------- |
| 1555 |
nothing calls this directly
no test coverage detected