Skip to content

Commit

Permalink
Merge pull request #517 from silx-kit/aux-signals
Browse files Browse the repository at this point in the history
useNxData now gets auxiliary_signals attr and associated datasets
  • Loading branch information
loichuder authored Feb 23, 2021
2 parents cd0a604 + b17cae9 commit 8d796d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/h5web/vis-packs/nexus/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ function useTitleDataset(
return dataset;
}

function useAxesDatasets(
group: Group
function useAssociatedDatasets(
group: Group,
type: 'axes' | 'auxiliary_signals'
): (Dataset<HDF5SimpleShape, HDF5NumericType> | undefined)[] {
const { valuesStore } = useContext(ProviderContext);

const axisList = getAttributeValue(group, 'axes') || [];
const axisNames = typeof axisList === 'string' ? [axisList] : axisList;
assertArray<string>(axisNames);
const dsetList = getAttributeValue(group, type) || [];
const dsetNames = typeof dsetList === 'string' ? [dsetList] : dsetList;
assertArray<string>(dsetNames);

return axisNames.map((name) => {
return dsetNames.map((name) => {
if (name === '.') {
return undefined;
}
Expand All @@ -81,8 +82,11 @@ export function useNxData(group: Group): NxData {
signalDataset,
errorsDataset: findErrorsDataset(group, signalDataset.name),
titleDataset: useTitleDataset(group),
axisDatasetMapping: useAxesDatasets(group),
axisDatasetMapping: useAssociatedDatasets(group, 'axes'),
silxStyle: getSilxStyle(group),
auxiliaryDatasets: useAssociatedDatasets(group, 'auxiliary_signals').filter(
isDefined
),
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/h5web/vis-packs/nexus/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export type NxAttribute =
| 'default'
| 'long_name'
| 'units'
| 'SILX_style';
| 'SILX_style'
| 'auxiliary_signals';

export enum NxInterpretation {
Spectrum = 'spectrum',
Expand All @@ -28,6 +29,7 @@ export interface NxData {
titleDataset?: Dataset<HDF5ScalarShape, HDF5StringType>;
axisDatasetMapping: AxisDatasetMapping;
silxStyle: SilxStyle;
auxiliaryDatasets: Dataset<HDF5SimpleShape, HDF5NumericType>[];
}

export type AxisDatasetMapping = (
Expand Down

0 comments on commit 8d796d2

Please sign in to comment.