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

Method expandScaleDomain

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

Source from the content-addressed store, hash-verified

91 }
92
93 private expandScaleDomain(
94 scale,
95 data: number[],
96 mode: AxisMode,
97 start: boolean
98 ) {
99 // This function expands the domain so that the heatmap has the
100 // minimum area needed to draw itself.
101 let currentPixels;
102 let minDiff;
103
104 if (mode === AxisMode.ExpandOne) {
105 currentPixels = data.map((el) => scale.scale(el));
106 const diffs = currentPixels
107 .slice(1)
108 .map((el: number, index: number) => el - currentPixels[index]);
109
110 //TODO: Explain what is going on here.
111 minDiff = 0;
112 if (diffs[0] < 0) {
113 start = !start;
114 // diffs are negative. So max instead of min
115 minDiff = d3.max(diffs);
116 } else {
117 minDiff = d3.min(diffs);
118 }
119 if (start) {
120 const newPixel = currentPixels[currentPixels.length - 1] + minDiff;
121 return [data[0], scale.invert(newPixel)];
122 } else {
123 const newPixel = currentPixels[0] - minDiff;
124 return [scale.invert(newPixel), data[currentPixels.length - 1]];
125 }
126 } else if (mode === AxisMode.ExpandTwo) {
127 currentPixels = data.map((el) => scale.scale(el));
128 minDiff = d3.min(
129 currentPixels
130 .slice(1)
131 .map((el: number, index: number) => el - currentPixels[index])
132 );
133 const newEnd = currentPixels[currentPixels.length - 1] + minDiff;
134 const newStart = currentPixels[0] - minDiff;
135 return [scale.invert(newStart), scale.invert(newEnd)];
136 }
137 }
138
139 get numRows(): number {
140 return this.model.colors.length;

Callers 1

drawMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected