8
8
9
9
const sigpadMap = new Map ( ) ;
10
10
11
- function drawPoints ( ctx , points ) {
11
+ // finished param: only draw last point after points wont differ from exec to exec
12
+ function drawPoints ( ctx , points , finished ) {
12
13
// draw a point instead
13
14
if ( points . length == 1 ) {
14
15
var b = points [ 0 ] ;
@@ -17,7 +18,7 @@ function drawPoints(ctx, points) {
17
18
}
18
19
19
20
// draw line for just two points
20
- if ( points . length == 2 ) {
21
+ if ( points . length == 2 && finished ) {
21
22
ctx . beginPath ( ) , ctx . moveTo ( points [ 0 ] . x , points [ 0 ] . y ) ;
22
23
ctx . lineTo ( points [ 1 ] . x , points [ 1 ] . y ) ;
23
24
ctx . stroke ( ) ;
@@ -32,7 +33,7 @@ function drawPoints(ctx, points) {
32
33
d = ( points [ i ] . y + points [ i + 1 ] . y ) / 2 ;
33
34
ctx . quadraticCurveTo ( points [ i ] . x , points [ i ] . y , c , d ) ;
34
35
}
35
- if ( i < points . length - 1 )
36
+ if ( i < points . length - 1 && finished )
36
37
ctx . quadraticCurveTo ( points [ i ] . x , points [ i ] . y , points [ i + 1 ] . x , points [ i + 1 ] . y ) ;
37
38
//ctx.closePath();
38
39
ctx . stroke ( ) ;
@@ -98,6 +99,7 @@ export default class Sigpad {
98
99
ctx = this . _element . getContext ( "2d" ) ;
99
100
}
100
101
ctx . strokeStyle = this . _config . strokeStyle ;
102
+ ctx . fillStyle = this . _config . strokeStyle ;
101
103
ctx . lineWidth = this . _config . lineWidth ;
102
104
ctx . lineCap = this . _config . lineCap ;
103
105
ctx . lineJoin = this . _config . lineJoin ;
@@ -230,7 +232,7 @@ export default class Sigpad {
230
232
return ;
231
233
}
232
234
233
- data . render ( ) ;
235
+ data . render ( true ) ;
234
236
data . _drawing = false ;
235
237
236
238
const event = new CustomEvent ( 'sigpad.finish' , { detail : data . getImage ( ) } ) ;
@@ -265,14 +267,16 @@ export default class Sigpad {
265
267
}
266
268
}
267
269
268
- render ( ) {
270
+ //finished: signal to renderer that all individual mouse position arrays are complete
271
+ render ( finished ) {
269
272
if ( this . _element . width != this . _element . clientWidth ) {
270
273
this . _element . width = this . _element . clientWidth ;
271
274
}
275
+
272
276
if ( this . _drawing ) {
273
277
var ctx = this . _element . getContext ( "2d" ) ;
274
278
this . _applyOptions ( ctx ) ;
275
- this . _mousePosis . filter ( ( stroke ) => stroke . length > 0 ) . forEach ( ( stroke ) => drawPoints ( ctx , stroke ) ) ;
279
+ this . _mousePosis . filter ( ( stroke ) => stroke . length > 0 ) . forEach ( ( stroke ) => drawPoints ( ctx , stroke , finished ) ) ;
276
280
}
277
281
}
278
282
}
@@ -291,7 +295,7 @@ const requestAnimFrame = (function (callback) {
291
295
( function renderSignatures ( ) {
292
296
requestAnimFrame ( renderSignatures ) ;
293
297
Sigpad . getAllInstances ( ) . forEach ( ( sigpad , index ) => {
294
- sigpad . render ( ) ;
298
+ sigpad . render ( false ) ;
295
299
} ) ;
296
300
297
301
} ) ( ) ;
0 commit comments