Skip to content

Instantly share code, notes, and snippets.

@nnnnnoel
nnnnnoel / LineChart.js
Created June 2, 2020 02:36
Line Chart Formula
const getLineChartD = ({ data, size, width, padding, topSpacing }) => {
const min = Math.min(...data);
const max = Math.max(...data);
const d = data
.map((v, i) => {
return `${i === 0 ? 'M' : 'L'} ${(i * (width - padding * 5)) / data.length},${
size - (v / (max - min)) * size + (topSpacing || 0)
}`;
}).join(' ');
@nnnnnoel
nnnnnoel / func.js
Created June 2, 2020 02:38
React Native toCommaNumber
export function removeDot(str: string): string {
return str.replace(/(^0)(?=[^.])/, '');
}
export function replComma(str: string): string {
return removeDot(str.replace(/(^[\d,]+\.(?:\d*[^0])?)(0*)$/, '$1').replace(/\.$/, ''));
}
export function addComma(str: string): string {
return str.replace(/\B(?=(\d{3})+(?!\d))/g, ',');