← Documentation
ADS-IDAC Engine 5.0.0
VisualizationServer.cpp File Reference

HTTP server serving a real-time DET visualization page on MPI rank 0. More...

#include "VisualizationServer.h"
#include "Server.h"
#include <httplib.h>
#include <json.hpp>
#include <thread>
#include <mpi.h>
Include dependency graph for VisualizationServer.cpp:

Go to the source code of this file.

Classes

struct  VisualizationServer::Impl
 

Typedefs

using json = nlohmann::json
 

Functions

function render (data)
 
function updateWorkers (data)
 
function niceNum (x)
 
treeContainer addEventListener ('mousedown',(e)=> { if(!e.shiftKey||e.button !==0) return;e.preventDefault();selecting=true;const rect=treeContainer.getBoundingClientRect();selStart={ x:e.clientX - rect.left+treeContainer.scrollLeft, y:e.clientY - rect.top+treeContainer.scrollTop };const box=document.getElementById('select-box');box.style.left=selStart.x+ 'px';box.style.top=selStart.y+ 'px';box.style.width='0';box.style.height='0';box.style.display='block';document.getElementById('select-toolbar').style.display='none';})
 
document addEventListener ('mousemove',(e)=> { if(!selecting) return;const rect=treeContainer.getBoundingClientRect();const curX=e.clientX - rect.left+treeContainer.scrollLeft;const curY=e.clientY - rect.top+treeContainer.scrollTop;const box=document.getElementById('select-box');const x=Math.min(selStart.x, curX);const y=Math.min(selStart.y, curY);const w=Math.abs(curX - selStart.x);const h=Math.abs(curY - selStart.y);box.style.left=x+ 'px';box.style.top=y+ 'px';box.style.width=w+ 'px';box.style.height=h+ 'px';})
 
document addEventListener ('mouseup',(e)=> { if(!selecting) return;selecting=false;const box=document.getElementById('select-box');const bx=parseFloat(box.style.left);const by=parseFloat(box.style.top);const bw=parseFloat(box.style.width);const bh=parseFloat(box.style.height);if(bw< 5||bh< 5) { box.style.display='none';return;} if(!cachedData) return;const { byParent, byId }=buildTree(cachedData.sequences||[]);const ordered=dfsOrder(cachedData.sequences||[]);const ROW_H=BASE_ROW_H *zoomLevel;const BAR_H=BASE_BAR_H *zoomLevel;const maxTime=Math.max(...(cachedData.sequences||[]).map(s=> s.end_time), 1);const W=Math.max(treeContainer.clientWidth - 10, 600);const xScale=(t)=> PAD_LEFT+(t/maxTime) *(W - PAD_LEFT - PAD_RIGHT);const yMap={};ordered.forEach((s, i)=> { yMap[s.id]=i;});selectedIds=[];const selSet=new Set();for(const s of ordered) { const yi=yMap[s.id];const x1=xScale(s.branch_time);const x2=xScale(s.end_time);const y=PAD_TOP+yi *ROW_H+(ROW_H - BAR_H)/2;if(x2 >=bx &&x1<=bx+bw &&y+BAR_H >=by &&y<=by+bh) { selSet.add(s.id);} } for(const s of ordered) { if(s.parent_id< 0||selSet.has(s.id)) continue;let ancestorId=s.parent_id;while(ancestorId >=0 &&yMap[ancestorId]===undefined) { const a=byId[ancestorId];if(!a) break;ancestorId=a.parent_id;} if(ancestorId< 0||yMap[ancestorId]===undefined) continue;const cx=xScale(s.branch_time);const py=PAD_TOP+yMap[ancestorId] *ROW_H+ROW_H/2;const cy=PAD_TOP+yMap[s.id] *ROW_H+ROW_H/2;const minY=Math.min(py, cy);const maxY=Math.max(py, cy);if(cx >=bx &&cx<=bx+bw &&maxY >=by &&minY<=by+bh) { selSet.add(s.id);} } selectedIds=[...selSet];if(selectedIds.length===0) { box.style.display='none';return;} const tb=document.getElementById('select-toolbar');const containerRect=treeContainer.getBoundingClientRect();tb.style.left=Math.min(bx+bw+4, treeContainer.clientWidth - 200)+ 'px';tb.style.top=Math.max(by - 4, 0)+ 'px';tb.style.display='flex';})
 
