Skip to content

Commit 0ae230b

Browse files
make bias plot x-axis values same as step and sweep plots (#36)
Make bias plot x-axis values same as step and sweep plots with and without step to sweep delay
1 parent 22808b7 commit 0ae230b

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

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

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { MatIconModule } from '@angular/material/icon';
2222
import { BrowserModule } from '@angular/platform-browser';
2323
import { parseToDecimal } from '../../../controls/input-parser.util';
2424
import { PlotUtils } from '../plot-utils';
25+
import { StepGlobalParameters } from '../../../../model/sweep_data/stepSweepConfig';
2526

2627
@Component({
2728
selector: 'app-plot-bias',
@@ -38,6 +39,7 @@ export class PlotBiasComponent
3839
// @Input() plotLayout: any;
3940
@Input() plotDataX: number[] = [];
4041
@Input() plotConfig: { staticPlot: boolean } | undefined;
42+
@Input() stepGlobalParameters: StepGlobalParameters | undefined;
4143
plotDivID = '';
4244

4345
@Input() isActive = false;
@@ -203,12 +205,20 @@ export class PlotBiasComponent
203205
this.bias = this.biasChannel.bias;
204206

205207
this.plotDivID = `plotDiv${this.biasChannel.common_chan_attributes.chan_name}`;
206-
for (let i = 0; i < 11; i++) {
207-
this.plotData1.y[i] = this.bias?.value ?? 0;
208-
}
209208
}
210-
// console.log(this.plotDataX, this.plotData);
211-
this.plotData1.x = this.plotDataX;
209+
210+
// Generate x-axis data if stepGlobalParameters are available
211+
if (this.stepGlobalParameters) {
212+
this.generateXAxisData();
213+
} else {
214+
// Fallback to plotDataX if provided
215+
this.plotData1.x = this.plotDataX.length > 0 ? this.plotDataX : [0];
216+
}
217+
218+
// Set constant y-values for bias
219+
const biasValue = this.bias?.value ?? 0;
220+
this.plotData1.y = new Array(this.plotData1.x.length).fill(biasValue);
221+
212222
this.updatePlotLayout();
213223
this.plotData1.line.color = this.color;
214224

@@ -221,6 +231,13 @@ export class PlotBiasComponent
221231
console.log('isActive changed:', changes['isActive'].currentValue);
222232
this.renderPlot(); // Re-render the plot when isActive changes
223233
}
234+
235+
// Re-generate x-axis data when stepGlobalParameters change
236+
if (changes['stepGlobalParameters'] && this.stepGlobalParameters) {
237+
this.generateXAxisData();
238+
this.updatePlotLayout();
239+
}
240+
224241
this.observeThemeChanges();
225242
}
226243

@@ -255,6 +272,26 @@ export class PlotBiasComponent
255272
console.log('Plot resized to:', this.plotLayout.width);
256273
}
257274

275+
private generateXAxisData(): void {
276+
if (!this.stepGlobalParameters) return;
277+
278+
const numSteps = this.stepGlobalParameters.step_points?.value ?? 1;
279+
const delayTime = this.stepGlobalParameters.step_to_sweep_delay?.value ?? 0;
280+
281+
// Generate x-axis data using the same formula as step and sweep components
282+
const xData: number[] = [];
283+
for (let i = 0; i <= numSteps; i++) {
284+
xData.push(i * (1 + delayTime));
285+
}
286+
287+
this.plotData1.x = xData;
288+
289+
// Calculate total time and dtick (same as step/sweep components)
290+
const totalTime = numSteps * (1 + delayTime);
291+
this.plotLayout.xaxis.dtick = totalTime / 10;
292+
this.plotLayout.xaxis2.dtick = totalTime / 10;
293+
}
294+
258295
private updatePlotLayout(): void {
259296
if (this.sourceFunction) {
260297
this.plotLayout.yaxis2.ticksuffix =

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[biasChannel]="biasChannel"
55
[plotDataX]="plotDataX"
66
[plotConfig]="plotConfig"
7+
[stepGlobalParameters]="stepGlobalParameters"
78
[isActive]="activeComponent === 'bias' && activeIndex === i"
89
[activeStyle]="getActiveStyle(biasChannel.common_chan_attributes.uuid, 'bias', i)"
910
[color]="getColor(biasChannel.common_chan_attributes.uuid)"

0 commit comments

Comments
 (0)