Skip to content

Commit

Permalink
fix theme fails if trace.marker.color isn't an array (#5144)
Browse files Browse the repository at this point in the history
  • Loading branch information
tehcoderer authored Jun 15, 2023
1 parent 4babd35 commit e464b4e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions frontend-components/plotly/src/components/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ export default function Chart({
if (changeTheme) {
try {
console.log("changeTheme", changeTheme);
const TRACES = plotData?.data.filter((trace) =>
trace?.name?.startsWith("Volume"),
const TRACES = plotData?.data.filter(
(trace) => trace?.name?.trim() === "Volume",
);
const darkmode = !darkMode;

Expand Down Expand Up @@ -375,7 +375,7 @@ export default function Chart({
const volumeColors = darkmode ? volumeColorsDark : volumeColorsLight;

TRACES.forEach((trace) => {
if (trace.type === "bar")
if (trace.type === "bar" && Array.isArray(trace.marker.color))
trace.marker.color = trace.marker.color.map((color) => {
return volumeColors[color] || color;
});
Expand Down
36 changes: 18 additions & 18 deletions frontend-components/plotly/src/components/ResizeHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ export default async function ResizeHandler({
.filter(
(x) =>
plotData.layout[x].showticklabels ||
plotData.layout[x].matches == undefined
plotData.layout[x].matches === undefined,
);

const TRACES = plotData.data.filter((trace) =>
trace?.name?.startsWith("Volume")
const TRACES = plotData.data.filter(
(trace) => trace?.name?.trim() === "Volume",
);

let layout_update: any = {};
let volume: any = volumeBars || { old_nticks: {} };
const layout_update: any = {};
const volume: any = volumeBars || { old_nticks: {} };

const width = window.innerWidth;
const height = window.innerHeight;
let tick_size =
const tick_size =
height > 420 && width < 920 ? 8 : height > 420 && width < 500 ? 9 : 7;

if (width < 750) {
// We hide the modebar and set the number of ticks to 6

TRACES.forEach((trace) => {
if (trace.type == "bar") {
if (trace.type === "bar") {
trace.opacity = 1;
trace.marker.line.width = 0.09;
if (volumeBars.yaxis == undefined) {
volume.yaxis = "yaxis" + trace.yaxis.replace("y", "");
layout_update[volume.yaxis + ".tickfont.size"] = tick_size;
if (volumeBars.yaxis === undefined) {
volume.yaxis = `yaxis${trace.yaxis.replace("y", "")}`;
layout_update[`${volume.yaxis}.tickfont.size`] = tick_size;
volume.tickfont = plotData.layout[volume.yaxis].tickfont || {};

plotData.layout.margin.l -= 40;
Expand All @@ -50,8 +50,8 @@ export default async function ResizeHandler({
});

XAXIS.forEach((x) => {
if (volumeBars.old_nticks?.[x] == undefined) {
layout_update[x + ".nticks"] = 6;
if (volumeBars.old_nticks?.[x] === undefined) {
layout_update[`${x}.nticks`] = 6;
volume.old_nticks[x] = plotData.layout[x].nticks || 10;
}
});
Expand All @@ -63,21 +63,21 @@ export default async function ResizeHandler({
await hideModebar(false);
setMaximizePlot(false);

if (volumeBars.old_nticks != undefined) {
if (volumeBars.old_nticks !== undefined) {
XAXIS.forEach((x) => {
if (volumeBars.old_nticks[x] != undefined) {
layout_update[x + ".nticks"] = volume.old_nticks[x];
if (volumeBars.old_nticks[x] !== undefined) {
layout_update[`${x}.nticks`] = volume.old_nticks[x];
volume.old_nticks[x] = undefined;
}
});
}

if (volumeBars.yaxis != undefined) {
if (volumeBars.yaxis !== undefined) {
TRACES.forEach((trace) => {
if (trace.type == "bar") {
if (trace.type === "bar") {
trace.opacity = 0.5;
trace.marker.line.width = 0.2;
layout_update[volume.yaxis + ".tickfont.size"] =
layout_update[`${volume.yaxis}.tickfont.size`] =
volume.tickfont.size + 3;
plotData.layout.margin.l += 40;
volume.yaxis = undefined;
Expand Down
2 changes: 1 addition & 1 deletion openbb_terminal/core/plots/plotly.html

Large diffs are not rendered by default.

0 comments on commit e464b4e

Please sign in to comment.