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

Function drawColorBar

src/components/colorbar/draw.js:170–855  ·  view source on GitHub ↗
(g, opts, gd)

Source from the content-addressed store, hash-verified

168}
169
170function drawColorBar(g, opts, gd) {
171 var isVertical = opts.orientation === 'v';
172 var len = opts.len;
173 var lenmode = opts.lenmode;
174 var thickness = opts.thickness;
175 var thicknessmode = opts.thicknessmode;
176 var outlinewidth = opts.outlinewidth;
177 var borderwidth = opts.borderwidth;
178 var bgcolor = opts.bgcolor;
179 var xanchor = opts.xanchor;
180 var yanchor = opts.yanchor;
181 var xpad = opts.xpad;
182 var ypad = opts.ypad;
183 var optsX = opts.x;
184 var optsY = isVertical ? opts.y : 1 - opts.y;
185
186 var isPaperY = opts.yref === 'paper';
187 var isPaperX = opts.xref === 'paper';
188
189 var fullLayout = gd._fullLayout;
190 var gs = fullLayout._size;
191
192 var fillColor = opts._fillcolor;
193 var line = opts._line;
194 var title = opts.title;
195 var titleSide = title.side;
196
197 var zrange = opts._zrange ||
198 d3.extent((typeof fillColor === 'function' ? fillColor : line.color).domain());
199
200 var lineColormap = typeof line.color === 'function' ?
201 line.color :
202 function() { return line.color; };
203 var fillColormap = typeof fillColor === 'function' ?
204 fillColor :
205 function() { return fillColor; };
206
207 var levelsIn = opts._levels;
208 var levelsOut = calcLevels(gd, opts, zrange);
209 var fillLevels = levelsOut.fill;
210 var lineLevels = levelsOut.line;
211
212 // we calculate pixel sizes based on the specified graph size,
213 // not the actual (in case something pushed the margins around)
214 // which is a little odd but avoids an odd iterative effect
215 // when the colorbar itself is pushing the margins.
216 // but then the fractional size is calculated based on the
217 // actual graph size, so that the axes will size correctly.
218 var thickPx = Math.round(thickness * (thicknessmode === 'fraction' ? (isVertical ? gs.w : gs.h) : 1));
219 var thickFrac = thickPx / (isVertical ? gs.w : gs.h);
220 var lenPx = Math.round(len * (lenmode === 'fraction' ? (isVertical ? gs.h : gs.w) : 1));
221 var lenFrac = lenPx / (isVertical ? gs.h : gs.w);
222
223 var posW = isPaperX ? gs.w : gd._fullLayout.width;
224 var posH = isPaperY ? gs.h : gd._fullLayout.height;
225
226 // x positioning: do it initially just for left anchor,
227 // then fix at the end (since we don't know the width yet)

Callers 1

drawFunction · 0.85

Calls 2

calcLevelsFunction · 0.85
mockColorBarAxisFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…