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
16030d3b
Commit
16030d3b
authored
2 months ago
by
Benedikt
Browse files
Options
Downloads
Patches
Plain Diff
influence condition render now uses correctly parsed units in header.
parent
abba0688
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/renderers/InfluenceConditionsRenderer.js
+44
-28
44 additions, 28 deletions
src/renderers/InfluenceConditionsRenderer.js
with
44 additions
and
28 deletions
src/renderers/InfluenceConditionsRenderer.js
+
44
−
28
View file @
16030d3b
...
@@ -19,27 +19,28 @@ export class InfluenceConditionsRenderer {
...
@@ -19,27 +19,28 @@ export class InfluenceConditionsRenderer {
conditions
=
[
conditions
];
conditions
=
[
conditions
];
}
}
conditions
.
forEach
(
condition
=>
{
conditions
.
forEach
(
condition
=>
{
// Create collapsible section for each influence condition
// Create
a
collapsible section for each influence condition
const
details
=
document
.
createElement
(
'
details
'
);
const
details
=
document
.
createElement
(
'
details
'
);
details
.
style
.
border
=
'
1px solid #ccc
'
;
details
.
style
.
border
=
'
1px solid #ccc
'
;
details
.
style
.
padding
=
'
8px
'
;
details
.
style
.
padding
=
'
8px
'
;
details
.
style
.
marginBottom
=
'
10px
'
;
details
.
style
.
marginBottom
=
'
10px
'
;
// Summary always shows condition name and
(
if only one quantity
)
its value
/unit
// Summary
:
always
visible,
shows
the
condition name and
,
if only one quantity
exists,
its value
(plain text)
const
summary
=
document
.
createElement
(
'
summary
'
);
const
summary
=
document
.
createElement
(
'
summary
'
);
const
condName
=
this
.
_getText
(
condition
[
'
dcc:name
'
]);
const
condName
=
this
.
_getText
(
condition
[
'
dcc:name
'
]);
let
summaryText
=
condName
;
let
summaryText
=
condName
;
const
quantities
=
this
.
_getQuantities
(
condition
);
const
quantities
=
this
.
_getQuantities
(
condition
);
if
(
quantities
.
length
===
1
)
{
if
(
quantities
.
length
===
1
)
{
//
If only one quantity, append
i
t
s
value and unit
//
Use plain flag for summary display so that HTML
is
not double-escaped
const
qty
=
quantities
[
0
];
const
qty
=
quantities
[
0
];
const
valueStr
=
this
.
_formatQuantity
(
qty
);
const
valueStr
=
this
.
_formatQuantity
(
qty
,
true
);
summaryText
+=
`
:
${
valueStr
}
`
;
summaryText
+=
`
:
${
valueStr
}
`
;
}
}
summary
.
textContent
=
summaryText
;
// Use innerHTML here so that any HTML markup in the unit is rendered
summary
.
innerHTML
=
summaryText
;
details
.
appendChild
(
summary
);
details
.
appendChild
(
summary
);
// Expanded content: description and quantities table
// Expanded content:
condition
description and quantities table
const
contentDiv
=
document
.
createElement
(
'
div
'
);
const
contentDiv
=
document
.
createElement
(
'
div
'
);
contentDiv
.
style
.
marginTop
=
'
8px
'
;
contentDiv
.
style
.
marginTop
=
'
8px
'
;
contentDiv
.
style
.
fontFamily
=
'
sans-serif
'
;
contentDiv
.
style
.
fontFamily
=
'
sans-serif
'
;
...
@@ -49,14 +50,16 @@ export class InfluenceConditionsRenderer {
...
@@ -49,14 +50,16 @@ export class InfluenceConditionsRenderer {
p
.
textContent
=
descText
;
p
.
textContent
=
descText
;
contentDiv
.
appendChild
(
p
);
contentDiv
.
appendChild
(
p
);
}
}
// Render quantities table
(
if a
ny)
// Render quantities table if a
vailable
if
(
condition
[
'
dcc:data
'
]
&&
condition
[
'
dcc:data
'
][
'
dcc:quantity
'
])
{
if
(
condition
[
'
dcc:data
'
]
&&
condition
[
'
dcc:data
'
][
'
dcc:quantity
'
])
{
let
quantities
=
this
.
_getQuantities
(
condition
);
const
table
=
document
.
createElement
(
'
table
'
);
const
table
=
document
.
createElement
(
'
table
'
);
table
.
style
.
width
=
'
100%
'
;
table
.
style
.
width
=
'
100%
'
;
table
.
style
.
borderCollapse
=
'
collapse
'
;
table
.
style
.
borderCollapse
=
'
collapse
'
;
// Header row
// Header row for the table
const
headerRow
=
document
.
createElement
(
'
tr
'
);
const
headerRow
=
document
.
createElement
(
'
tr
'
);
[
'
Quantity
'
,
'
Value
'
,
'
Description
'
].
forEach
(
text
=>
{
[
'
Quantity
'
,
'
Value
'
,
'
Description
'
,
'
Additional Info
'
].
forEach
(
text
=>
{
const
th
=
document
.
createElement
(
'
th
'
);
const
th
=
document
.
createElement
(
'
th
'
);
th
.
textContent
=
text
;
th
.
textContent
=
text
;
th
.
style
.
border
=
'
1px solid #ccc
'
;
th
.
style
.
border
=
'
1px solid #ccc
'
;
...
@@ -64,39 +67,50 @@ export class InfluenceConditionsRenderer {
...
@@ -64,39 +67,50 @@ export class InfluenceConditionsRenderer {
headerRow
.
appendChild
(
th
);
headerRow
.
appendChild
(
th
);
});
});
table
.
appendChild
(
headerRow
);
table
.
appendChild
(
headerRow
);
// Data rows for each quantity
this
.
_getQuantities
(
condition
).
forEach
(
q
=>
{
// Render each quantity as a row
quantities
.
forEach
(
q
=>
{
const
row
=
document
.
createElement
(
'
tr
'
);
const
row
=
document
.
createElement
(
'
tr
'
);
// Quantity name cell
// Column 1: Quantity name
const
nameCell
=
document
.
createElement
(
'
td
'
);
const
nameCell
=
document
.
createElement
(
'
td
'
);
nameCell
.
style
.
border
=
'
1px solid #ccc
'
;
nameCell
.
style
.
border
=
'
1px solid #ccc
'
;
nameCell
.
style
.
padding
=
'
4px
'
;
nameCell
.
style
.
padding
=
'
4px
'
;
nameCell
.
textContent
=
this
.
_getText
(
q
[
'
dcc:name
'
]);
nameCell
.
textContent
=
this
.
_getText
(
q
[
'
dcc:name
'
]);
row
.
appendChild
(
nameCell
);
row
.
appendChild
(
nameCell
);
// Value cell with merged unit and uncertainty, plus tooltip for additional info
// Column 2: Value (with unit, uncertainty, merged) – rendered with HTML markup
const
valueCell
=
document
.
createElement
(
'
td
'
);
const
valueCell
=
document
.
createElement
(
'
td
'
);
valueCell
.
style
.
border
=
'
1px solid #ccc
'
;
valueCell
.
style
.
border
=
'
1px solid #ccc
'
;
valueCell
.
style
.
padding
=
'
4px
'
;
valueCell
.
style
.
padding
=
'
4px
'
;
const
formattedValue
=
this
.
_formatQuantity
(
q
);
const
formattedValue
=
this
.
_formatQuantity
(
q
,
false
);
valueCell
.
innerHTML
=
formattedValue
;
valueCell
.
innerHTML
=
formattedValue
;
// If
there is
additional (non-standard) data
, add
a tooltip
// If additional (non-standard) data
exists, attach
a tooltip
const
additional
=
this
.
_getAdditionalData
(
q
);
const
additional
=
this
.
_getAdditionalData
(
q
);
if
(
Object
.
keys
(
additional
).
length
>
0
)
{
if
(
Object
.
keys
(
additional
).
length
>
0
)
{
const
infoSpan
=
document
.
createElement
(
'
span
'
);
const
infoSpan
=
document
.
createElement
(
'
span
'
);
infoSpan
.
textContent
=
'
ⓘ
'
;
infoSpan
.
textContent
=
'
ⓘ
'
;
infoSpan
.
style
.
cursor
=
'
pointer
'
;
infoSpan
.
style
.
cursor
=
'
pointer
'
;
infoSpan
.
style
.
color
=
'
#888
'
;
infoSpan
.
style
.
color
=
'
#888
'
;
// Use the title attribute for a basic tooltip (or later replace with a dynamic tree)
infoSpan
.
title
=
JSON
.
stringify
(
additional
,
null
,
2
);
infoSpan
.
title
=
JSON
.
stringify
(
additional
,
null
,
2
);
valueCell
.
appendChild
(
infoSpan
);
valueCell
.
appendChild
(
infoSpan
);
}
}
row
.
appendChild
(
valueCell
);
row
.
appendChild
(
valueCell
);
// Description cell
// Column 3: Description for the quantity
const
descCell
=
document
.
createElement
(
'
td
'
);
const
descCell
=
document
.
createElement
(
'
td
'
);
descCell
.
style
.
border
=
'
1px solid #ccc
'
;
descCell
.
style
.
border
=
'
1px solid #ccc
'
;
descCell
.
style
.
padding
=
'
4px
'
;
descCell
.
style
.
padding
=
'
4px
'
;
descCell
.
textContent
=
this
.
_getText
(
q
[
'
dcc:description
'
]);
descCell
.
textContent
=
this
.
_getText
(
q
[
'
dcc:description
'
]);
row
.
appendChild
(
descCell
);
row
.
appendChild
(
descCell
);
// Column 4: Additional info (if any)
const
additionalCell
=
document
.
createElement
(
'
td
'
);
additionalCell
.
style
.
border
=
'
1px solid #ccc
'
;
additionalCell
.
style
.
padding
=
'
4px
'
;
additionalCell
.
textContent
=
Object
.
keys
(
additional
).
length
>
0
?
JSON
.
stringify
(
additional
)
:
''
;
row
.
appendChild
(
additionalCell
);
table
.
appendChild
(
row
);
table
.
appendChild
(
row
);
});
});
contentDiv
.
appendChild
(
table
);
contentDiv
.
appendChild
(
table
);
...
@@ -129,13 +143,14 @@ export class InfluenceConditionsRenderer {
...
@@ -129,13 +143,14 @@ export class InfluenceConditionsRenderer {
return
quantities
;
return
quantities
;
}
}
// Helper: format a quantity’s value (supporting si:hybrid, si:realListXMLList, si:real, and dcc:noQuantity)
// Helper: format a quantity's value.
_formatQuantity
(
quantity
)
{
// If plain is true, render unit as plain text; otherwise use HTML from DSIUnit.
_formatQuantity
(
quantity
,
plain
=
false
)
{
// Handle noQuantity (categorical data)
// Handle noQuantity (categorical data)
if
(
quantity
[
'
dcc:noQuantity
'
])
{
if
(
quantity
[
'
dcc:noQuantity
'
])
{
return
this
.
_getText
(
quantity
[
'
dcc:noQuantity
'
]);
return
this
.
_getText
(
quantity
[
'
dcc:noQuantity
'
]);
}
}
// Handle si:hybrid
: if there are two si:real elements, render first normally and second in light gray
.
// Handle si:hybrid
block: map over si:real elements
.
if
(
quantity
[
'
si:hybrid
'
])
{
if
(
quantity
[
'
si:hybrid
'
])
{
const
hybrid
=
quantity
[
'
si:hybrid
'
];
const
hybrid
=
quantity
[
'
si:hybrid
'
];
let
reals
=
hybrid
[
'
si:real
'
];
let
reals
=
hybrid
[
'
si:real
'
];
...
@@ -148,7 +163,7 @@ export class InfluenceConditionsRenderer {
...
@@ -148,7 +163,7 @@ export class InfluenceConditionsRenderer {
if
(
real
[
'
si:unit
'
])
{
if
(
real
[
'
si:unit
'
])
{
const
rawUnit
=
real
[
'
si:unit
'
].
trim
();
const
rawUnit
=
real
[
'
si:unit
'
].
trim
();
const
unitObj
=
new
DSIUnit
(
rawUnit
);
const
unitObj
=
new
DSIUnit
(
rawUnit
);
unit
=
unitObj
.
toHTML
({
oneLine
:
true
});
unit
=
plain
?
unitObj
.
toHTML
()
:
unitObj
.
toHTML
({
oneLine
:
true
});
}
}
let
uncertainty
=
''
;
let
uncertainty
=
''
;
if
(
real
[
'
si:measurementUncertaintyUnivariate
'
]
&&
if
(
real
[
'
si:measurementUncertaintyUnivariate
'
]
&&
...
@@ -161,11 +176,11 @@ export class InfluenceConditionsRenderer {
...
@@ -161,11 +176,11 @@ export class InfluenceConditionsRenderer {
:
`
${
value
}
${
unit
}
`
;
:
`
${
value
}
${
unit
}
`
;
if
(
index
>
0
)
{
if
(
index
>
0
)
{
// For subsequent representations, wrap in a light gray span.
// For subsequent representations, wrap in a light gray span.
result
=
`<span style="color:lightgray;">
${
result
}
</span>`
;
result
=
`<span style="color:lightgray;">
(
${
result
}
)
</span>`
;
}
}
return
result
;
return
result
;
});
});
return
formatted
.
join
(
'
/
'
);
return
formatted
.
join
(
'
'
);
}
}
// Handle si:realListXMLList
// Handle si:realListXMLList
if
(
quantity
[
'
si:realListXMLList
'
])
{
if
(
quantity
[
'
si:realListXMLList
'
])
{
...
@@ -175,13 +190,14 @@ export class InfluenceConditionsRenderer {
...
@@ -175,13 +190,14 @@ export class InfluenceConditionsRenderer {
if
(
rl
[
'
si:unitXMLList
'
])
{
if
(
rl
[
'
si:unitXMLList
'
])
{
const
rawUnit
=
rl
[
'
si:unitXMLList
'
].
trim
();
const
rawUnit
=
rl
[
'
si:unitXMLList
'
].
trim
();
const
unitObj
=
new
DSIUnit
(
rawUnit
);
const
unitObj
=
new
DSIUnit
(
rawUnit
);
unit
=
unitObj
.
toHTML
({
oneLine
:
true
});
unit
=
plain
?
unitObj
.
toHTML
()
:
unitObj
.
toHTML
({
oneLine
:
true
});
}
}
let
uncertainty
=
[];
let
uncertainty
=
[];
if
(
rl
[
'
si:measurementUncertaintyUnivariateXMLList
'
]
&&
if
(
rl
[
'
si:measurementUncertaintyUnivariateXMLList
'
]
&&
rl
[
'
si:measurementUncertaintyUnivariateXMLList
'
][
'
si:expandedMUXMLList
'
]
&&
rl
[
'
si:measurementUncertaintyUnivariateXMLList
'
][
'
si:expandedMUXMLList
'
]
&&
rl
[
'
si:measurementUncertaintyUnivariateXMLList
'
][
'
si:expandedMUXMLList
'
][
'
si:valueExpandedMUXMLList
'
])
{
rl
[
'
si:measurementUncertaintyUnivariateXMLList
'
][
'
si:expandedMUXMLList
'
][
'
si:valueExpandedMUXMLList
'
])
{
uncertainty
=
rl
[
'
si:measurementUncertaintyUnivariateXMLList
'
][
'
si:expandedMUXMLList
'
][
'
si:valueExpandedMUXMLList
'
].
trim
().
split
(
/
\s
+/
);
uncertainty
=
rl
[
'
si:measurementUncertaintyUnivariateXMLList
'
][
'
si:expandedMUXMLList
'
][
'
si:valueExpandedMUXMLList
'
]
.
trim
().
split
(
/
\s
+/
);
}
}
const
formatted
=
values
.
map
((
val
,
i
)
=>
{
const
formatted
=
values
.
map
((
val
,
i
)
=>
{
const
unc
=
(
uncertainty
[
i
]
!==
undefined
)
?
uncertainty
[
i
]
:
''
;
const
unc
=
(
uncertainty
[
i
]
!==
undefined
)
?
uncertainty
[
i
]
:
''
;
...
@@ -197,7 +213,7 @@ export class InfluenceConditionsRenderer {
...
@@ -197,7 +213,7 @@ export class InfluenceConditionsRenderer {
if
(
real
[
'
si:unit
'
])
{
if
(
real
[
'
si:unit
'
])
{
const
rawUnit
=
real
[
'
si:unit
'
].
trim
();
const
rawUnit
=
real
[
'
si:unit
'
].
trim
();
const
unitObj
=
new
DSIUnit
(
rawUnit
);
const
unitObj
=
new
DSIUnit
(
rawUnit
);
unit
=
unitObj
.
toHTML
({
oneLine
:
true
});
unit
=
plain
?
unitObj
.
toHTML
()
:
unitObj
.
toHTML
({
oneLine
:
true
});
}
}
let
uncertainty
=
''
;
let
uncertainty
=
''
;
if
(
real
[
'
si:measurementUncertaintyUnivariate
'
]
&&
if
(
real
[
'
si:measurementUncertaintyUnivariate
'
]
&&
...
@@ -210,7 +226,7 @@ export class InfluenceConditionsRenderer {
...
@@ -210,7 +226,7 @@ export class InfluenceConditionsRenderer {
return
''
;
return
''
;
}
}
// Helper: extract additional data (all keys except the common ones)
// Helper: extract additional data (all keys except the common ones)
for tooltip purposes
_getAdditionalData
(
quantity
)
{
_getAdditionalData
(
quantity
)
{
const
exclude
=
[
'
dcc:name
'
,
'
dcc:description
'
,
'
si:real
'
,
'
si:realListXMLList
'
,
'
dcc:noQuantity
'
];
const
exclude
=
[
'
dcc:name
'
,
'
dcc:description
'
,
'
si:real
'
,
'
si:realListXMLList
'
,
'
dcc:noQuantity
'
];
const
additional
=
{};
const
additional
=
{};
...
...
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