UNPKG

bands-visualiser

Version:

A plotly.js renderer for Bands, DOS, combined Bands/Dos and fatBands.

81 lines (67 loc) 1.9 kB
import { plotBandLayout, traceDefaultBands } from "./utils/MCXDPlotTemplates"; import { transpose } from "./utils/dataUtils"; import deepmerge from "deepmerge"; import { getXLabelsfromkpath, getXLabelPos, getXYData, prettifyLabels, getColor, } from "./utils/plotUtils"; function getBandTraces(xs, ys, traceFormat = {}) { const lineTraces = []; ys.forEach((yVals, i) => { lineTraces.push({ name: traceFormat.name, legendgroup: traceFormat.name, showlegend: i === 0, ...traceDefaultBands, ...traceFormat, x: xs, y: yVals, }); }); return lineTraces; } function getBandLayout(xLabels = [], xLabelPos = []) { const fullLayout = deepmerge.all([ plotBandLayout, { xaxis: { tickvals: xLabelPos, ticktext: xLabels, }, yaxis: {}, }, ]); return fullLayout; } export function getBandStructure(bandsDataArray) { // layout // TODO add new logic (x, ys)... const splitLabels = getXLabelsfromkpath(bandsDataArray[0].bandsData.path); const xLabels = splitLabels.map(prettifyLabels); const xLabelsPos = getXLabelPos(bandsDataArray[0].bandsData.paths); const bandLayout = getBandLayout(xLabels, xLabelsPos); // traces here let bandTraces = []; for (const [index, i] of bandsDataArray.entries()) { let formatting = i.traceFormat; // if there is no traceFormat info we give a color and a label if (!formatting || Object.keys(formatting).length === 0) { const color = getColor(index); formatting = { name: `Band Structure ${index}`, line: { color: getColor(index), width: 1.0, }, }; } const bandsData = i.bandsData; const { xs, ys } = getXYData(bandsData); const traces = getBandTraces(xs, ys, formatting); bandTraces.push(...traces); } return { bandTraces, bandLayout }; }