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

Function drawShape

src/components/shapes/draw.js:112–192  ·  view source on GitHub ↗
(shapeLayer)

Source from the content-addressed store, hash-verified

110 }
111
112 function drawShape(shapeLayer) {
113 var d = getPathString(gd, options);
114 var attrs = {
115 'data-index': index,
116 'fill-rule': options.fillrule,
117 d: d
118 };
119
120 var opacity = options.opacity;
121 var fillColor = options.fillcolor;
122 var lineColor = options.line.width ? options.line.color : 'rgba(0,0,0,0)';
123 var lineWidth = options.line.width;
124 var lineDash = options.line.dash;
125 if (!lineWidth && options.editable === true) {
126 // ensure invisible border to activate the shape
127 lineWidth = 5;
128 lineDash = 'solid';
129 }
130
131 var isOpen = d[d.length - 1] !== 'Z';
132
133 var isActiveShape = couldHaveActiveShape(gd) && options.editable && gd._fullLayout._activeShapeIndex === index;
134
135 if (isActiveShape) {
136 fillColor = isOpen ? 'rgba(0,0,0,0)' : gd._fullLayout.activeshape.fillcolor;
137
138 opacity = gd._fullLayout.activeshape.opacity;
139 }
140
141 var shapeGroup = shapeLayer.append('g').classed('shape-group', true).attr({ 'data-index': index });
142
143 var path = shapeGroup
144 .append('path')
145 .attr(attrs)
146 .style('opacity', opacity)
147 .call(Color.stroke, lineColor)
148 .call(Color.fill, fillColor)
149 .call(Drawing.dashLine, lineDash, lineWidth);
150
151 setClipPath(shapeGroup, gd, options);
152
153 // Draw or clear the label
154 drawLabel(gd, index, options, shapeGroup);
155
156 var editHelpers;
157 if (isActiveShape || gd._context.edits.shapePosition) editHelpers = arrayEditor(gd.layout, 'shapes', options);
158
159 if (isActiveShape) {
160 path.style({
161 cursor: 'move'
162 });
163
164 var dragOptions = {
165 element: path.node(),
166 plotinfo: plotinfo,
167 gd: gd,
168 editHelpers: editHelpers,
169 hasText: options.label.text || options.label.texttemplate,

Callers 1

drawOneFunction · 0.85

Calls 6

couldHaveActiveShapeFunction · 0.85
drawLabelFunction · 0.85
activateShapeFunction · 0.85
setClipPathFunction · 0.70
setupDragElementFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…