charts = {
options: new Object,
setOptions: (options) => {
charts.options = options
charts.options.min = Math.floor(options.min / options.dist) * options.dist
charts.options.max = Math.ceil(options.max / options.dist) * options.dist
return charts
},
getFrag: () => {
return (charts.options.max - charts.options.min) / charts.options.dist;
},
getScale: () => {
let length = charts.getFrag()
let arr = [];
for (let i = 0; i <= length; i++) {
arr.push(charts.options.min + charts.options.dist * i);
}
return arr
},
getOrigin: () => {
let arr = charts.getScale()
let index = arr.indexOf(0)
index == -1 ? 0 : index
return index
},
getRatio: (px) => {
return px / (charts.options.max - charts.options.min)
}
}
console.log(
charts.setOptions({
min: -3,
max: 5,
dist: 2
}).getScale(),
charts.getRatio(720),
charts.getOrigin()
)
console