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

Method boxClickHandler

js/src/Boxplot.ts:355–420  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

353 }
354
355 private boxClickHandler(args) {
356 const index = args.index;
357 const that = this;
358 const idx = this.model.get('selected') || [];
359 let selected: number[] = Array.from(idx);
360 // index of box i. Checking if it is already present in the list.
361 const elem_index = selected.indexOf(index);
362 // Replacement for "Accel" modifier.
363 const accelKey = d3GetEvent().ctrlKey || d3GetEvent().metaKey;
364 if (elem_index > -1 && accelKey) {
365 // if the index is already selected and if accel key is
366 // pressed, remove the element from the list
367 selected.splice(elem_index, 1);
368 } else {
369 if (d3GetEvent().shiftKey) {
370 //If shift is pressed and the element is already
371 //selected, do not do anything
372 if (elem_index > -1) {
373 return;
374 }
375 //Add elements before or after the index of the current
376 //box which has been clicked
377 const min_index = selected.length !== 0 ? d3.min(selected) : -1;
378 const max_index =
379 selected.length !== 0
380 ? d3.max(selected)
381 : that.model.mark_data.length;
382 if (index > max_index) {
383 _.range(max_index + 1, index + 1).forEach((i) => {
384 selected.push(i);
385 });
386 } else if (index < min_index) {
387 _.range(index, min_index).forEach((i) => {
388 selected.push(i);
389 });
390 }
391 } else if (accelKey) {
392 //If accel is pressed and the box is not already selected
393 //add the box to the list of selected boxes.
394 selected.push(index);
395 }
396 // updating the array containing the box indexes selected
397 // and updating the style
398 else {
399 //if accel is not pressed, then clear the selected ones
400 //and set the current element to the selected
401 selected = [];
402 selected.push(index);
403 }
404 }
405 this.model.set(
406 'selected',
407 selected.length === 0 ? null : new Uint32Array(selected),
408 { updated_view: this }
409 );
410 this.touch();
411 const e = d3GetEvent();
412 if (e.cancelBubble !== undefined) {

Callers

nothing calls this directly

Calls 2

d3GetEventFunction · 0.90
rangeMethod · 0.80

Tested by

no test coverage detected