Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dccviewer-js
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benedikt
dccviewer-js
Commits
f4e05737
Commit
f4e05737
authored
2 months ago
by
Benedikt
Browse files
Options
Downloads
Patches
Plain Diff
improved siReal handling
parent
09fe8d45
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/dccQuantity.js
+17
-40
17 additions, 40 deletions
src/dccQuantity.js
with
17 additions
and
40 deletions
src/dccQuantity.js
+
17
−
40
View file @
f4e05737
// src/dccQuantity.js
import
{
DSIUnit
}
from
"
dsiunits-js/src/dsiUnit.js
"
;
// Import the unit input component if needed:
// import "dsi-units-js-lib/src/dsiUnitInput.js";
/**
* Base class for a DCC quantity.
* Holds a pointer to the original JSON data.
*/
export
class
DCCQuantity
{
constructor
(
jsonData
)
{
this
.
jsonData
=
jsonData
;
}
/**
* Returns the refType attribute of the quantity.
*/
getRefType
()
{
return
(
this
.
jsonData
.
$
&&
this
.
jsonData
.
$
.
refType
)
?
this
.
jsonData
.
$
.
refType
:
''
;
}
/**
* Returns the quantity name in the specified language.
* @param {string} language - e.g., 'en', 'de'
*/
getName
(
language
)
{
const
nameData
=
this
.
jsonData
[
'
dcc:name
'
];
if
(
!
nameData
)
return
''
;
...
...
@@ -30,23 +17,16 @@ export class DCCQuantity {
if
(
Array
.
isArray
(
content
))
{
const
match
=
content
.
find
(
item
=>
item
.
$
&&
item
.
$
.
lang
===
language
)
||
content
[
0
];
return
match
.
_
||
match
;
}
else
{
return
content
.
_
||
content
;
}
return
content
.
_
||
content
;
}
}
/**
* Class for quantities represented by <si:realListXMLList>.
*/
export
class
DCCRealListQuantity
extends
DCCQuantity
{
constructor
(
jsonData
)
{
super
(
jsonData
);
}
/**
* Extracts and returns an array of numeric values.
*/
getValues
()
{
const
realList
=
this
.
jsonData
[
'
si:realListXMLList
'
];
if
(
realList
&&
realList
[
'
si:valueXMLList
'
])
{
...
...
@@ -58,26 +38,20 @@ export class DCCRealListQuantity extends DCCQuantity {
return
[];
}
/**
* Returns the unit string rendered as HTML using the dsi-units-js library.
*/
getUnit
()
{
const
realList
=
this
.
jsonData
[
'
si:realListXMLList
'
];
if
(
realList
&&
realList
[
'
si:unitXMLList
'
])
{
const
rawUnit
=
realList
[
'
si:unitXMLList
'
].
trim
();
const
unit
=
new
DSIUnit
(
rawUnit
);
// Render the unit in a one-line format
return
unit
.
toHTML
({
oneLine
:
true
});
}
return
''
;
}
/**
* Extracts and returns an array of uncertainty values.
*/
getUncertainty
()
{
const
realList
=
this
.
jsonData
[
'
si:realListXMLList
'
];
if
(
realList
&&
realList
[
'
si:measurementUncertaintyUnivariateXMLList
'
]
&&
realList
[
'
si:measurementUncertaintyUnivariateXMLList
'
][
'
si:expandedMUXMLList
'
]
&&
realList
[
'
si:measurementUncertaintyUnivariateXMLList
'
][
'
si:expandedMUXMLList
'
][
'
si:valueExpandedMUXMLList
'
]
...
...
@@ -89,19 +63,12 @@ export class DCCRealListQuantity extends DCCQuantity {
}
}
/**
* Class for quantities represented by a single <si:real>.
* (This class is provided for completeness and may be expanded as needed.)
*/
export
class
DCCRealQuantity
extends
DCCQuantity
{
constructor
(
jsonData
)
{
super
(
jsonData
);
}
/**
* Returns the numeric value from the <si:real> element.
*/
getValue
()
{
getValues
()
{
const
realData
=
this
.
jsonData
[
'
si:real
'
];
if
(
realData
&&
realData
[
'
si:value
'
])
{
return
parseFloat
(
realData
[
'
si:value
'
]);
...
...
@@ -109,9 +76,6 @@ export class DCCRealQuantity extends DCCQuantity {
return
null
;
}
/**
* Returns the unit rendered as HTML.
*/
getUnit
()
{
const
realData
=
this
.
jsonData
[
'
si:real
'
];
if
(
realData
&&
realData
[
'
si:unit
'
])
{
...
...
@@ -121,4 +85,17 @@ export class DCCRealQuantity extends DCCQuantity {
}
return
''
;
}
}
\ No newline at end of file
getUncertainty
()
{
const
realList
=
this
.
jsonData
[
'
si:real
'
];
if
(
realList
&&
realList
[
'
si:measurementUncertaintyUnivariate
'
]
&&
realList
[
'
si:measurementUncertaintyUnivariate
'
][
'
si:expandedMU
'
]
&&
realList
[
'
si:measurementUncertaintyUnivariate
'
][
'
si:expandedMU
'
][
'
si:valueExpandedMU
'
]
)
{
const
errStr
=
realList
[
'
si:measurementUncertaintyUnivariate
'
][
'
si:expandedMU
'
][
'
si:valueExpandedMU
'
];
return
errStr
.
trim
().
split
(
/
\s
+/
).
map
(
v
=>
parseFloat
(
v
));
}
return
[];
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment