UNPKG

wykrestest

Version:

Candlestick Chart made with Konva, React and Jotai

126 lines (125 loc) 3.84 kB
export const highLowFunc = (data) => { let high = 0; let low = 50000; data.forEach((el) => { high = el.high > high ? el.high : high; low = el.low < low ? el.low : low; }); return { high: high, low: low, diff: high - low }; }; export const maxXFunc = (dataLength, winSize, gap, scaleX) => { return -((dataLength - winSize) * gap) * scaleX; }; export const winSizeFunc = (width, gap, scaleX) => { return Math.ceil((width / gap) / scaleX); }; export const winPosFunc = (newX, gap, scaleX) => { return (Math.abs(Math.ceil((newX / gap) / scaleX))); }; export const checkBoundry = (pos, maxX) => { let newPos = pos; if (newPos.x > 0) { newPos.x = 0; } else if (newPos.x < maxX) { newPos.x = maxX; } return newPos; }; export const stepSpace = (diff, steps) => { const tempStep = diff / steps; const mag = Math.floor(Math.log10(tempStep)); const magPow = Math.pow(10, mag); let magMsd = tempStep / magPow + .5; if (magMsd > 5) { magMsd = 10; } else if (magMsd > 2) { magMsd = 5; } else if (magMsd > 1) { magMsd = 2; } return magMsd * magPow; }; export const countDP = (value) => { const text = value.toString(); const index = text.indexOf('.'); // return (text.length - index - 1) //to return the 1.12 (example) return (6 - index); }; //export const dateFunc = (data: IData[]): IDateObj => { // let baseDate = {year: 0, month: 0, day: 0, hour: 0, min: 0} // let years: IDateArray[] = [] // let months: IDateArray[] = [] // let days: IDateArray[] = [] // let hours: IDateArray[] = [] // let mins: IDateArray[] = [] // let count = 0 // let yearClass = new Years // if(data.length > 1){ // data.forEach((el, i) => { // const date = parseISO(el.api_date) // const currYear = date.getFullYear() // const currMonth = date.getMonth() // const currDay = date.getDay() // const currHour = date.getHours() // const currMin = date.getMinutes() // if(baseDate.year == 0){ // baseDate = setBaseDate(date) // } // else if(baseDate.year != currYear){ // //dateObj.newYear({date: date, index: i}) // years.push({date: date, index: i}) // yearClass.push({date: date, index: i}) // baseDate = { // year: currYear, // month: currMonth, // day: currDay, // hour: currHour, // min: currMin} // } // else if(baseDate.month != currMonth){ // months.push({date: date, index: i}) // baseDate = { // ...baseDate, // month: currMonth, // day: currDay, // hour: currHour, // min: currMin // } // } // else if(baseDate.day != currDay){ // days.push({date: date, index: i}) // baseDate = { // ...baseDate, // day: currDay, // hour: currHour, // min: currMin // } // } // else if(baseDate.hour != currHour){ // hours.push({date: date, index: i}) // baseDate = { // ...baseDate, // hour: currHour, // min: currMin // } // } // else if (baseDate.min != currMin){ // mins.push({date: date, index: i}) // baseDate = { // ...baseDate, // min: currMin // } // } // }) // } // return { // years: {data: years, count: count+=years.length}, // months: {data: months, count: count+=months.length}, // days: {data: days, count: count+=days.length}, // hours: {data: hours, count: count+=hours.length}, // mins: {data: mins, count: count+=mins.length} // } //}