camelcase intervals.js
This commit is contained in:
parent
0b0c26002f
commit
eeefeeb54d
122
dist/frappe-charts.esm.js
vendored
122
dist/frappe-charts.esm.js
vendored
@ -396,77 +396,77 @@ function normalize(x) {
|
|||||||
return [sig * man, exp];
|
return [sig * man, exp];
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_range_intervals(max, min=0) {
|
function getRangeIntervals(max, min=0) {
|
||||||
let upper_bound = Math.ceil(max);
|
let upperBound = Math.ceil(max);
|
||||||
let lower_bound = Math.floor(min);
|
let lowerBound = Math.floor(min);
|
||||||
let range = upper_bound - lower_bound;
|
let range = upperBound - lowerBound;
|
||||||
|
|
||||||
let no_of_parts = range;
|
let noOfParts = range;
|
||||||
let part_size = 1;
|
let partSize = 1;
|
||||||
|
|
||||||
// To avoid too many partitions
|
// To avoid too many partitions
|
||||||
if(range > 5) {
|
if(range > 5) {
|
||||||
if(range % 2 !== 0) {
|
if(range % 2 !== 0) {
|
||||||
upper_bound++;
|
upperBound++;
|
||||||
// Recalc range
|
// Recalc range
|
||||||
range = upper_bound - lower_bound;
|
range = upperBound - lowerBound;
|
||||||
}
|
}
|
||||||
no_of_parts = range/2;
|
noOfParts = range/2;
|
||||||
part_size = 2;
|
partSize = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case: 1 and 2
|
// Special case: 1 and 2
|
||||||
if(range <= 2) {
|
if(range <= 2) {
|
||||||
no_of_parts = 4;
|
noOfParts = 4;
|
||||||
part_size = range/no_of_parts;
|
partSize = range/noOfParts;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case: 0
|
// Special case: 0
|
||||||
if(range === 0) {
|
if(range === 0) {
|
||||||
no_of_parts = 5;
|
noOfParts = 5;
|
||||||
part_size = 1;
|
partSize = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let intervals = [];
|
let intervals = [];
|
||||||
for(var i = 0; i <= no_of_parts; i++){
|
for(var i = 0; i <= noOfParts; i++){
|
||||||
intervals.push(lower_bound + part_size * i);
|
intervals.push(lowerBound + partSize * i);
|
||||||
}
|
}
|
||||||
return intervals;
|
return intervals;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_intervals(max_value, min_value=0) {
|
function getIntervals(maxValue, minValue=0) {
|
||||||
let [normal_max_value, exponent] = normalize(max_value);
|
let [normalMaxValue, exponent] = normalize(maxValue);
|
||||||
let normal_min_value = min_value ? min_value/Math.pow(10, exponent): 0;
|
let normalMinValue = minValue ? minValue/Math.pow(10, exponent): 0;
|
||||||
|
|
||||||
// Allow only 7 significant digits
|
// Allow only 7 significant digits
|
||||||
normal_max_value = normal_max_value.toFixed(6);
|
normalMaxValue = normalMaxValue.toFixed(6);
|
||||||
|
|
||||||
let intervals = get_range_intervals(normal_max_value, normal_min_value);
|
let intervals = getRangeIntervals(normalMaxValue, normalMinValue);
|
||||||
intervals = intervals.map(value => value * Math.pow(10, exponent));
|
intervals = intervals.map(value => value * Math.pow(10, exponent));
|
||||||
return intervals;
|
return intervals;
|
||||||
}
|
}
|
||||||
|
|
||||||
function calc_intervals(values, with_minimum=false) {
|
function calcIntervals(values, withMinimum=false) {
|
||||||
//*** Where the magic happens ***
|
//*** Where the magic happens ***
|
||||||
|
|
||||||
// Calculates best-fit y intervals from given values
|
// Calculates best-fit y intervals from given values
|
||||||
// and returns the interval array
|
// and returns the interval array
|
||||||
|
|
||||||
let max_value = Math.max(...values);
|
let maxValue = Math.max(...values);
|
||||||
let min_value = Math.min(...values);
|
let minValue = Math.min(...values);
|
||||||
|
|
||||||
// Exponent to be used for pretty print
|
// Exponent to be used for pretty print
|
||||||
let exponent = 0, intervals = []; // eslint-disable-line no-unused-vars
|
let exponent = 0, intervals = []; // eslint-disable-line no-unused-vars
|
||||||
|
|
||||||
function get_positive_first_intervals(max_value, abs_min_value) {
|
function getPositiveFirstIntervals(maxValue, absMinValue) {
|
||||||
let intervals = get_intervals(max_value);
|
let intervals = getIntervals(maxValue);
|
||||||
|
|
||||||
let interval_size = intervals[1] - intervals[0];
|
let intervalSize = intervals[1] - intervals[0];
|
||||||
|
|
||||||
// Then unshift the negative values
|
// Then unshift the negative values
|
||||||
let value = 0;
|
let value = 0;
|
||||||
for(var i = 1; value < abs_min_value; i++) {
|
for(var i = 1; value < absMinValue; i++) {
|
||||||
value += interval_size;
|
value += intervalSize;
|
||||||
intervals.unshift((-1) * value);
|
intervals.unshift((-1) * value);
|
||||||
}
|
}
|
||||||
return intervals;
|
return intervals;
|
||||||
@ -474,52 +474,52 @@ function calc_intervals(values, with_minimum=false) {
|
|||||||
|
|
||||||
// CASE I: Both non-negative
|
// CASE I: Both non-negative
|
||||||
|
|
||||||
if(max_value >= 0 && min_value >= 0) {
|
if(maxValue >= 0 && minValue >= 0) {
|
||||||
exponent = normalize(max_value)[1];
|
exponent = normalize(maxValue)[1];
|
||||||
if(!with_minimum) {
|
if(!withMinimum) {
|
||||||
intervals = get_intervals(max_value);
|
intervals = getIntervals(maxValue);
|
||||||
} else {
|
} else {
|
||||||
intervals = get_intervals(max_value, min_value);
|
intervals = getIntervals(maxValue, minValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CASE II: Only min_value negative
|
// CASE II: Only minValue negative
|
||||||
|
|
||||||
else if(max_value > 0 && min_value < 0) {
|
else if(maxValue > 0 && minValue < 0) {
|
||||||
// `with_minimum` irrelevant in this case,
|
// `withMinimum` irrelevant in this case,
|
||||||
// We'll be handling both sides of zero separately
|
// We'll be handling both sides of zero separately
|
||||||
// (both starting from zero)
|
// (both starting from zero)
|
||||||
// Because ceil() and floor() behave differently
|
// Because ceil() and floor() behave differently
|
||||||
// in those two regions
|
// in those two regions
|
||||||
|
|
||||||
let abs_min_value = Math.abs(min_value);
|
let absMinValue = Math.abs(minValue);
|
||||||
|
|
||||||
if(max_value >= abs_min_value) {
|
if(maxValue >= absMinValue) {
|
||||||
exponent = normalize(max_value)[1];
|
exponent = normalize(maxValue)[1];
|
||||||
intervals = get_positive_first_intervals(max_value, abs_min_value);
|
intervals = getPositiveFirstIntervals(maxValue, absMinValue);
|
||||||
} else {
|
} else {
|
||||||
// Mirror: max_value => abs_min_value, then change sign
|
// Mirror: maxValue => absMinValue, then change sign
|
||||||
exponent = normalize(abs_min_value)[1];
|
exponent = normalize(absMinValue)[1];
|
||||||
let pos_intervals = get_positive_first_intervals(abs_min_value, max_value);
|
let posIntervals = getPositiveFirstIntervals(absMinValue, maxValue);
|
||||||
intervals = pos_intervals.map(d => d * (-1));
|
intervals = posIntervals.map(d => d * (-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CASE III: Both non-positive
|
// CASE III: Both non-positive
|
||||||
|
|
||||||
else if(max_value <= 0 && min_value <= 0) {
|
else if(maxValue <= 0 && minValue <= 0) {
|
||||||
// Mirrored Case I:
|
// Mirrored Case I:
|
||||||
// Work with positives, then reverse the sign and array
|
// Work with positives, then reverse the sign and array
|
||||||
|
|
||||||
let pseudo_max_value = Math.abs(min_value);
|
let pseudoMaxValue = Math.abs(minValue);
|
||||||
let pseudo_min_value = Math.abs(max_value);
|
let pseudoMinValue = Math.abs(maxValue);
|
||||||
|
|
||||||
exponent = normalize(pseudo_max_value)[1];
|
exponent = normalize(pseudoMaxValue)[1];
|
||||||
if(!with_minimum) {
|
if(!withMinimum) {
|
||||||
intervals = get_intervals(pseudo_max_value);
|
intervals = getIntervals(pseudoMaxValue);
|
||||||
} else {
|
} else {
|
||||||
intervals = get_intervals(pseudo_max_value, pseudo_min_value);
|
intervals = getIntervals(pseudoMaxValue, pseudoMinValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
intervals = intervals.reverse().map(d => d * (-1));
|
intervals = intervals.reverse().map(d => d * (-1));
|
||||||
@ -528,24 +528,24 @@ function calc_intervals(values, with_minimum=false) {
|
|||||||
return intervals;
|
return intervals;
|
||||||
}
|
}
|
||||||
|
|
||||||
function calc_distribution(values, distribution_size) {
|
function calcDistribution(values, distributionSize) {
|
||||||
// Assume non-negative values,
|
// Assume non-negative values,
|
||||||
// implying distribution minimum at zero
|
// implying distribution minimum at zero
|
||||||
|
|
||||||
let data_max_value = Math.max(...values);
|
let dataMaxValue = Math.max(...values);
|
||||||
|
|
||||||
let distribution_step = 1 / (distribution_size - 1);
|
let distributionStep = 1 / (distributionSize - 1);
|
||||||
let distribution = [];
|
let distribution = [];
|
||||||
|
|
||||||
for(var i = 0; i < distribution_size; i++) {
|
for(var i = 0; i < distributionSize; i++) {
|
||||||
let checkpoint = data_max_value * (distribution_step * i);
|
let checkpoint = dataMaxValue * (distributionStep * i);
|
||||||
distribution.push(checkpoint);
|
distribution.push(checkpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
return distribution;
|
return distribution;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_max_checkpoint(value, distribution) {
|
function getMaxCheckpoint(value, distribution) {
|
||||||
return distribution.filter(d => d < value).length;
|
return distribution.filter(d => d < value).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1099,7 +1099,7 @@ class AxisChart extends BaseChart {
|
|||||||
values = values.concat(this.y_sums);
|
values = values.concat(this.y_sums);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.y_axis_values = calc_intervals(values, this.type === 'line');
|
this.y_axis_values = calcIntervals(values, this.type === 'line');
|
||||||
|
|
||||||
if(!this.y_old_axis_values) {
|
if(!this.y_old_axis_values) {
|
||||||
this.y_old_axis_values = this.y_axis_values.slice();
|
this.y_old_axis_values = this.y_axis_values.slice();
|
||||||
@ -2600,7 +2600,7 @@ class Heatmap extends BaseChart {
|
|||||||
this.data_groups.textContent = '';
|
this.data_groups.textContent = '';
|
||||||
|
|
||||||
let data_values = Object.keys(this.data).map(key => this.data[key]);
|
let data_values = Object.keys(this.data).map(key => this.data[key]);
|
||||||
this.distribution = calc_distribution(data_values, this.distribution_size);
|
this.distribution = calcDistribution(data_values, this.distribution_size);
|
||||||
|
|
||||||
this.month_names = ["January", "February", "March", "April", "May", "June",
|
this.month_names = ["January", "February", "March", "April", "May", "June",
|
||||||
"July", "August", "September", "October", "November", "December"
|
"July", "August", "September", "October", "November", "December"
|
||||||
@ -2668,7 +2668,7 @@ class Heatmap extends BaseChart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(data_value) {
|
if(data_value) {
|
||||||
color_index = get_max_checkpoint(data_value, this.distribution);
|
color_index = getMaxCheckpoint(data_value, this.distribution);
|
||||||
}
|
}
|
||||||
|
|
||||||
let x = 13 + (index + week_col_change) * 12;
|
let x = 13 + (index + week_col_change) * 12;
|
||||||
|
|||||||
2
dist/frappe-charts.min.cjs.js
vendored
2
dist/frappe-charts.min.cjs.js
vendored
File diff suppressed because one or more lines are too long
2
dist/frappe-charts.min.esm.js
vendored
2
dist/frappe-charts.min.esm.js
vendored
File diff suppressed because one or more lines are too long
@ -1,7 +1,7 @@
|
|||||||
import $ from '../utils/dom';
|
import $ from '../utils/dom';
|
||||||
import { UnitRenderer, make_x_line, make_y_line } from '../utils/draw';
|
import { UnitRenderer, make_x_line, make_y_line } from '../utils/draw';
|
||||||
import { runSVGAnimation } from '../utils/animate';
|
import { runSVGAnimation } from '../utils/animate';
|
||||||
import { calc_intervals } from '../utils/intervals';
|
import { calcIntervals } from '../utils/intervals';
|
||||||
import { float_2, arrays_equal, get_string_width } from '../utils/helpers';
|
import { float_2, arrays_equal, get_string_width } from '../utils/helpers';
|
||||||
import BaseChart from './BaseChart';
|
import BaseChart from './BaseChart';
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ export default class AxisChart extends BaseChart {
|
|||||||
values = values.concat(this.y_sums);
|
values = values.concat(this.y_sums);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.y_axis_values = calc_intervals(values, this.type === 'line');
|
this.y_axis_values = calcIntervals(values, this.type === 'line');
|
||||||
|
|
||||||
if(!this.y_old_axis_values) {
|
if(!this.y_old_axis_values) {
|
||||||
this.y_old_axis_values = this.y_axis_values.slice();
|
this.y_old_axis_values = this.y_axis_values.slice();
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import BaseChart from './BaseChart';
|
import BaseChart from './BaseChart';
|
||||||
import $ from '../utils/dom';
|
import $ from '../utils/dom';
|
||||||
import { add_days, get_dd_mm_yyyy, get_weeks_between } from '../utils/date-utils';
|
import { add_days, get_dd_mm_yyyy, get_weeks_between } from '../utils/date-utils';
|
||||||
import { calc_distribution, get_max_checkpoint } from '../utils/intervals';
|
import { calcDistribution, getMaxCheckpoint } from '../utils/intervals';
|
||||||
import { is_valid_color } from '../utils/colors';
|
import { is_valid_color } from '../utils/colors';
|
||||||
|
|
||||||
export default class Heatmap extends BaseChart {
|
export default class Heatmap extends BaseChart {
|
||||||
@ -97,7 +97,7 @@ export default class Heatmap extends BaseChart {
|
|||||||
this.data_groups.textContent = '';
|
this.data_groups.textContent = '';
|
||||||
|
|
||||||
let data_values = Object.keys(this.data).map(key => this.data[key]);
|
let data_values = Object.keys(this.data).map(key => this.data[key]);
|
||||||
this.distribution = calc_distribution(data_values, this.distribution_size);
|
this.distribution = calcDistribution(data_values, this.distribution_size);
|
||||||
|
|
||||||
this.month_names = ["January", "February", "March", "April", "May", "June",
|
this.month_names = ["January", "February", "March", "April", "May", "June",
|
||||||
"July", "August", "September", "October", "November", "December"
|
"July", "August", "September", "October", "November", "December"
|
||||||
@ -165,7 +165,7 @@ export default class Heatmap extends BaseChart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(data_value) {
|
if(data_value) {
|
||||||
color_index = get_max_checkpoint(data_value, this.distribution);
|
color_index = getMaxCheckpoint(data_value, this.distribution);
|
||||||
}
|
}
|
||||||
|
|
||||||
let x = 13 + (index + week_col_change) * 12;
|
let x = 13 + (index + week_col_change) * 12;
|
||||||
|
|||||||
@ -21,77 +21,77 @@ function normalize(x) {
|
|||||||
return [sig * man, exp];
|
return [sig * man, exp];
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_range_intervals(max, min=0) {
|
function getRangeIntervals(max, min=0) {
|
||||||
let upper_bound = Math.ceil(max);
|
let upperBound = Math.ceil(max);
|
||||||
let lower_bound = Math.floor(min);
|
let lowerBound = Math.floor(min);
|
||||||
let range = upper_bound - lower_bound;
|
let range = upperBound - lowerBound;
|
||||||
|
|
||||||
let no_of_parts = range;
|
let noOfParts = range;
|
||||||
let part_size = 1;
|
let partSize = 1;
|
||||||
|
|
||||||
// To avoid too many partitions
|
// To avoid too many partitions
|
||||||
if(range > 5) {
|
if(range > 5) {
|
||||||
if(range % 2 !== 0) {
|
if(range % 2 !== 0) {
|
||||||
upper_bound++;
|
upperBound++;
|
||||||
// Recalc range
|
// Recalc range
|
||||||
range = upper_bound - lower_bound;
|
range = upperBound - lowerBound;
|
||||||
}
|
}
|
||||||
no_of_parts = range/2;
|
noOfParts = range/2;
|
||||||
part_size = 2;
|
partSize = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case: 1 and 2
|
// Special case: 1 and 2
|
||||||
if(range <= 2) {
|
if(range <= 2) {
|
||||||
no_of_parts = 4;
|
noOfParts = 4;
|
||||||
part_size = range/no_of_parts;
|
partSize = range/noOfParts;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case: 0
|
// Special case: 0
|
||||||
if(range === 0) {
|
if(range === 0) {
|
||||||
no_of_parts = 5;
|
noOfParts = 5;
|
||||||
part_size = 1;
|
partSize = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let intervals = [];
|
let intervals = [];
|
||||||
for(var i = 0; i <= no_of_parts; i++){
|
for(var i = 0; i <= noOfParts; i++){
|
||||||
intervals.push(lower_bound + part_size * i);
|
intervals.push(lowerBound + partSize * i);
|
||||||
}
|
}
|
||||||
return intervals;
|
return intervals;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_intervals(max_value, min_value=0) {
|
function getIntervals(maxValue, minValue=0) {
|
||||||
let [normal_max_value, exponent] = normalize(max_value);
|
let [normalMaxValue, exponent] = normalize(maxValue);
|
||||||
let normal_min_value = min_value ? min_value/Math.pow(10, exponent): 0;
|
let normalMinValue = minValue ? minValue/Math.pow(10, exponent): 0;
|
||||||
|
|
||||||
// Allow only 7 significant digits
|
// Allow only 7 significant digits
|
||||||
normal_max_value = normal_max_value.toFixed(6);
|
normalMaxValue = normalMaxValue.toFixed(6);
|
||||||
|
|
||||||
let intervals = get_range_intervals(normal_max_value, normal_min_value);
|
let intervals = getRangeIntervals(normalMaxValue, normalMinValue);
|
||||||
intervals = intervals.map(value => value * Math.pow(10, exponent));
|
intervals = intervals.map(value => value * Math.pow(10, exponent));
|
||||||
return intervals;
|
return intervals;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calc_intervals(values, with_minimum=false) {
|
export function calcIntervals(values, withMinimum=false) {
|
||||||
//*** Where the magic happens ***
|
//*** Where the magic happens ***
|
||||||
|
|
||||||
// Calculates best-fit y intervals from given values
|
// Calculates best-fit y intervals from given values
|
||||||
// and returns the interval array
|
// and returns the interval array
|
||||||
|
|
||||||
let max_value = Math.max(...values);
|
let maxValue = Math.max(...values);
|
||||||
let min_value = Math.min(...values);
|
let minValue = Math.min(...values);
|
||||||
|
|
||||||
// Exponent to be used for pretty print
|
// Exponent to be used for pretty print
|
||||||
let exponent = 0, intervals = []; // eslint-disable-line no-unused-vars
|
let exponent = 0, intervals = []; // eslint-disable-line no-unused-vars
|
||||||
|
|
||||||
function get_positive_first_intervals(max_value, abs_min_value) {
|
function getPositiveFirstIntervals(maxValue, absMinValue) {
|
||||||
let intervals = get_intervals(max_value);
|
let intervals = getIntervals(maxValue);
|
||||||
|
|
||||||
let interval_size = intervals[1] - intervals[0];
|
let intervalSize = intervals[1] - intervals[0];
|
||||||
|
|
||||||
// Then unshift the negative values
|
// Then unshift the negative values
|
||||||
let value = 0;
|
let value = 0;
|
||||||
for(var i = 1; value < abs_min_value; i++) {
|
for(var i = 1; value < absMinValue; i++) {
|
||||||
value += interval_size;
|
value += intervalSize;
|
||||||
intervals.unshift((-1) * value);
|
intervals.unshift((-1) * value);
|
||||||
}
|
}
|
||||||
return intervals;
|
return intervals;
|
||||||
@ -99,52 +99,52 @@ export function calc_intervals(values, with_minimum=false) {
|
|||||||
|
|
||||||
// CASE I: Both non-negative
|
// CASE I: Both non-negative
|
||||||
|
|
||||||
if(max_value >= 0 && min_value >= 0) {
|
if(maxValue >= 0 && minValue >= 0) {
|
||||||
exponent = normalize(max_value)[1];
|
exponent = normalize(maxValue)[1];
|
||||||
if(!with_minimum) {
|
if(!withMinimum) {
|
||||||
intervals = get_intervals(max_value);
|
intervals = getIntervals(maxValue);
|
||||||
} else {
|
} else {
|
||||||
intervals = get_intervals(max_value, min_value);
|
intervals = getIntervals(maxValue, minValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CASE II: Only min_value negative
|
// CASE II: Only minValue negative
|
||||||
|
|
||||||
else if(max_value > 0 && min_value < 0) {
|
else if(maxValue > 0 && minValue < 0) {
|
||||||
// `with_minimum` irrelevant in this case,
|
// `withMinimum` irrelevant in this case,
|
||||||
// We'll be handling both sides of zero separately
|
// We'll be handling both sides of zero separately
|
||||||
// (both starting from zero)
|
// (both starting from zero)
|
||||||
// Because ceil() and floor() behave differently
|
// Because ceil() and floor() behave differently
|
||||||
// in those two regions
|
// in those two regions
|
||||||
|
|
||||||
let abs_min_value = Math.abs(min_value);
|
let absMinValue = Math.abs(minValue);
|
||||||
|
|
||||||
if(max_value >= abs_min_value) {
|
if(maxValue >= absMinValue) {
|
||||||
exponent = normalize(max_value)[1];
|
exponent = normalize(maxValue)[1];
|
||||||
intervals = get_positive_first_intervals(max_value, abs_min_value);
|
intervals = getPositiveFirstIntervals(maxValue, absMinValue);
|
||||||
} else {
|
} else {
|
||||||
// Mirror: max_value => abs_min_value, then change sign
|
// Mirror: maxValue => absMinValue, then change sign
|
||||||
exponent = normalize(abs_min_value)[1];
|
exponent = normalize(absMinValue)[1];
|
||||||
let pos_intervals = get_positive_first_intervals(abs_min_value, max_value);
|
let posIntervals = getPositiveFirstIntervals(absMinValue, maxValue);
|
||||||
intervals = pos_intervals.map(d => d * (-1));
|
intervals = posIntervals.map(d => d * (-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CASE III: Both non-positive
|
// CASE III: Both non-positive
|
||||||
|
|
||||||
else if(max_value <= 0 && min_value <= 0) {
|
else if(maxValue <= 0 && minValue <= 0) {
|
||||||
// Mirrored Case I:
|
// Mirrored Case I:
|
||||||
// Work with positives, then reverse the sign and array
|
// Work with positives, then reverse the sign and array
|
||||||
|
|
||||||
let pseudo_max_value = Math.abs(min_value);
|
let pseudoMaxValue = Math.abs(minValue);
|
||||||
let pseudo_min_value = Math.abs(max_value);
|
let pseudoMinValue = Math.abs(maxValue);
|
||||||
|
|
||||||
exponent = normalize(pseudo_max_value)[1];
|
exponent = normalize(pseudoMaxValue)[1];
|
||||||
if(!with_minimum) {
|
if(!withMinimum) {
|
||||||
intervals = get_intervals(pseudo_max_value);
|
intervals = getIntervals(pseudoMaxValue);
|
||||||
} else {
|
} else {
|
||||||
intervals = get_intervals(pseudo_max_value, pseudo_min_value);
|
intervals = getIntervals(pseudoMaxValue, pseudoMinValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
intervals = intervals.reverse().map(d => d * (-1));
|
intervals = intervals.reverse().map(d => d * (-1));
|
||||||
@ -153,23 +153,23 @@ export function calc_intervals(values, with_minimum=false) {
|
|||||||
return intervals;
|
return intervals;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calc_distribution(values, distribution_size) {
|
export function calcDistribution(values, distributionSize) {
|
||||||
// Assume non-negative values,
|
// Assume non-negative values,
|
||||||
// implying distribution minimum at zero
|
// implying distribution minimum at zero
|
||||||
|
|
||||||
let data_max_value = Math.max(...values);
|
let dataMaxValue = Math.max(...values);
|
||||||
|
|
||||||
let distribution_step = 1 / (distribution_size - 1);
|
let distributionStep = 1 / (distributionSize - 1);
|
||||||
let distribution = [];
|
let distribution = [];
|
||||||
|
|
||||||
for(var i = 0; i < distribution_size; i++) {
|
for(var i = 0; i < distributionSize; i++) {
|
||||||
let checkpoint = data_max_value * (distribution_step * i);
|
let checkpoint = dataMaxValue * (distributionStep * i);
|
||||||
distribution.push(checkpoint);
|
distribution.push(checkpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
return distribution;
|
return distribution;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get_max_checkpoint(value, distribution) {
|
export function getMaxCheckpoint(value, distribution) {
|
||||||
return distribution.filter(d => d < value).length;
|
return distribution.filter(d => d < value).length;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user