bands-visualiser
Version:
A JavaScript library for visualising bandstructures.
49 lines (43 loc) • 1.13 kB
JavaScript
import { transpose } from "./utils/dataUtils";
export function getProjectionTraces(
x,
ys,
weights,
traceFormat = {},
scale = 1.0
) {
const transposedWeights = transpose(weights);
const transposedys = transpose(ys);
const traces = [];
transposedys.forEach((yArr, i) => {
const wArr = transposedWeights[i];
const yTop = new Float64Array(yArr.length);
const yBottom = new Float64Array(yArr.length);
for (let j = 0; j < yArr.length; j++) {
const w = wArr[j] * scale;
yTop[j] = yArr[j] + w;
yBottom[j] = yArr[j] - w;
}
const len = x.length;
const fillX = new Float32Array(len * 2);
const fillY = new Float32Array(len * 2);
for (let j = 0; j < len; j++) {
fillX[j] = x[j];
fillY[j] = yBottom[j];
fillX[2 * len - 1 - j] = x[j];
fillY[2 * len - 1 - j] = yTop[j];
}
traces.push({
name: traceFormat.name,
legendgroup: traceFormat.name,
type: "scatter",
mode: "lines",
fill: "toself",
...traceFormat,
showlegend: i === 0,
x: fillX,
y: fillY,
});
});
return traces;
}