Skip to content

Commit bc732e6

Browse files
fix sweep plot x values for increasing number of points (#14)
1 parent 5255755 commit bc732e6

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

script-gen-ui/src/app/components/main-sweep/plot-container/plot-sweep/plot-sweep.component.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ import { PlotUtils } from '../plot-utils';
3636
styleUrl: './plot-sweep.component.scss',
3737
})
3838
export class PlotSweepComponent
39-
implements AfterViewInit, OnInit, OnDestroy, OnChanges
40-
{
39+
implements AfterViewInit, OnInit, OnDestroy, OnChanges {
4140
@Input() sweepChannel: SweepChannel | undefined;
4241
@Input() sweepGlobalParameters: SweepGlobalParameters | undefined;
4342
@Input() stepGlobalParameters: StepGlobalParameters | undefined;
@@ -91,6 +90,7 @@ export class PlotSweepComponent
9190
size: 9,
9291
},
9392
dtick: 1,
93+
range: [0, 10],
9494
// tick0: 0,
9595
showtickprefix: 'none',
9696
showticksuffix: 'all',
@@ -207,7 +207,7 @@ export class PlotSweepComponent
207207
};
208208
private plotData = [this.plotData1, this.plotData2];
209209

210-
constructor(public elementRef: ElementRef) {}
210+
constructor(public elementRef: ElementRef) { }
211211

212212
ngOnChanges(changes: SimpleChanges): void {
213213
if (changes['isActive'] && !changes['isActive'].isFirstChange()) {
@@ -291,26 +291,31 @@ export class PlotSweepComponent
291291
}
292292
}
293293

294-
private generatePlotDataxy(sweepValues: number[]) {
294+
private generatePlotDataxy(sweepValues: number[], xData?: number[]) {
295295
if (this.numPoints && this.numSteps) {
296296
const numSteps = this.numSteps;
297297
const numberOfPoints = this.numPoints?.value;
298298
this.plotData1.y = Array.from({ length: numSteps }, () => sweepValues)
299299
.flat()
300300
.concat(sweepValues[sweepValues.length - 1]);
301301

302-
this.plotData1.x = Array.from({ length: numSteps }, (_, i) =>
303-
Array.from({ length: numberOfPoints }, (_, j) => i + j / numberOfPoints)
304-
)
305-
.flat()
306-
.concat(numSteps);
302+
if (xData) {
303+
this.plotData1.x = xData;
304+
} else {
305+
this.plotData1.x = Array.from({ length: numSteps }, (_, i) =>
306+
Array.from({ length: numberOfPoints }, (_, j) => i + j / numberOfPoints)
307+
)
308+
.flat()
309+
.concat(numSteps);
310+
}
307311
}
308312
}
309313

310314
private generatePlotData(sweepValues: number[], type: string) {
311315
if (this.numPoints && this.numSteps) {
312-
const targetLength = this.plotWidth / this.numPoints.value;
316+
const targetLength = this.plotWidth / this.numSteps;
313317
if (this.numPoints?.value > targetLength) {
318+
let xData: number[] = [];
314319
if (type == 'LIN') {
315320
const interpolated = PlotUtils.linearInterpolation(
316321
sweepValues,
@@ -324,11 +329,14 @@ export class PlotSweepComponent
324329
);
325330
sweepValues = interpolated.y;
326331
}
327-
this.generatePlotDataxy(sweepValues);
332+
xData = Array.from({ length: this.numSteps }, (_, i) =>
333+
Array.from({ length: sweepValues.length }, (_, j) => i + j / sweepValues.length)).flat().concat(this.numSteps)
334+
this.generatePlotDataxy(sweepValues, xData);
328335
} else {
329336
this.generatePlotDataxy(sweepValues);
330337
}
331338
this.plotLayout.xaxis.dtick = this.numSteps / 10;
339+
this.plotLayout.xaxis.range = [0, this.numSteps];
332340
}
333341
}
334342

0 commit comments

Comments
 (0)