@@ -244,21 +244,19 @@ function makeCollageFromData(palettes, order, marks, row, color = undefined, siz
244244
245245 let offX = base [ 0 ]
246246 let offY = base [ 0 ]
247+ console . log ( ref . apply ) ;
247248
248-
249+ let toOffX = 0
250+ let toOffY = 0
249251 if ( ref . apply ) {
250252 let anchorId = ref . linkTo
251253
252254 let to = megaPalettes [ ref . apply ]
253255
254256 //WHERE PREVIOUS WAS DRAWN
255- offX = drawnMarks [ ref . apply ] . x
256- offY = drawnMarks [ ref . apply ] . y
257-
258- let selfAnchor = mark . proto . anchors [ anchorId ]
259-
260- offX += selfAnchor . rx * sourceW
261- offY += selfAnchor . ry * sourceH
257+ offX = drawnMarks [ ref . apply ] . x - ( drawnMarks [ ref . apply ] . w / 2 )
258+ offY = drawnMarks [ ref . apply ] . y - ( drawnMarks [ ref . apply ] . h / 2 )
259+ // tcon.fillRect(offX, offY, 5, 5)
262260
263261 if ( to . displayType === "range" ) {
264262 let instancedMark = marks [ ref . apply ] [ row [ dataBinding [ ref . apply ] ] ]
@@ -267,21 +265,45 @@ function makeCollageFromData(palettes, order, marks, row, color = undefined, siz
267265 if ( instancedMark . scale ) {
268266 tsc = instancedMark . scale
269267 }
270- offX -= ToAnchor . rx * ( instancedMark . source . width * tsc )
271- offY -= ToAnchor . ry * ( instancedMark . source . height * tsc )
268+
269+
270+ offX += ToAnchor . rx * ( instancedMark . source . width * tsc )
271+ offY += ToAnchor . ry * ( instancedMark . source . height * tsc )
272272
273273 }
274+ // tcon.fillStyle = "red"
275+ // tcon.fillRect(offX, offY, 5, 5)
276+
277+ let selfAnchor = mark . proto . anchors [ anchorId ]
278+
279+ // offX += selfAnchor.rx * sourceW
280+ // offY += selfAnchor.ry * sourceH
281+
282+ toOffX = selfAnchor . rx * sourceW
283+ toOffY = selfAnchor . ry * sourceH
284+
285+ console . log ( toOffX * sourceW , toOffY )
286+
287+ tcon . drawImage ( can ,
288+ offX - toOffX ,
289+ offY - toOffY ,
290+ sourceW ,
291+ sourceH )
292+
293+ } else {
294+ tcon . drawImage ( can ,
295+ offX - ( sourceW / 2 + toOffX ) ,
296+ offY - ( sourceH / 2 + toOffY ) ,
297+ sourceW ,
298+ sourceH )
274299 }
275300
301+ //TODO: bug inducing with chained anchors
276302 drawnMarks [ order [ j ] ] = { x : offX , y : offY , w : sourceW , h : sourceH }
277303
278304
279- // tcon.drawImage(mark.source, offX - sourceW / 2, offY - sourceH / 2, sourceW, sourceH)
280- tcon . drawImage ( can , offX - sourceW / 2 , offY - sourceH / 2 , sourceW , sourceH )
281305
282306 }
283- // console.log(drawnMarks);
284-
285307
286308 }
287309
0 commit comments