|
5 | 5 | import {comparer, reaction} from "mobx"
|
6 | 6 | import {addDisposer, Instance, types} from "mobx-state-tree"
|
7 | 7 | import { format } from "d3"
|
| 8 | +import { formatDate } from "../../../utilities/date-utils" |
| 9 | +import { IValueType } from "../../../models/data/attribute-types" |
| 10 | +import { IAttribute } from "../../../models/data/attribute" |
8 | 11 | import {IDataSet} from "../../../models/data/data-set"
|
9 | 12 | import {ISharedCaseMetadata} from "../../../models/shared/shared-case-metadata"
|
10 | 13 | import {ISharedDataSet} from "../../../models/shared/shared-data-set"
|
@@ -68,14 +71,39 @@ export const DataDisplayContentModel = TileContentModel
|
68 | 71 | return getTileContentInfo(self.type)?.getFormulaAdapters?.(self) ?? []
|
69 | 72 | },
|
70 | 73 | caseTipText(attributeIDs: string[], caseID: string, dataset?: IDataSet) {
|
| 74 | + |
| 75 | + const getValueToDisplay = (numValue: number | undefined, value: IValueType, attribute?: IAttribute) => { |
| 76 | + if (!attribute) return '' |
| 77 | + switch (attribute.type) { |
| 78 | + case 'numeric': { |
| 79 | + const numPrecision = attribute.numPrecision |
| 80 | + const showUnits = attribute.units && attribute.units !== "" |
| 81 | + const unitsString = showUnits ? ` ${attribute.units}` : "" |
| 82 | + if (numValue && isFinite(numValue) && numPrecision) { |
| 83 | + const formatStr = `.${attribute.numPrecision}~f` |
| 84 | + const formatter = format(formatStr) |
| 85 | + return `${formatter ? `${formatter(numValue)}` : `${numValue}`}${unitsString}` |
| 86 | + } |
| 87 | + return `${value}${unitsString}` |
| 88 | + } |
| 89 | + case 'date': { |
| 90 | + const datePrecision = attribute.datePrecision |
| 91 | + return value && datePrecision ? formatDate(String(value), datePrecision) : value |
| 92 | + } |
| 93 | + default: |
| 94 | + return value |
| 95 | + } |
| 96 | + } |
| 97 | + |
71 | 98 | const float = format('.3~f')
|
72 | 99 | const attrArray = (attributeIDs?.map(attrID => {
|
73 | 100 | const attribute = dataset?.attrFromID(attrID),
|
74 | 101 | name = attribute?.name,
|
75 | 102 | numValue = dataset?.getNumeric(caseID, attrID),
|
76 | 103 | value = numValue != null && isFinite(numValue) ? float(numValue)
|
77 |
| - : dataset?.getValue(caseID, attrID) |
78 |
| - return value ? `${name}: ${value}` : '' |
| 104 | + : dataset?.getValue(caseID, attrID), |
| 105 | + displayedValue = getValueToDisplay(numValue, value, attribute) |
| 106 | + return value ? `${name}: ${displayedValue}` : '' |
79 | 107 | }))
|
80 | 108 | // Caption attribute can also be one of the plotted attributes, so we remove dups and join into html string
|
81 | 109 | return Array.from(new Set(attrArray)).filter(anEntry => anEntry !== '').join('<br>')
|
|
0 commit comments