MCPcopy Create free account
hub / github.com/bqplot/bqplot / set_tick_values

Method set_tick_values

js/src/Axis.ts:133–208  ·  view source on GitHub ↗
(animate?: boolean)

Source from the content-addressed store, hash-verified

131 }
132
133 set_tick_values(animate?: boolean) {
134 // Sets specific tick values from "tick_values" parameter
135
136 let useticks = [];
137 const tick_values = this.model.get('tick_values');
138 const num_ticks = this.model.get('num_ticks');
139
140 if (
141 tick_values !== undefined &&
142 tick_values !== null &&
143 tick_values.length > 0
144 ) {
145 this.axis.tickValues(this.get_ticks_from_array_or_length(tick_values));
146 } else if (num_ticks !== undefined && num_ticks !== null) {
147 this.axis.tickValues(this.get_ticks_from_array_or_length());
148 } else {
149 if (isDateScale(this.axis_scale)) {
150 // Reduce number of suggested ticks if figure width is below the
151 // threshold. Note: "undefined" will result in the D3 default
152 // setting
153 const numDateTicks =
154 this.width < DATESCALE_WIDTH_THRESHOLD ? 5 : undefined;
155 const scale = this.axis_scale.scale;
156 this.axis.tickValues(scale.ticks(numDateTicks));
157 } else if (isOrdinalScale(this.axis_scale)) {
158 this.axis.tickValues(this.axis_scale.scale.domain());
159 } else if (isLogScale(this.axis_scale)) {
160 let i, r;
161 const scale = this.axis_scale.scale;
162 const allticks = scale.ticks();
163 const oom = Math.abs(Math.log10(scale.domain()[1] / scale.domain()[0]));
164 if (oom < 2) {
165 this.axis.tickValues(allticks);
166 } else if (oom < 7) {
167 useticks = [];
168 for (i = 0; i < allticks.length; i++) {
169 r = Math.abs(Math.log10(allticks[i]) % 1);
170 if (
171 Math.abs(r) < 0.001 ||
172 Math.abs(r - 1) < 0.001 ||
173 Math.abs(r - 0.30103) < 0.001 ||
174 Math.abs(r - 0.69897) < 0.001
175 ) {
176 useticks.push(allticks[i]);
177 }
178 }
179 this.axis.tickValues(useticks);
180 } else {
181 useticks = [];
182 const s = Math.round(oom / 10);
183 for (i = 0; i < allticks.length; i++) {
184 r = Math.abs(Math.log10(allticks[i]) % s);
185 if (Math.abs(r) < 0.001 || Math.abs(r - s) < 0.001) {
186 useticks.push(allticks[i]);
187 }
188 }
189 this.axis.tickValues(useticks);
190 }

Callers 6

renderMethod · 0.95
update_displayMethod · 0.95
redraw_axislineMethod · 0.95
rescale_axisMethod · 0.95
renderMethod · 0.80
redraw_axislineMethod · 0.80

Calls 2

apply_tick_stylingMethod · 0.95

Tested by

no test coverage detected