| 38 | namespace |
| 39 | { |
| 40 | auto MakeDocument_( |
| 41 | gfx::Graphics& gfx, |
| 42 | const OverlaySpec& spec, |
| 43 | MetricPackMapper& mapper, |
| 44 | pmon::MetricFetcherFactory& fetcherFactory, |
| 45 | std::shared_ptr<TextElement>& captureIndicator) |
| 46 | { |
| 47 | auto pRoot = FlexElement::Make({}, { "doc" }); |
| 48 | std::shared_ptr<gfx::lay::Element> pReadoutContainer; |
| 49 | |
| 50 | for (const auto& w : spec.widgets) { |
| 51 | try { |
| 52 | if (auto pGraphSpec = std::get_if<GraphSpec>(&w)) { |
| 53 | auto packsData = pGraphSpec->metrics | |
| 54 | std::views::transform([&](const GraphMetricSpec& gms) { |
| 55 | auto metInfo = fetcherFactory.GetMetricInfo(gms.metric); |
| 56 | return std::make_shared<GraphLinePack>(GraphLinePack{ |
| 57 | .data = mapper[gms.metric].graphData, |
| 58 | .axisAffinity = gms.axisAffinity, |
| 59 | .label = std::move(metInfo.fullName), |
| 60 | .units = std::move(metInfo.unitLabel), |
| 61 | }); |
| 62 | }) | rn::to<std::vector>(); |
| 63 | pRoot->AddChild(GraphElement::Make( |
| 64 | pGraphSpec->type, std::move(packsData), { pGraphSpec->tag } |
| 65 | )); |
| 66 | pReadoutContainer.reset(); |
| 67 | } |
| 68 | else if (auto pReadoutSpec = std::get_if<ReadoutSpec>(&w)) { |
| 69 | if (!pReadoutContainer) { |
| 70 | pReadoutContainer = gfx::lay::FlexElement::Make({}, { "readout-container" }); |
| 71 | pRoot->AddChild(pReadoutContainer); |
| 72 | } |
| 73 | |
| 74 | auto metInfo = fetcherFactory.GetMetricInfo(pReadoutSpec->metric); |
| 75 | pReadoutContainer->AddChild(gfx::lay::ReadoutElement::Make( |
| 76 | metInfo.isNonNumeric, std::move(metInfo.fullName), std::move(metInfo.unitLabel), |
| 77 | mapper[pReadoutSpec->metric].textData.get(), { pReadoutSpec->tag } |
| 78 | )); |
| 79 | } |
| 80 | else { |
| 81 | throw Except<OverlayDocumentException>("Bad widget variant"); |
| 82 | } |
| 83 | } |
| 84 | catch (...) { |
| 85 | pmlog_warn("Failed building a widget into document"); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | // capture state indicator |
| 90 | pRoot->AddChild(FlexElement::Make( |
| 91 | { |
| 92 | TextElement::Make(L"Capture Status:", {"label"}), |
| 93 | captureIndicator = TextElement::Make(L"-------------------", {"value"}), |
| 94 | }, |
| 95 | { "cap" } |
| 96 | )); |
| 97 |
no test coverage detected