File size: 1,224 Bytes
c964813
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Plot from "react-plotly.js";
import type { Data } from "plotly.js";

import type { Trajectory } from "./useOptimisation";

// f at each iteration, one line per run
export default function HistoryPlot({ trajectories }: { trajectories: Trajectory[] }) {
  const data = trajectories.map((t) => ({
    x: t.path.map((_, k) => k),
    y: t.path.map((p) => p.value),
    type: "scatter",
    mode: "lines+markers",
    name: t.label,
    line: { color: t.color, width: 2 },
    marker: { color: t.color, size: 4 },
    hovertemplate: "iteration %{x}<br>f = %{y:.4g}<extra></extra>",
  })) as Data[];

  return (
    <div className="flex flex-col gap-1">
      <span className="text-sm text-gray-700">f at each iteration</span>
      <div className="h-40">
        <Plot
          data={data}
          layout={{
            showlegend: false,
            margin: { t: 8, r: 8, b: 32, l: 48 },
            font: { size: 11 },
            xaxis: { title: { text: "iteration", standoff: 4 }, rangemode: "tozero" },
            yaxis: { automargin: true },
          }}
          config={{ displayModeBar: false, responsive: true }}
          style={{ width: "100%", height: "100%" }}
        />
      </div>
    </div>
  );
}