updated the api to use a new variable for whether to load all nodes, this will still use the show errors boolean for the component page

fixed issue in the filter function in the grain cable model that caused it to return empty when a top node was not set
updated the bin svg to have the disabled nodes greyed out
This commit is contained in:
csawatzky 2025-07-31 13:20:31 -06:00
parent 35e8996c29
commit 23223aa1a8
10 changed files with 134 additions and 109 deletions

View file

@ -10,10 +10,12 @@ export class GrainCable {
public settings: pond.ComponentSettings = pond.ComponentSettings.create();
public status: pond.ComponentStatus = pond.ComponentStatus.create();
public lastReading: string = "";
//bear in mind these three arrays are reversed due to the bin svg needing the first node on the bottom of the image and the svg being drawn from the top
public temperatures: number[] = [];
public humidities: number[] = [];
public grainMoistures: number[] = [];
public topNode: number = 0;
public excludedNodes: number[] = [];
public static create(comp: Component): GrainCable {
let my = new GrainCable();
@ -58,6 +60,7 @@ export class GrainCable {
my.grainMoistures = emc;
my.lastReading = lastReading;
my.topNode = comp.settings.grainFilledTo;
my.excludedNodes = comp.settings.excludedNodes;
return my;
}
@ -239,4 +242,41 @@ export class GrainCable {
component.lastMeasurement = lastMeasurements;
return component;
}
/**
* Filters out the excluded nodes and anything above the top node of the cable, note that the nodes are reversed during creation if a grain cable ie: node 1 is the end of the array
*
* @param unReversed will tell the function to reverse the array back to its original state
* @returns array of active node values
*/
public filteredNodes(unReversed?: boolean): {temps: number[], humids: number[], moistures: number[]} {
//make clones of the node values and reverse them back to their original state for index purposes
let temps: number [] = cloneDeep(this.temperatures).reverse()
let humids: number [] = cloneDeep(this.humidities).reverse()
let moistures: number[] = cloneDeep(this.grainMoistures).reverse()
//filter out the excluded nodes
temps = this.filter(temps)
humids = this.filter(humids)
moistures = this.filter(moistures)
if(!unReversed){
temps.reverse()
humids.reverse()
moistures.reverse()
}
return {temps, humids, moistures}
}
private filter(values: number[]): number[] {
let filtered: number[] = []
values.forEach((val, index) => {
//if the node is not excluded AND is either under the top node OR top node is not set
if(!this.excludedNodes.includes(index) && (index <= this.topNode || this.topNode === 0)){
filtered.push(val)
}
})
return filtered
}
}