function selectionZoom ()
 
function selectionCollapse ()
 
function selectionHide ()
 
function clearSelection ()
 
document addEventListener ('click',(e)=> { const panel=document.getElementById('controls-panel');const btn=document.getElementById('controls-btn');if(panel.classList.contains('open') &&!panel.contains(e.target) &&e.target !==btn) { panel.classList.remove('open');} })
 
document getElementById ('tree-svg').addEventListener('click'
 
document getElementById ('tree-container').addEventListener('wheel'
 
async function poll ()
 
window addEventListener ('resize',()=> { if(cachedData) render(cachedData);})
 

Variables

let selecting = false
 
let selStart = { x: 0, y: 0 }
 
let selectedIds = []
 
const treeContainer = document.getElementById('tree-container')
 
document e
 
let polling = true
 
</script ></body ></html > html
 

Detailed Description

HTTP server serving a real-time DET visualization page on MPI rank 0.

Definition in file VisualizationServer.cpp.

Typedef Documentation

◆ json

using json = nlohmann::json

Definition at line 13 of file VisualizationServer.cpp.

Function Documentation

◆ addEventListener() [1/5]

document addEventListener ( 'click'  ,
(e)  ,
{ const panel=document.getElementById('controls-panel');const btn=document.getElementById('controls-btn');if(panel.classList.contains('open') &&!panel.contains(e.target) &&e.target !==btn) { panel.classList.remove('open');} }   
)

◆ addEventListener() [2/5]

treeContainer addEventListener ( 'mousedown'  ,
(e)  ,
{ if(!e.shiftKey||e.button !==0) return;e.preventDefault();selecting=true;const rect=treeContainer.getBoundingClientRect();selStart={ x:e.clientX - rect.left+treeContainer.scrollLeft, y:e.clientY - rect.top+treeContainer.scrollTop };const box=document.getElementById('select-box');box.style.left=selStart.x+ 'px';box.style.top=selStart.y+ 'px';box.style.width='0';box.style.height='0';box.style.display='block';document.getElementById('select-toolbar').style.display='none';}   
)

◆ addEventListener() [3/5]

document addEventListener ( 'mousemove'  ,
(e)  ,
{ if(!selecting) return;const rect=treeContainer.getBoundingClientRect();const curX=e.clientX - rect.left+treeContainer.scrollLeft;const curY=e.clientY - rect.top+treeContainer.scrollTop;const box=document.getElementById('select-box');const x=Math.min(selStart.x, curX);const y=Math.min(selStart.y, curY);const w=Math.abs(curX - selStart.x);const h=Math.abs(curY - selStart.y);box.style.left=x+ 'px';box.style.top=y+ 'px';box.style.width=w+ 'px';box.style.height=h+ 'px';}   
)

◆ addEventListener() [4/5]

document addEventListener ( 'mouseup'  ,
(e)  ,
{ if(!selecting) return;selecting=false;const box=document.getElementById('select-box');const bx=parseFloat(box.style.left);const by=parseFloat(box.style.top);const bw=parseFloat(box.style.width);const bh=parseFloat(box.style.height);if(bw< 5||bh< 5) { box.style.display='none';return;} if(!cachedData) return;const { byParent, byId }=buildTree(cachedData.sequences||[]);const ordered=dfsOrder(cachedData.sequences||[]);const ROW_H=BASE_ROW_H *zoomLevel;const BAR_H=BASE_BAR_H *zoomLevel;const maxTime=Math.max(...(cachedData.sequences||[]).map(s=> s.end_time), 1);const W=Math.max(treeContainer.clientWidth - 10, 600);const xScale=(t)=> PAD_LEFT+(t/maxTime) *(W - PAD_LEFT - PAD_RIGHT);const yMap={};ordered.forEach((s, i)=> { yMap[s.id]=i;});selectedIds=[];const selSet=new Set();for(const s of ordered) { const yi=yMap[s.id];const x1=xScale(s.branch_time);const x2=xScale(s.end_time);const y=PAD_TOP+yi *ROW_H+(ROW_H - BAR_H)/2;if(x2 >=bx &&x1<=bx+bw &&y+BAR_H >=by &&y<=by+bh) { selSet.add(s.id);} } for(const s of ordered) { if(s.parent_id< 0||selSet.has(s.id)) continue;let ancestorId=s.parent_id;while(ancestorId >=0 &&yMap[ancestorId]===undefined) { const a=byId[ancestorId];if(!a) break;ancestorId=a.parent_id;} if(ancestorId< 0||yMap[ancestorId]===undefined) continue;const cx=xScale(s.branch_time);const py=PAD_TOP+yMap[ancestorId] *ROW_H+ROW_H/2;const cy=PAD_TOP+yMap[s.id] *ROW_H+ROW_H/2;const minY=Math.min(py, cy);const maxY=Math.max(py, cy);if(cx >=bx &&cx<=bx+bw &&maxY >=by &&minY<=by+bh) { selSet.add(s.id);} } selectedIds=[...selSet];if(selectedIds.length===0) { box.style.display='none';return;} const tb=document.getElementById('select-toolbar');const containerRect=treeContainer.getBoundingClientRect();tb.style.left=Math.min(bx+bw+4, treeContainer.clientWidth - 200)+ 'px';tb.style.top=Math.max(by - 4, 0)+ 'px';tb.style.display='flex';}   
)

◆ addEventListener() [5/5]

window addEventListener ( 'resize'  ,
()  ,
{ if(cachedData) render(cachedData);}   
)

◆ clearSelection()

function clearSelection ( )

Definition at line 950 of file VisualizationServer.cpp.

◆ getElementById() [1/2]

document getElementById ( 'tree-container'  )

◆ getElementById() [2/2]

document getElementById ( 'tree-svg'  )

◆ niceNum()

function niceNum ( x  )

Definition at line 794 of file VisualizationServer.cpp.

◆ poll()

poll ( )

Definition at line 985 of file VisualizationServer.cpp.

◆ render()

function render ( data  )

Definition at line 558 of file VisualizationServer.cpp.

◆ selectionCollapse()

function selectionCollapse ( )

Definition at line 932 of file VisualizationServer.cpp.

◆ selectionHide()

function selectionHide ( )

Definition at line 943 of file VisualizationServer.cpp.

◆ selectionZoom()

function selectionZoom ( )

Definition at line 910 of file VisualizationServer.cpp.

◆ updateWorkers()

function updateWorkers ( data  )

Definition at line 773 of file VisualizationServer.cpp.

Variable Documentation

◆ e

document e
Initial value:
=> {
if (e.target.tagName === 'svg') {
highlightedId = null;
if (cachedData) render(cachedData);
}
})
document e
function render(data)

Definition at line 968 of file VisualizationServer.cpp.

Referenced by KBConcept::ActivationDecayOfConcept(), KBConcept::AddDataSetOfTheConceptBase(), KBConcept::BuidConnectionsWithinKBConcept(), RoutineMonitor::BuildConnectionsForRoutineMonitor(), InstantiationBase::BuildConnectionsForTheInstantiationBase(), EventSchemaUnit::BuildConnectionsForThisESU(), SymptomInvestigator::BuildConnectionsForThisSymptomInvestigator(), BranchProbability::calculateProbability(), MRAlarmUnit::CheckAlarmStateWithinTimeRange(), MRComponentStateUnit::CheckComponentStateWithinTimeRange(), KBConcept::checkExistanceOfConceptBasicUnit(), KBConcept::checkExistanceOfConceptComposedUnit(), InstantiationBase::CheckExistanceOfInstantiationGroupByIndefiniteConceptName(), InstantiationBase::CheckExistanceOfLabelGroupByName(), MRAlarmUnit::CheckFirstAlarmStateAfterATime(), MRSupportSystemStateUnit::CheckSupportSystemStateWithinTimeRange(), MRComponentStateUnit::CheckTheFirstComponentStateReadingAfterATime(), MRSupportSystemStateUnit::CheckTheFirstSupportSystemStateReadingAfterATime(), InstantiationBase::CheckWhetherASentenceContainIndefiniteItem(), adsidac::compute_config_fingerprint(), KBConcept::ConvertConnectionToStringForm(), EventSchemaUnit::ConvertESUinfoToString(), InstantiationBase::ConvertIBInfoToStringForm(), EventSchemaBase::ConvertStaticESBinfoToString(), CommunicationPlace::copyCommunicationPlace(), EventSchemaBase::CopyESBinfoFromAnother(), EventSchemaUnit::CopyESUInfoWithoutPointerFromAnother(), PassiveAlarmLoadUnit::CopyFromAnotherPassiveAlarmLoadUnit(), InstantiationBase::CopyInstantiationBaseFromAnotherIB(), MRAlarmUnit::CopyMRAlarmUnitInfoFromAnother(), MRComponentStateUnit::CopyMRComponentStateInfoFromAnother(), MRParameterUnit::CopyMRParameterUnitInforFromAnother(), MRSupportSystemStateUnit::CopyMRSupportSystemStateUnitInfoFromAnother(), ProximityModel::CopyProximityModelFromAnother(), RoutineMonitor::CopyRoutineMonitorInfoFromAnother(), KBConcept::CopyStaticKBConceptFromAnother(), SymptomInvestigator::CopySymptomInvestigatorInfoFromAnother(), EventSchemaBase::CrossCheckProcedureUse(), adsidac::merge::discover_ranks(), Server::dispatch_resume_tasks(), KBConcept::FillTheConceptCompsedUnitUpdateList(), EventSchemaBase::FindACorrespondingDiagnoseInvestigatorByKE(), EventSchemaBase::FindACorrespondingEventSchemaUnitByKE(), ProximityModel::FindAProximityGroupUnitByOneMemberName(), SymptomInvestigator::FindASymptomCaseByInvestigator(), KBConcept::FindConceptByID(), EventSchemaBase::FindDiagnoseInvestigatorByID(), EventSchemaBase::FindEventSchemaUnitByID(), MRComponentStateUnit::FindTheFirstPositionReadingAfterATime(), MRComponentStateUnit::FoundAPositionReadingWithinTimeRange(), MRParameterUnit::FoundAValueReadingWithinTimeRange(), RoutineMonitor::GetaMonitorUnit11(), SymptomInvestigator::GetTheLastRejectionTime(), RoutineMonitor::GetTheLongestIntervalRatio(), adsidac::load_array_state(), main(), Server::merge_outputs(), Scheduler::parseOptions(), KBConcept::PropagateActivationAmongComposedConceptBottomUp(), KBConcept::PropagateActivationFromBasicConceptToComposedConcept(), bncore::BatchWorkspace::query_marginals_multi(), KBConcept::ReconstructThePointerLinks(), adsidac::save_array_state(), KBConcept::SaveActivationToOldActivationVariable(), KBConcept::SaveConceptActivationIntoOutputFile(), ControlVariable::saveControlVariableToFile(), DisplayParameterValueRate::saveDisplayParameterValueRateToFile(), DisplayParameterValue::saveDisplayParameterValueToFile(), ExpectationORUnit::saveExpectationORUnitToFile(), HydraulicJunction::saveHydraulicJunctionToFile(), HydraulicVolume::saveHydraulicVolumeToFile(), CommunicationPlace::saveInfoToFileAsBranchForADSV1(), KeyParameterHistoryUnit::saveKeyParameterHistoryUnitToFile(), MentalParameterValue::saveMentalParameterValueToFile(), MentalRepresentation::SaveMentalRepresentationInforToFile(), ProcedureStepUnit::saveProcedureStepUnitExpectationToFile(), BranchProbability::sendBranchInfoToCommandCenter(), RestApiSolver::sendInterventions(), boost::serialization::serialize(), KBConcept::SetActivationChangeOfConceptBasicUnitsBackToOne(), KBConcept::SetActivationChangeOfConceptComposedUnitsBackToOne(), EventSymptomMatrix::state_load(), ExpectationORUnit::state_load(), EventSymptomMatrix::state_save(), ExpectationORUnit::state_save(), EventSchemaBase::TrackTheOngoingInvestigation(), CommunicationPlace::updateSenderReceiverInfo(), EventSchemaBase::UpdateTheBranchingHistory(), and EventSchemaBase::WhetherItIsNormalOperating().

◆ html

</script></body></html> html

Definition at line 1002 of file VisualizationServer.cpp.

◆ polling

let polling = true

Definition at line 984 of file VisualizationServer.cpp.

◆ selectedIds

let selectedIds = []

Definition at line 809 of file VisualizationServer.cpp.

◆ selecting

let selecting = false

Definition at line 807 of file VisualizationServer.cpp.

◆ selStart

let selStart = { x: 0, y: 0 }

Definition at line 808 of file VisualizationServer.cpp.

◆ treeContainer

const treeContainer = document.getElementById('tree-container')

Definition at line 811 of file VisualizationServer.cpp.