svg_words = {
const svg = d3.create('svg').attr("width", svg_w).attr("height", svg_h).attr('viewBox',`0 0 ${svg_w} ${svg_h}`)
let space = rowSize
svg.append('rect')
.attr('id','wordRect')
.attr('x',space/2)
.attr('y',row[1])
.attr('width',wordSize[word.word]+space)
.attr('height',space-(space/8))
.attr('rx',15)
.attr('fill','#85CB33')
.attr('stroke-width',1)
.attr('stroke','#041B15')
.attr('cursor','pointer')
.on("click", () => {
let r = teRegions[word.word]
console.log(r)
teReo.start('0.001',r.start, r.length)
return Tone.context.resume()
})
svg.append('text')
.attr('pointer-events','none')
.style('font-family','sans-serif')
.style('font-size', '42px')
.style('alignment-baseline','hanging')
.attr('x',space)
.attr('y',row[1])
.attr('id', `word`)
.text(reo[word.word].Māori+' 🔊');
//-----------------------------------------------------------------------
// guesses
svg.append('rect')
.attr('id','choice0')
.attr('x',space/2) // .attr('y',space-(space*0.1)) // y position is off in firefox
.attr('y',row[2]) // y position is off in firefox
.attr('width',space)
.attr('height',rowSize)
.attr('rx',15)
.attr('fill','#92AD94')
.attr('stroke-width',3)
.attr('stroke','#061A40')
.attr('cursor','pointer')
.on("click", () => {
if (word.word === word.otherWords[0]) {
d3.select('#choice0').attr('fill','red')
} else {
d3.select('#choice0').attr('fill','blue')
}
})
svg.append('text')
.attr('pointer-events','none')
.style('font-family','sans-serif')
.style('font-size', '42px')
.style('alignment-baseline','hanging')
.attr('x',space*2)
.attr('y',row[2])
.attr('id', `word`)
.text(reo[word.otherWords[0]].meaning);
// -----------
svg.append('rect')
.attr('id','choice1')
.attr('x',space/2) // .attr('y',space-(space*0.1)) // y position is off in firefox
.attr('y',row[3]) // y position is off in firefox
.attr('width',space)
.attr('height',rowSize )
.attr('rx',15)
.attr('fill','#92AD94')
.attr('stroke-width',3)
.attr('stroke','#061A40')
.attr('cursor','pointer')
.on("click", () => {
if (word.word === word.otherWords[1]) {
d3.select('#choice1').attr('fill','red')
} else {
d3.select('#choice1').attr('fill','blue')
}
})
svg.append('text')
.attr('pointer-events','none')
.style('font-family','sans-serif')
.style('font-size', '42px')
.style('alignment-baseline','hanging')
.attr('x',space*2)
.attr('y',row[3])
.attr('id', `word`)
.text(reo[word.otherWords[1]].meaning);
// -----------
svg.append('rect')
.attr('id','choice2')
.attr('x',space/2) // .attr('y',space-(space*0.1)) // y position is off in firefox
.attr('y',row[4]) // y position is off in firefox
.attr('width',space)
.attr('height',rowSize )
.attr('rx',15)
.attr('fill','#92AD94')
.attr('stroke-width',3)
.attr('stroke','#061A40')
.attr('cursor','pointer')
.on("click", () => {
if (word.word === word.otherWords[2]) {
d3.select('#choice2').attr('fill','red')
} else {
d3.select('#choice2').attr('fill','blue')
}
})
svg.append('text')
.attr('pointer-events','none')
.style('font-family','sans-serif')
.style('font-size', '42px')
.style('alignment-baseline','hanging')
.attr('x',space*2)
.attr('y',row[4])
.attr('id', `word`)
.text(reo[word.otherWords[2]].meaning);
// -----------
svg.append('rect')
.attr('id','choice3')
.attr('x',space/2) // .attr('y',space-(space*0.1)) // y position is off in firefox
.attr('y',row[5]) // y position is off in firefox
.attr('width',space)
.attr('height',rowSize )
.attr('rx',15)
.attr('fill','#92AD94')
.attr('stroke-width',3)
.attr('stroke','#061A40')
.attr('cursor','pointer')
.on("click", () => {
if (word.word === word.otherWords[3]) {
d3.select('#choice3').attr('fill','red')
} else {
d3.select('#choice3').attr('fill','blue')
}
})
svg.append('text')
.attr('pointer-events','none')
.style('font-family','sans-serif')
.style('font-size', '42px')
.style('alignment-baseline','hanging')
.attr('x',space*2)
.attr('y',row[5])
.attr('id', `word`)
.text(reo[word.otherWords[3]].meaning);
// -----------
svg.append('rect')
.attr('id','choice4')
.attr('x',space/2) // .attr('y',space-(space*0.1)) // y position is off in firefox
.attr('y',row[6]) // y position is off in firefox
.attr('width',space)
.attr('height',rowSize )
.attr('rx',15)
.attr('fill','#92AD94')
.attr('stroke-width',3)
.attr('stroke','#061A40')
.attr('cursor','pointer')
.on("click", () => {
if (word.word === word.otherWords[4]) {
d3.select('#choice4').attr('fill','red')
} else {
d3.select('#choice4').attr('fill','blue')
}
})
svg.append('text')
.attr('pointer-events','none')
.style('font-family','sans-serif')
.style('font-size', '42px')
.style('alignment-baseline','hanging')
.attr('x',space*2)
.attr('y',row[6])
.attr('id', `word`)
.text(reo[word.otherWords[4]].meaning);
// -------------------------------------------------
// next button
svg.append('rect')
.attr('id','nextRect')
.attr('x',space/2)
.attr('y',row[row.length-1])
.attr('width',nextWord.width+space)
.attr('height',space-(space/4))
.attr('rx',15)
.attr('fill','#EF946C')
.attr('cursor','pointer')
.attr('stroke-width',3)
.attr('stroke','#A01A40')
.on("click", () => {
mutable word = pickWords() // This causes this svg_words cell to redraw.
// d3.select('#wordRect')
// .attr('x',space/2)
// .attr('y',space-(space*0.1)) // y position is off in firefox
// .attr('width',wordSizes[word.word].width+space)
// .attr('height',space)
// d3.select('#word')
// .attr('x',svg_w*0.04)
// .attr('y',svg_h*0.1)
// .text(reo[word.word].Māori);
})
svg.append('text')
.attr('pointer-events','none')
.style('font-family','sans-serif')
.style('font-size', '42px')
.style('alignment-baseline','hanging')
.attr('x',svg_w*0.04)
.attr('y',row[row.length-1])
.attr('id', `next`)
.text('Next Word');
return svg.node()
}