Browse Source

custom label for distance/angle/dihedral

David Sehnal 5 years ago
parent
commit
f0d7a4ed2a

+ 4 - 4
src/mol-repr/shape/loci/angle.ts

@@ -24,6 +24,7 @@ import { transformPrimitive } from '../../../mol-geo/primitive/primitive';
 import { MarkerActions, MarkerAction } from '../../../mol-util/marker-action';
 import { angleLabel } from '../../../mol-theme/label';
 import { Sphere3D } from '../../../mol-math/geometry';
+import { MeasurementRepresentationCommonTextParams } from './common';
 
 export interface AngleData {
     triples: Loci.Bundle<3>[]
@@ -62,9 +63,8 @@ type SectorParams = typeof SectorParams
 
 const TextParams = {
     ...Text.Params,
-    borderWidth: PD.Numeric(0.2, { min: 0, max: 0.5, step: 0.01 }),
-    textColor: PD.Color(ColorNames.black),
-    textSize: PD.Numeric(0.4, { min: 0.1, max: 5, step: 0.1 }),
+    ...MeasurementRepresentationCommonTextParams,
+    borderWidth: PD.Numeric(0.2, { min: 0, max: 0.5, step: 0.01 })
 };
 type TextParams = typeof TextParams
 
@@ -227,7 +227,7 @@ function buildText(data: AngleData, props: AngleProps, text?: Text): Text {
         Vec3.add(tmpVec, tmpState.sphereB.center, tmpVec);
 
         const angle = radToDeg(tmpState.angle).toFixed(2);
-        const label = `${angle}\u00B0`;
+        const label = props.customText || `${angle}\u00B0`;
         const radius = Math.max(2, tmpState.sphereA.radius, tmpState.sphereB.radius, tmpState.sphereC.radius);
         const scale = radius / 2;
         builder.add(label, tmpVec[0], tmpVec[1], tmpVec[2], 0.1, scale, i);

+ 1 - 0
src/mol-repr/shape/loci/common.ts

@@ -9,6 +9,7 @@ import { ParamDefinition as PD } from '../../../mol-util/param-definition';
 import { ColorNames } from '../../../mol-util/color/names';
 
 export const MeasurementRepresentationCommonTextParams = {
+    customText: PD.Text('', { label: 'Text', description: 'Override the label with custom value.' }),
     textColor: PD.Color(ColorNames.black, { isEssential: true }),
     textSize: PD.Numeric(0.5, { min: 0.1, max: 5, step: 0.1 }, { isEssential: true }),
 };

+ 1 - 1
src/mol-repr/shape/loci/dihedral.ts

@@ -307,7 +307,7 @@ function buildText(data: DihedralData, props: DihedralProps, text?: Text): Text
         Vec3.add(tmpVec, tmpState.arcCenter, tmpVec);
 
         const angle = Math.abs(radToDeg(tmpState.angle)).toFixed(2);
-        const label = `${angle}\u00B0`;
+        const label =  props.customText || `${angle}\u00B0`;
         const radius = Math.max(2, tmpState.sphereA.radius, tmpState.sphereB.radius, tmpState.sphereC.radius, tmpState.sphereD.radius);
         const scale = radius / 2;
         builder.add(label, tmpVec[0], tmpVec[1], tmpVec[2], 0.1, scale, i);

+ 1 - 1
src/mol-repr/shape/loci/distance.ts

@@ -118,7 +118,7 @@ function buildText(data: DistanceData, props: DistanceProps, text?: Text): Text
     for (let i = 0, il = data.pairs.length; i < il; ++i) {
         setDistanceState(data.pairs[i], tmpState);
         const { center, distance, sphereA, sphereB } = tmpState;
-        const label = `${distance.toFixed(2)} ${props.unitLabel}`;
+        const label = props.customText || `${distance.toFixed(2)} ${props.unitLabel}`;
         const radius = Math.max(2, sphereA.radius, sphereB.radius);
         const scale = radius / 2;
         builder.add(label, center[0], center[1], center[2], 1, scale, i);