Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled scalefactor and improved text readout for Identifier tool #567

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/pages/Tools/Identifier/Identifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The following is an example of the Sites Tool's Tool Tab configuration:
"url": "(str) path_to_data/data.tif",
"bands": "(int) how many bands to query from",
"sigfigs": "(int) how many digits after the decimal",
"scalefactor": "(float) number to multiply value",
"unit": "(str) whatever string unit",
"timeFormat": "(str) for formatting injected '{starttime}' and '{endtime}' in url."
},
Expand All @@ -30,5 +31,6 @@ The following is an example of the Sites Tool's Tool Tab configuration:
- `url`: This can be a relative path to a file under the Mission name or a full url path. The former is preferred is the file is large. Can use '{starttime}' and '{endtime}' if the layer is time enabled.
- `bands`: Allows you to specify how many bands to return data from. Default is 1.
- `sigfigs`: Sets the decimal precision.
- `scalefactor`: A float number that will multiply the value to scale.
- `unit`: A string that is appended to your returned value. e.g. " m" would be appended on a raw value ("41") and show "41 m". If it was "m", it would return "41m", without a space.
- `timeFormat`: A string for formatting the injected '{starttime}' and '{endtime}' in the url. See syntax in https://d3js.org/d3-time-format#locale_format
27 changes: 19 additions & 8 deletions src/essence/Tools/Identifier/IdentifierTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var IdentifierTool = {
//Get tool variables and UI adjustments
this.justification = L_.getToolVars('identifier')['justification']
var toolContent = d3.select('#toolSeparated_Identifier')
toolContent.style('bottom', '2px')

if (this.justification == 'right') {
var toolController = d3.select('#toolcontroller_sepdiv')
Expand Down Expand Up @@ -351,17 +352,25 @@ var IdentifierTool = {
var valueParsed =
parseValue(
value[v][1],
d2.sigfigs
d2.sigfigs,
d2.scalefactor
) +
'' +
unit

htmlValues +=
'<div style="display: flex; justify-content: space-between;"><div style="margin-right: 15px; color: var(--color-a5); font-size: 12px;">' +
value[v][0] +
'</div><div style="color: var(--color-a6); font-size: 14px;">' +
valueParsed +
'</div></div>'
if (value.length > 1) {
htmlValues +=
'<div style="display: flex; justify-content: space-between;"><div style="margin-right: 15px; color: var(--color-a5); font-size: 12px;">' +
value[v][0] +
'</div><div style="color: var(--color-a6); font-size: 14px;">' +
valueParsed +
'</div></div>'
} else {
htmlValues +=
'<div style="display: flex; justify-content: space-between;"><div style="color: var(--color-a6); font-size: 16px;">' +
valueParsed +
'</div></div>'
}
cnt++
}
$(
Expand Down Expand Up @@ -441,7 +450,7 @@ var IdentifierTool = {
}, 150)
}

function parseValue(v, sigfigs) {
function parseValue(v, sigfigs, scalefactor) {
var ed = 10
if (typeof v === 'string') {
return v
Expand All @@ -450,13 +459,15 @@ var IdentifierTool = {
return v
} else if (v.toString().indexOf('e') != -1) {
if (sigfigs != undefined) ed = sigfigs
if (scalefactor != undefined) v = v * parseFloat(scalefactor)
v = parseFloat(v)
return v.toExponential(ed)
} else {
var decSplit = v.toString().split('.')
var decPlacesBefore = decSplit[0] ? decSplit[0].length : 0
var decPlacesAfter = decSplit[1] ? decSplit[1].length : 0
if (decPlacesBefore <= 5) {
if (scalefactor != undefined) v = v * parseFloat(scalefactor)
if (sigfigs != undefined) v = v.toFixed(sigfigs)
}
v = parseFloat(v)
Expand Down
Loading