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

Function transformPositions

stackgl_modules/index.js:39023–39094  ·  view source on GitHub ↗
(positions, options, size)

Source from the content-addressed store, hash-verified

39021}
39022
39023function transformPositions(positions, options, size) {
39024 var align = options.textAlign || "start"
39025 var baseline = options.textBaseline || "alphabetic"
39026
39027 var lo = [1<<30, 1<<30]
39028 var hi = [0,0]
39029 var n = positions.length
39030 for(var i=0; i<n; ++i) {
39031 var p = positions[i]
39032 for(var j=0; j<2; ++j) {
39033 lo[j] = Math.min(lo[j], p[j])|0
39034 hi[j] = Math.max(hi[j], p[j])|0
39035 }
39036 }
39037
39038 var xShift = 0
39039 switch(align) {
39040 case "center":
39041 xShift = -0.5 * (lo[0] + hi[0])
39042 break
39043
39044 case "right":
39045 case "end":
39046 xShift = -hi[0]
39047 break
39048
39049 case "left":
39050 case "start":
39051 xShift = -lo[0]
39052 break
39053
39054 default:
39055 throw new Error("vectorize-text: Unrecognized textAlign: '" + align + "'")
39056 }
39057
39058 var yShift = 0
39059 switch(baseline) {
39060 case "hanging":
39061 case "top":
39062 yShift = -lo[1]
39063 break
39064
39065 case "middle":
39066 yShift = -0.5 * (lo[1] + hi[1])
39067 break
39068
39069 case "alphabetic":
39070 case "ideographic":
39071 yShift = -3 * size
39072 break
39073
39074 case "bottom":
39075 yShift = -hi[1]
39076 break
39077
39078 default:
39079 throw new Error("vectorize-text: Unrecoginized textBaseline: '" + baseline + "'")
39080 }

Callers 1

processPixelsImplFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…