function plotWithXaxis(yArray,xArray,config = {}) {
if (!xArray) xArray = yArray.map((v,i) => i)
const plot = asciichart.plot(yArray,config)
const fullWidth = plot.split('\n')[0].length
const reservedYLegendWidth = plot.split('\n')[0].split(/┤|┼╮|┼/)[0].length + 2
const widthXaxis = fullWidth - reservedYLegendWidth
const longestXLabel = xArray.map(l => l.toString().length).sort((a,b) => b - a)[0]
const maxDecimals = !isNaN(config.decimals) ? config.decimals : xArray.map(l => countDecimals(l)).sort((a,b) => b - a)[0]
const maxNoXLabels = Math.floor(widthXaxis / (longestXLabel + 2))
const valueBetweenLabels = (xArray[xArray.length - 1] - xArray[0]) / (maxNoXLabels - 2)
const factor = Math.pow(10,maxDecimals)
const labels = [Math.round(xArray[0] * factor)/factor]
for (let i = 0; i < maxNoXLabels - 2; ++i) {
labels.push(Math.round((labels[labels.length - 1] + valueBetweenLabels) * factor) / factor)
}
const tickPositions = labels.map(value => Math.round((value - xArray[0]) / (xArray[xArray.length - 1] - xArray[0]) * widthXaxis))
let tickString = [...new Array(reservedYLegendWidth)].join(" ") + [...new Array(widthXaxis)].map((v,i) => tickPositions.indexOf(i) > -1 ? "┬" : "─").join("")
const tickLabelStartPosition = tickPositions.map((pos,i) => pos - Math.floor(labels[i].toString().length / 2 ))
const reservedWhitespace = [...new Array(reservedYLegendWidth - 1)].map((v,i) => {
if ((i - reservedYLegendWidth + 1) == tickLabelStartPosition[0]) return labels[0]
else return " "
}).join("")
const startIndex = reservedWhitespace.length + 1 - reservedYLegendWidth
const tickLabels = []
for (let i = startIndex; i < widthXaxis; ++i) {
if (tickLabelStartPosition.indexOf(i) > -1) {
tickLabels.push(labels[tickLabelStartPosition.indexOf(i)])
i = startIndex + tickLabels.join("").length - 1
}
else tickLabels.push(" ")
}
return box`${'\n' + plot + '\n' + tickString + '\n' + reservedWhitespace + tickLabels.join("")}`
}