Skip to content

Commit

Permalink
fix #7192 replace Array.toReversed() which isn't always available (#7194
Browse files Browse the repository at this point in the history
)
  • Loading branch information
moellep committed Jul 26, 2024
1 parent 67c02d0 commit e843e65
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions sirepo/package_data/static/js/openmc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,16 @@ SIREPO.app.directive('geometry2d', function(appState, openmcService, panelState,
.attr('fill', d => sourceColor(d));
}

function toReversed(arr) {
// Array.toReversed() is not available in all active browsers
// not using a polyfill due to array iteration bugs
const r = [];
for (let i = (arr.length - 1); i >= 0; --i) {
r.push(arr[i]);
}
return r;
}

const outlines = [];
const dim = SIREPO.GEOMETRY.GeometryUtils.BASIS()[dimIndex];
for (const volId of openmcService.getNonGraveyardVolumes()) {
Expand All @@ -1112,7 +1122,7 @@ SIREPO.app.directive('geometry2d', function(appState, openmcService, panelState,
outlines.push({
name: `source-${s.particle}-${s.space._type}-${i}`,
color: sourceColor('#ff0000'),
data: view.shapePoints(dim).map(p => p.toReversed()),
data: view.shapePoints(dim).map(p => toReversed(p)),
doClose: true,
});
});
Expand All @@ -1132,7 +1142,7 @@ SIREPO.app.directive('geometry2d', function(appState, openmcService, panelState,
name: `${p.type}-${p.energy}eV-${n}`,
color: sourceColor(particleColor(p)),
dashes: p.type === 'PHOTON' ? '6 2' : '',
data: [p1, p2].map(p => p.toReversed()),
data: [p1, p2].map(p => toReversed(p)),
marker: particleId(p),
});
});
Expand Down Expand Up @@ -2048,9 +2058,10 @@ SIREPO.app.directive('volumeSelector', function(appState, openmcService, panelSt

loadRows();

for (const i in $scope.rows) {
for (let i = 0; i < $scope.rows.length; i++) {
for (const p of ['color', 'opacity']) {
$scope.$watch(`rows[${i}].${p}`, () => broadcastVolumePropertyChanged(i, p));
const i2 = i;
$scope.$watch(`rows[${i}].${p}`, () => broadcastVolumePropertyChanged(i2, p));
}
}
},
Expand Down

0 comments on commit e843e65

Please sign in to comment.