{
const div = DOM.element("div");
function mkTrace(jetPnt, bombPnts, jetPnts) {
const n = bombPnts.length,
m = parseInt(n / 5),
data = [jetPnt, targetPnt, bombPnts[n - 1]],
bombTextPnts = bombPnts.filter((d, i) => i % m === 0),
traceLine = {
name: "Eyesight",
x: data.map((d) => d.x),
y: data.map((d) => d.y),
z: data.map((d) => d.z),
type: "scatter3d",
mode: "lines",
opacity: 1,
line: {
width: 3,
color: jetPnt.color
}
},
frameShip = {
name: "Ship",
x: shipDesign.map((d) => d.x),
y: shipDesign.map((d) => d.y),
z: shipDesign.map((d) => d.z),
type: "scatter3d",
mode: "lines",
opacity: 1,
line: {
width: 3,
color: "gray"
}
},
tracePnt = {
name: "Key points",
x: data.map((d) => d.x),
y: data.map((d) => d.y),
z: data.map((d) => d.z),
type: "scatter3d",
mode: "markers",
marker: {
size: 5,
color: data.map((d) => (d.color ? d.color : "gray"))
}
},
traceBomb = {
name: "Bomb trace",
x: bombPnts.map((d) => d.x),
y: bombPnts.map((d) => d.y),
z: bombPnts.map((d) => d.z),
type: "scatter3d",
mode: "markers",
opacity: 0.1,
marker: {
size: 5,
color: d3.color(jetPnt.color).darker().hex()
}
},
traceJet = {
name: "Jet trace",
x: jetPnts.map((d) => d.x),
y: jetPnts.map((d) => d.y),
z: jetPnts.map((d) => d.z),
type: "scatter3d",
mode: "markers",
opacity: 0.1,
marker: {
size: 3,
color: d3.color(jetPnt.color).darker().hex()
}
},
traceBombText = {
name: "Bomb trace",
x: bombTextPnts.map((d) => d.x),
y: bombTextPnts.map((d) => d.y),
z: bombTextPnts.map((d) => d.z),
text: bombTextPnts.map((d) => d.t.toFixed(2)),
type: "scatter3d",
mode: "text",
opacity: 0.9
};
return [traceLine, tracePnt, traceBomb, traceJet, traceBombText, frameShip];
}
const traceIdeal = mkTrace(jetPnt, bombPnts, jetPnts),
traceTurning = mkTrace(turningJetPnt, turningBombPnts, []);
const trace = traceIdeal.concat(traceTurning);
Plotly.newPlot(div, trace, layout);
return div;
}