chart-axis
Library to generate a continuous range by some interval, and get the coordinate position according to the specified value
Install
npm install geolib
yarn add geolib
Usage
import { getIntervalRange, getCoordByValue } from 'chart-axis'
const { getIntervalRange, getCoordByValue } = require('chart-axis');
<script src="lib/chart_axis.js"></script>
<script>
const { getIntervalRange, getCoordByValue } = chart_axis;
</script>
Functions
getIntervalRange({ data, intervals = 5, forceInt=false, max=null, steps = [3] })
This function takes up to 3 arguments. First one argument is required.
It returns an incremental array represents the range
const reange1 = getIntervalRange({data:[2343,1234,5434,7435], intervals:5, steps:[3]});
const reange2 = getIntervalRange({data:[2343,1234,5434,7435], intervals:5, steps:[5]})
const reange3 = getIntervalRange({data:[2343,1234,5434,7435], intervals:4, steps:[10]})
const reange4 = getIntervalRange({data:[2343,1234,5434,7435], intervals:5, steps:[2,4,6]});
data
Param 'data' must be an value array, most times it is your data list, it is required
intervals
Param 'intervals' determies how many intervals there are in the value range. It's equal to the number of intervals after the range array removes 0;
steps
Param steps is an array type, the inner elements can be valued from 1 to 10. it determines how to decrease in the range returned
max
forceInt
getCoordByValue({ type = "reverse", minCoord, maxCoord, range })
This function return another function that reutrns the coordinate according to a specified value which is within the given range
type
Param type can only be valued at 'reverse' and 'normal',it determines whether the start point for coordinate of specified value is minCoord or maxCoord.
minCoord
If you have a coordinate system in your page, no matter whether it is svg or canvas or just a div, you should specify which interval of the continuous value range should be distributed in the coordinate system.
minCoord is the minimum coordinate in the coordinate interval
maxCoord
maxCoord is the maxmum coordinate in the coordinate interval
range
an array returned by getIntervalRange
const getCoord = getCoordByValue({minCoord:0,maxCoord:300,range:[0, 1000, 6700, 6900, 7100, 7300, 7500]});
getCoord(7500)
getCoord(0)
getCoord(6900)
const getCoord = getCoordByValue({type:'normal', minCoord:0,maxCoord:300,range:[0, 1000, 6700, 6900, 7100, 7300, 7500]});
getCoord(7500)
getCoord(0)
getCoord(6900)