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

Method get_ticks_from_array_or_length

js/src/Axis.ts:720–770  ·  view source on GitHub ↗
(data_array?: any[])

Source from the content-addressed store, hash-verified

718 }
719
720 get_ticks_from_array_or_length(data_array?: any[]) {
721 // This function is to be called when the ticks are passed explicitly
722 // or the number of ticks to be drawn.
723 // Have to do different things based on the type of the scale.
724 // If an array is passed, then just scale and return equally spaced
725 // points in the array. This is the way it is done for ordinal
726 // scales.
727 let step, max;
728 const num_ticks = this.model.get('num_ticks');
729
730 if (isOrdinalScale(this.axis_scale)) {
731 data_array = this.axis_scale.scale.domain();
732 }
733 if (num_ticks !== undefined && num_ticks !== null && num_ticks < 2) {
734 return [];
735 }
736 if (data_array) {
737 if (
738 num_ticks == undefined ||
739 num_ticks == null ||
740 data_array.length <= num_ticks
741 ) {
742 return data_array;
743 } else {
744 step = Math.floor(data_array.length / (num_ticks - 1));
745 const indices = _.range(0, data_array.length, step);
746 return indices.map((index) => {
747 return data_array[index];
748 });
749 }
750 }
751 const scale_range = this.axis_scale.scale.domain();
752 const max_index = this.axis_scale.scale.domain().length - 1;
753 step =
754 ((scale_range[max_index] as any) - (scale_range[0] as any)) /
755 (num_ticks - 1);
756 if (isDateScale(this.axis_scale) || isDateColorScale(this.axis_scale)) {
757 //For date scale, the dates have to be converted into milliseconds
758 //since epoch time and then back.
759 scale_range[0] = (scale_range[0] as Date).getTime();
760 scale_range[max_index] = (scale_range[max_index] as Date).getTime();
761 max = (scale_range[max_index] as any) + step * 0.5;
762 const range_in_times = _.range(scale_range[0] as any, max, step);
763 return range_in_times.map((elem) => {
764 return new Date(elem);
765 });
766 } else {
767 max = (scale_range[max_index] as any) + step * 0.5;
768 return _.range(scale_range[0] as any, max, step);
769 }
770 }
771
772 set_scale_promise(model: ScaleModel) {
773 // Sets the child scale

Callers 1

set_tick_valuesMethod · 0.95

Calls 1

rangeMethod · 0.80

Tested by

no test coverage detected