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

Function stylePoints

src/components/legend/style.js:168–274  ·  view source on GitHub ↗
(d)

Source from the content-addressed store, hash-verified

166 }
167
168 function stylePoints(d) {
169 var styleGuide = getStyleGuide(d);
170 var anyFill = styleGuide.anyFill;
171 var anyLine = styleGuide.anyLine;
172 var showLine = styleGuide.showLine;
173 var showMarker = styleGuide.showMarker;
174
175 var d0 = d[0];
176 var trace = d0.trace;
177 var showText = !showMarker && !anyLine && !anyFill && subTypes.hasText(trace);
178 var dMod, tMod;
179
180 // 'scatter3d' don't use gd.calcdata,
181 // use d0.trace to infer arrayOk attributes
182
183 function boundVal(attrIn, arrayToValFn, bounds, cst) {
184 var valIn = Lib.nestedProperty(trace, attrIn).get();
185 var valToBound = Lib.isArrayOrTypedArray(valIn) && arrayToValFn ? arrayToValFn(valIn) : valIn;
186
187 if (constantItemSizing && valToBound && cst !== undefined) {
188 valToBound = cst;
189 }
190
191 if (bounds) {
192 if (valToBound < bounds[0]) return bounds[0];
193 else if (valToBound > bounds[1]) return bounds[1];
194 }
195 return valToBound;
196 }
197
198 function pickFirst(array) {
199 if (d0._distinct && d0.index && array[d0.index]) return array[d0.index];
200 return array[0];
201 }
202
203 // constrain text, markers, etc so they'll fit on the legend
204 if (showMarker || showText || showLine) {
205 var dEdit = {};
206 var tEdit = {};
207
208 if (showMarker) {
209 dEdit.mc = boundVal('marker.color', pickFirst);
210 dEdit.mx = boundVal('marker.symbol', pickFirst);
211 dEdit.mo = boundVal('marker.opacity', Lib.mean, [0.2, 1]);
212 dEdit.mlc = boundVal('marker.line.color', pickFirst);
213 dEdit.mlw = boundVal('marker.line.width', Lib.mean, [0, 5], CST_MARKER_LINE_WIDTH);
214 // TODO: Remove this check in next major version
215 // Use 'solid' for shapes to match existing behavior
216 dEdit.mld = trace._isShape ? 'solid' : boundVal('marker.line.dash', pickFirst);
217 tEdit.marker = {
218 sizeref: 1,
219 sizemin: 1,
220 sizemode: 'diameter'
221 };
222
223 var ms = boundVal('marker.size', Lib.mean, [2, 16], CST_MARKER_SIZE);
224 dEdit.ms = ms;
225 tEdit.marker.size = ms;

Callers

nothing calls this directly

Calls 2

getStyleGuideFunction · 0.85
boundValFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…