Skip to content

Commit 88578e1

Browse files
committed
Work around Firefox dash render bug
Fixes #35
1 parent 7aa8da4 commit 88578e1

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/prefabs/Markers.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ShapeConfig } from 'konva/lib/Shape';
2+
import { EllipseConfig } from 'konva/lib/shapes/Ellipse';
23
import * as React from 'react';
34
import { Ellipse, Group, Image, Rect } from 'react-konva';
45
import { getDragOffset, registerDropHandler } from '../DropHandler';
@@ -105,6 +106,18 @@ const EllipseOutline: React.FC<OutlineProps> = ({
105106
showHighlight,
106107
strokeProps,
107108
}) => {
109+
// Making the object always slightly elliptical works around a bug on
110+
// Firefox where it draws a very thick arc instead of dashes.
111+
// https://github.com/konvajs/konva/issues/1864
112+
const firefoxHack = 1.0000001;
113+
114+
if (width === height) {
115+
width *= firefoxHack;
116+
}
117+
if (highlightWidth === highlightHeight) {
118+
highlightWidth *= firefoxHack;
119+
}
120+
108121
return (
109122
<>
110123
{showHighlight && (
@@ -161,19 +174,23 @@ const MarkerRenderer: React.FC<RendererProps<MarkerObject>> = ({ object }) => {
161174
const iconX = (object.width - iconWidth) / 2;
162175
const iconY = (object.height - iconHeight) / 2;
163176

177+
const strokeWidth = 1;
178+
164179
const dashSize = getDashSize(object);
165-
const strokeProps = {
180+
const strokeProps: Partial<EllipseConfig> = {
166181
stroke: object.color,
167-
strokeWidth: 1,
182+
strokeWidth,
168183
shadowColor: object.color,
169-
shadowBlur: 2,
184+
shadowBlur: 1,
170185
dash: [dashSize, dashSize],
171186
};
172187

173-
const highlightOffset = strokeProps.strokeWidth * 4;
188+
const highlightOffset = strokeWidth * 4;
174189
const highlightWidth = object.width + highlightOffset;
175190
const highlightHeight = object.height + highlightOffset;
176191

192+
console.log(strokeProps);
193+
177194
return (
178195
<ResizeableObjectContainer object={object} transformerProps={{ centeredScaling: true }}>
179196
{(groupProps) => (

0 commit comments

Comments
 (0)