MCPcopy Index your code
hub / github.com/bqplot/bqplot / draw

Method draw

js/src/Bars.ts:275–356  ·  view source on GitHub ↗
(animate?: boolean)

Source from the content-addressed store, hash-verified

273 }
274
275 draw(animate?: boolean) {
276 this.set_ranges();
277 let barGroups: d3.Selection<any, any, any, any> = this.d3el
278 .selectAll('.bargroup')
279 .data(this.model.mark_data, (d: any) => d.key);
280
281 // this.stackedScale is the ordinal scale used to draw the bars. If a linear
282 // scale is given, then the ordinal scale is created from the
283 // linear scale.
284 if (!isOrdinalScale(this.domScale)) {
285 const modelDomain = this.model.mark_data.map((elem) => elem.key);
286 this.stackedScale.domain(modelDomain);
287 } else {
288 this.stackedScale.domain(this.domScale.scale.domain());
289 }
290
291 this.updateInternalScales();
292
293 if (this.model.mark_data.length > 0) {
294 this.groupedScale
295 .domain(_.range(this.model.mark_data[0].values.length))
296 .rangeRound([0, Math.round(this.stackedScale.bandwidth() * 100) / 100]);
297 }
298
299 // Since we will assign the enter and update selection of barGroups to
300 // itself, we may remove exit selection first.
301 barGroups.exit().remove();
302
303 barGroups = barGroups
304 .enter()
305 .append('g')
306 .attr('class', 'bargroup')
307 .merge(barGroups);
308 // The below function sorts the DOM elements so that the order of
309 // the DOM elements matches the order of the data they are bound
310 // to. This is required to maintain integrity with selection.
311 barGroups.order();
312
313 barGroups.on('click', (d, i) => {
314 return this.event_dispatcher('element_clicked', { data: d, index: i });
315 });
316
317 const barsSel = barGroups.selectAll('.bar').data((d) => d.values);
318
319 // default values for width and height are to ensure smooth
320 // transitions
321 barsSel
322 .enter()
323 .append('rect')
324 .attr('class', 'bar')
325 .attr('width', 0)
326 .attr('height', 0);
327
328 barsSel.exit().remove();
329
330 if (!this.model.get('label_display')) {
331 barGroups.selectAll('text').remove();
332 }

Callers 4

renderMethod · 0.95
set_positional_scalesMethod · 0.95
create_listenersMethod · 0.95
updateTypeMethod · 0.95

Calls 7

set_rangesMethod · 0.95
updateInternalScalesMethod · 0.95
drawBarsMethod · 0.95
drawZeroLineMethod · 0.95
rangeMethod · 0.80
removeMethod · 0.45
apply_stylesMethod · 0.45

Tested by

no test coverage detected