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

Method getTilePlottingData

js/src/GridHeatMap.ts:615–720  ·  view source on GitHub ↗
(
    scale,
    data: number[],
    mode: AxisMode,
    start: boolean
  )

Source from the content-addressed store, hash-verified

613 }
614
615 private getTilePlottingData(
616 scale,
617 data: number[],
618 mode: AxisMode,
619 start: boolean
620 ): { start: number[]; widths: number[] } {
621 // This function returns the starting points and widths of the
622 // cells based on the parameters passed.
623 //
624 // scale is the scale and data is the data for which the plot data
625 // is to be generated. mode refers to the expansion of the data to
626 // generate the plotting data and start is a boolean indicating the
627 // alignment of the data w.r.t the cells.
628 let startPoints = data.map((d) => scale.scale(d));
629 let widths = [];
630 data = Array.from(data); // copy to Array
631
632 if (mode === AxisMode.Middle) {
633 widths = data.map((d) => scale.scale.bandwidth());
634 }
635
636 if (mode === AxisMode.Boundaries) {
637 const pixelPoints = data.map((d) => scale.scale(d));
638
639 for (let i = 1; i < pixelPoints.length; ++i) {
640 widths[i - 1] = Math.abs(pixelPoints[i] - pixelPoints[i - 1]);
641 }
642
643 startPoints =
644 pixelPoints[1] > pixelPoints[0]
645 ? pixelPoints.slice(0, -1)
646 : pixelPoints.slice(1);
647 }
648
649 if (mode === AxisMode.ExpandOne) {
650 let bounds;
651
652 if (start) {
653 widths = startPoints.slice(1).map((d, ind) => {
654 // Absolute value is required as the order of the data
655 // can be increasing or decreasing in terms of pixels
656 return Math.abs(d - startPoints[ind]);
657 });
658
659 // Now we have n-1 widths. We have to add the last or the
660 // first width depending on scale is increasing or
661 // decreasing.
662 bounds = d3.max(scale.scale.range());
663 if (startPoints[0] < startPoints[1]) {
664 widths = Array.prototype.concat(widths, [
665 Math.abs(bounds - d3.max(startPoints)),
666 ]);
667 } else {
668 widths = Array.prototype.concat(
669 [Math.abs(bounds - d3.max(startPoints))],
670 widths
671 );
672 }

Callers 1

drawMethod · 0.95

Calls 1

rangeMethod · 0.80

Tested by

no test coverage detected