Просмотр исходного кода

fix floating point number precision

RoyLiu 4 лет назад
Родитель
Сommit
59f940f166
4 измененных файлов с 11 добавлено и 3 удалено
  1. 3 1
      components/Highlight/index.tsx
  2. 3 1
      components/Highlight/styled.ts
  3. 1 1
      helpers/annotation.ts
  4. 4 0
      helpers/utility.ts

+ 3 - 1
components/Highlight/index.tsx

@@ -3,6 +3,7 @@ import React from 'react';
 import AnnotationSelector from '../AnnotationSelector';
 import AnnotationSelector from '../AnnotationSelector';
 import Markup from '../Markup';
 import Markup from '../Markup';
 import { rectCalc } from '../../helpers/position';
 import { rectCalc } from '../../helpers/position';
+import { strip } from '../../helpers/utility';
 
 
 import { Popper } from './styled';
 import { Popper } from './styled';
 
 
@@ -35,6 +36,7 @@ const Highlight: React.SFC<AnnotationElementPropsType> = ({
             opacity={transparency || 0}
             opacity={transparency || 0}
             markupType={obj_type}
             markupType={obj_type}
             isCovered={isCovered}
             isCovered={isCovered}
+            scale={scale}
           />
           />
         );
         );
       })}
       })}
@@ -44,7 +46,7 @@ const Highlight: React.SFC<AnnotationElementPropsType> = ({
           onUpdate={onUpdate}
           onUpdate={onUpdate}
           onDelete={onDelete}
           onDelete={onDelete}
           colorProps={bdcolor}
           colorProps={bdcolor}
-          opacityProps={transparency ? transparency * 100 : 0}
+          opacityProps={transparency ? strip(transparency * 100) : 0}
         />
         />
       </Popper>
       </Popper>
     ) : (
     ) : (

+ 3 - 1
components/Highlight/styled.ts

@@ -1,9 +1,11 @@
 import styled from 'styled-components';
 import styled from 'styled-components';
 
 
-export const Popper = styled('div')<{position: Record<string, any>}>`
+export const Popper = styled('div')<{ position: Record<string, any> }>`
   position: absolute;
   position: absolute;
   top: ${props => props.position.y}px;
   top: ${props => props.position.y}px;
   left: ${props => props.position.x}px;
   left: ${props => props.position.x}px;
   transform: translate(-50%, -80px);
   transform: translate(-50%, -80px);
   z-index: 10;
   z-index: 10;
 `;
 `;
+
+export default Popper;

+ 1 - 1
helpers/annotation.ts

@@ -68,7 +68,7 @@ export const parseAnnotationFromXml = (xmlString: string): AnnotationType[] => {
             ? parseInt(cur.attributes.width.value, 10)
             ? parseInt(cur.attributes.width.value, 10)
             : 0,
             : 0,
           transparency: cur.attributes.opacity
           transparency: cur.attributes.opacity
-            ? parseFloat(cur.attributes.opacity.value).toFixed(2)
+            ? cur.attributes.opacity.value
             : 1,
             : 1,
           content: getContent(type, cur) || undefined,
           content: getContent(type, cur) || undefined,
           fcolor: cur.attributes['interior-color']
           fcolor: cur.attributes['interior-color']

+ 4 - 0
helpers/utility.ts

@@ -322,3 +322,7 @@ export const printPdf = async (url: string) => {
       }
       }
     });
     });
 };
 };
+
+export const strip = (number: number): number => {
+  return parseFloat(parseFloat(number.toString()).toPrecision(12));
+};