99 assertStringType ,
1010 hasArrayShape ,
1111 hasNonNullShape ,
12- hasScalarShape ,
1312 hasStringType ,
1413 isAxisScaleType ,
1514 isColorScaleType ,
@@ -30,7 +29,12 @@ import { getChildEntity } from '@h5web/shared/hdf5-utils';
3029import { castArray } from '@h5web/shared/vis-utils' ;
3130
3231import { type AttrValuesStore } from '../../providers/models' ;
33- import { findAttribute , getAttributeValue , hasAttribute } from '../../utils' ;
32+ import {
33+ findAttribute ,
34+ findScalarStrAttr ,
35+ getAttributeValue ,
36+ hasAttribute ,
37+ } from '../../utils' ;
3438import {
3539 type AxisDef ,
3640 type DatasetInfo ,
@@ -42,11 +46,7 @@ export function getNxClass(
4246 group : Group ,
4347 attrValuesStore : AttrValuesStore ,
4448) : string | undefined {
45- const attr = findAttribute ( group , 'NX_class' ) ;
46- if ( ! attr || ! hasScalarShape ( attr ) || ! hasStringType ( attr ) ) {
47- return undefined ;
48- }
49-
49+ const attr = findScalarStrAttr ( group , 'NX_class' ) ;
5050 return getAttributeValue ( group , attr , attrValuesStore ) ;
5151}
5252
@@ -194,8 +194,8 @@ function findOldStyleAxesDatasets(
194194 signal : Dataset ,
195195 attrValuesStore : AttrValuesStore ,
196196) : Dataset < ArrayShape , NumericType > [ ] {
197- const axesAttr = findAttribute ( signal , 'axes' ) ;
198- if ( ! axesAttr || ! hasScalarShape ( axesAttr ) || ! hasStringType ( axesAttr ) ) {
197+ const axesAttr = findScalarStrAttr ( signal , 'axes' ) ;
198+ if ( ! axesAttr ) {
199199 return [ ] ;
200200 }
201201
@@ -309,13 +309,8 @@ export function getSilxStyle(
309309 group : Group ,
310310 attrValuesStore : AttrValuesStore ,
311311) : SilxStyle {
312- const silxStyleAttr = findAttribute ( group , 'SILX_style' ) ;
313-
314- if (
315- ! silxStyleAttr ||
316- ! hasScalarShape ( silxStyleAttr ) ||
317- ! hasStringType ( silxStyleAttr )
318- ) {
312+ const silxStyleAttr = findScalarStrAttr ( group , 'SILX_style' ) ;
313+ if ( ! silxStyleAttr ) {
319314 return { } ;
320315 }
321316
@@ -348,18 +343,11 @@ export function getDatasetInfo(
348343 dataset : Dataset ,
349344 attrValuesStore : AttrValuesStore ,
350345) : DatasetInfo {
351- const longNameAttr = findAttribute ( dataset , 'long_name' ) ;
352- const unitsAttr = findAttribute ( dataset , 'units' ) ;
353-
354- const longName =
355- longNameAttr && hasScalarShape ( longNameAttr ) && hasStringType ( longNameAttr )
356- ? getAttributeValue ( dataset , longNameAttr , attrValuesStore )
357- : undefined ;
358-
359- const units =
360- unitsAttr && hasScalarShape ( unitsAttr ) && hasStringType ( unitsAttr )
361- ? getAttributeValue ( dataset , unitsAttr , attrValuesStore )
362- : undefined ;
346+ const longNameAttr = findScalarStrAttr ( dataset , 'long_name' ) ;
347+ const longName = getAttributeValue ( dataset , longNameAttr , attrValuesStore ) ;
348+
349+ const unitsAttr = findScalarStrAttr ( dataset , 'units' ) ;
350+ const units = getAttributeValue ( dataset , unitsAttr , attrValuesStore ) ;
363351
364352 return {
365353 label : longName || ( units ? `${ dataset . name } (${ units } )` : dataset . name ) ,
0 commit comments