Skip to content

Commit 0acdbad

Browse files
authored
Workaround the colorfill problem for the vertical DOS plot (#56)
The dos plot has problem that the TDOS will have a spurious step jump if the grap colorfill background is used. We don't know what exactly cause the issue but the workaround is found by adding a dumb dos as the first line to the plot. --------- Co-authored-by: Jusong Yu <[email protected]>
1 parent d7979b5 commit 0acdbad

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

js/lib/bands.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ function bandPlot(bandDivId, bandPathTextBoxId, dataFilePaths, dosFile, showFerm
170170
$("#" + bandDivId + "bt-togglePdos").addClass("button-white");
171171
$("#" + bandDivId + "bt-togglePdos").removeClass("button");
172172

173-
for (var i = 1; i < theBandPlot.dosSeries.length; i++) {
173+
// The PDOS curves start from index 2.
174+
// Index 0 is for the dumb datset of y axis add to workaround the step change issue #49 .
175+
// Index 1 is for total DOS (The widget don't know if the first set of data is TDOS or not, this need to be polish in future.)
176+
for (var i = 2; i < theBandPlot.dosSeries.length; i++) {
174177
theBandPlot.dosSeries[i].hidden = true;
175178
};
176179
theBandPlot.myDos.update();
@@ -179,7 +182,7 @@ function bandPlot(bandDivId, bandPathTextBoxId, dataFilePaths, dosFile, showFerm
179182
$("#" + bandDivId + "bt-togglePdos").addClass("button");
180183
$("#" + bandDivId + "bt-togglePdos").removeClass("button-white");
181184

182-
for (var i = 1; i < theBandPlot.dosSeries.length; i++) {
185+
for (var i = 2; i < theBandPlot.dosSeries.length; i++) {
183186
theBandPlot.dosSeries[i].hidden = false;
184187
};
185188
theBandPlot.myDos.update();

js/lib/bandstructure.js

+47-1
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ BandPlot.prototype.initDosChart = function (orientation = 'vertical') {
332332
legend: {
333333
display: this.showLegend,
334334
position: 'right',
335+
labels: {
336+
filter: function(item, chart) {
337+
// remove the label for the dumb dataset of the y axis
338+
return !item.text.includes('y axis');
339+
}
340+
}
335341
},
336342
scales: {
337343
xAxes: [{
@@ -443,6 +449,12 @@ BandPlot.prototype.initDosChart = function (orientation = 'vertical') {
443449
legend: {
444450
display: true,
445451
position: 'right',
452+
labels: {
453+
filter: function(item, chart) {
454+
// remove the label for the dumb dataset of the y axis
455+
return !item.text.includes('y axis');
456+
}
457+
}
446458
},
447459
scales: {
448460
yAxes: [{
@@ -784,6 +796,40 @@ BandPlot.prototype.updateDosPlot = function (orientation = 'vertical') {
784796
bandPlotObject.dosSeries = [];
785797
curve = [];
786798

799+
800+
// Here, a dumb dataset was created to represent the y axis.
801+
// All the DOS curves were filled to this dumb dataset.
802+
var dosx = bandPlotObject.dosData['dos'][0]['x'];
803+
var dosy = bandPlotObject.dosData['dos'][0]['y'];
804+
805+
// The dumb dataset was set to the Fermi level (<= dosFermiEnergy)
806+
// So the color fill will up to the Fermi level
807+
dosx.forEach(function (data, k) {
808+
if (orientation === 'vertical') {
809+
if (data <= bandPlotObject.dosFermiEnergy) {
810+
curve.push({ x: 0, y: data - bandPlotObject.dosFermiEnergy });
811+
};
812+
} else {
813+
if (data <= bandPlotObject.dosFermiEnergy) {
814+
curve.push({ x: data - bandPlotObject.dosFermiEnergy, y: 0 });
815+
};
816+
};
817+
});
818+
819+
// The color of the dumb dataset is white, label is 'y axis'
820+
var dumb_dos = {
821+
borderColor: 'white',
822+
hidden: false,
823+
borderWidth: 1,
824+
data: curve,
825+
fill: false,
826+
showLine: true,
827+
pointRadius: 0,
828+
label: 'y axis'
829+
};
830+
831+
bandPlotObject.dosSeries.push(dumb_dos);
832+
787833
for (let i = 0; i < bandPlotObject.dosData['dos'].length; i++) {
788834
curve = [];
789835

@@ -804,7 +850,7 @@ BandPlot.prototype.updateDosPlot = function (orientation = 'vertical') {
804850
hidden: false,
805851
borderWidth: 1,
806852
data: curve,
807-
fill: true,
853+
fill: 0,
808854
showLine: true,
809855
pointRadius: 0,
810856
label: bandPlotObject.dosData['dos'][i]['label'],

0 commit comments

Comments
 (0)