MCPcopy Index your code
hub / github.com/plotly/plotly.js / getPixels

Function getPixels

stackgl_modules/index.js:39096–39258  ·  view source on GitHub ↗
(canvas, context, rawString, fontSize, lineSpacing, styletags)

Source from the content-addressed store, hash-verified

39094}
39095
39096function getPixels(canvas, context, rawString, fontSize, lineSpacing, styletags) {
39097
39098 rawString = rawString.replace(/\n/g, '') // don't accept \n in the input
39099
39100 if(styletags.breaklines === true) {
39101 rawString = rawString.replace(/\<br\>/g, '\n') // replace <br> tags with \n in the string
39102 } else {
39103 rawString = rawString.replace(/\<br\>/g, ' ') // don't accept <br> tags in the input and replace with space in this case
39104 }
39105
39106 var activeStyle = ""
39107 var map = []
39108 for(j = 0; j < rawString.length; ++j) {
39109 map[j] = activeStyle
39110 }
39111
39112 if(styletags.bolds === true) map = parseTag(TAG_bold, CHR_bold, rawString, map)
39113 if(styletags.italics === true) map = parseTag(TAG_italic, CHR_italic, rawString, map)
39114 if(styletags.superscripts === true) map = parseTag(TAG_super, CHR_super, rawString, map)
39115 if(styletags.subscripts === true) map = parseTag(TAG_sub, CHR_sub, rawString, map)
39116
39117 var allStyles = []
39118 var plainText = ""
39119 for(j = 0; j < rawString.length; ++j) {
39120 if(map[j] !== null) {
39121 plainText += rawString[j]
39122 allStyles.push(map[j])
39123 }
39124 }
39125
39126 var allTexts = plainText.split('\n')
39127
39128 var numberOfLines = allTexts.length
39129 var lineHeight = Math.round(lineSpacing * fontSize)
39130 var offsetX = fontSize
39131 var offsetY = fontSize * 2
39132 var maxWidth = 0
39133 var minHeight = numberOfLines * lineHeight + offsetY
39134
39135 if(canvas.height < minHeight) {
39136 canvas.height = minHeight
39137 }
39138
39139 context.fillStyle = "#000"
39140 context.fillRect(0, 0, canvas.width, canvas.height)
39141
39142 context.fillStyle = "#fff"
39143 var i, j, xPos, yPos, zPos
39144 var nDone = 0
39145
39146 var buffer = ""
39147 function writeBuffer() {
39148 if(buffer !== "") {
39149 var delta = context.measureText(buffer).width
39150
39151 context.fillText(buffer, offsetX + xPos, offsetY + yPos)
39152 xPos += delta
39153 }

Callers 1

vectorizeTextFunction · 0.85

Calls 3

parseTagFunction · 0.85
writeBufferFunction · 0.85
changeStyleFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…