Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix / improve autoscaling/dynamic loading, fix forex candle charts, equity reports #5183

Merged
merged 27 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d44337c
improve autoscaling/dynamic loading, fix forex candle charts
tehcoderer Jun 25, 2023
f47c40e
updates
tehcoderer Jun 26, 2023
ca15fdd
Update plotly_helper.py
tehcoderer Jun 27, 2023
7bf6676
fix?
tehcoderer Jun 28, 2023
0bc7c7c
fix table date sorting, localize forex load
tehcoderer Jun 28, 2023
cdbcba8
tests
tehcoderer Jun 29, 2023
8363eab
tests?
tehcoderer Jun 29, 2023
ce63bab
ugh tests
tehcoderer Jun 29, 2023
bad19e4
Update test_display_debt.txt
tehcoderer Jun 29, 2023
299443f
Update test_get_debt.csv
tehcoderer Jun 29, 2023
671852b
Update forex_helper.py
tehcoderer Jun 29, 2023
461b52a
close #5182
tehcoderer Jun 29, 2023
eb77f9c
fix `crypto/dd/info` tables not loading due to `dict` object in dataf…
tehcoderer Jun 29, 2023
fcfdcd9
Update parent_classes.py
tehcoderer Jun 29, 2023
614d951
tables: show full value on hover, fix year only filtering. on reset u…
tehcoderer Jun 30, 2023
c5b7026
Merge branch 'develop' into hotfix/forex-plots
tehcoderer Jul 1, 2023
71379d7
Merge branch 'develop' into hotfix/forex-plots
jmaslek Jul 5, 2023
e613f45
Merge branch 'develop' into hotfix/forex-plots
tehcoderer Jul 5, 2023
8aa0ed3
Merge branch 'develop' into hotfix/forex-plots
tehcoderer Jul 7, 2023
c5e6172
Merge branch 'develop' into hotfix/forex-plots
jmaslek Jul 12, 2023
e430851
Merge branch 'develop' into hotfix/forex-plots
jmaslek Jul 13, 2023
a9fc28e
Merge branch 'develop' into hotfix/forex-plots
jmaslek Jul 14, 2023
f81b184
lint + first batch of test fix
jmaslek Jul 14, 2023
0829159
tests pt2
jmaslek Jul 14, 2023
e88cda6
Tests v3
jmaslek Jul 14, 2023
070be05
Pylint
jmaslek Jul 14, 2023
b861ee5
typo
jmaslek Jul 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions frontend-components/plotly/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend-components/plotly/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@radix-ui/react-dialog": "^1.0.3",
"dom-to-image": "^2.6.0",
"lodash": "^4.17.21",
"plotly.js-dist-min": "^2.21.0",
"posthog-js": "^1.55.0",
"react": "^18.0.0",
Expand All @@ -20,6 +21,7 @@
},
"devDependencies": {
"@types/dom-to-image": "^2.6.4",
"@types/lodash": "^4.14.195",
"@types/node": "^18.16.3",
"@types/plotly.js-dist-min": "^2.3.1",
"@types/react": "^18.0.27",
Expand Down
81 changes: 60 additions & 21 deletions frontend-components/plotly/src/components/AutoScaling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,41 @@ export default async function autoScaling(
let y_min;
let y_max;

const YaxisData = graphs.data.filter(
(trace) => trace.yaxis !== undefined,
);
const get_all_yaxis_traces = {};
const get_all_yaxis_annotations = {};
let volumeTraceYaxis = null;

const yaxis_unique = [
...new Set(
YaxisData.map(
(trace) =>
graphs.data.map((trace) => {
if (
trace.yaxis ||
trace.y !== undefined ||
trace.type === "candlestick",
),
trace.type === "candlestick"
) {
if (trace.type === "bar" && trace?.name?.trim() === "Volume") {
volumeTraceYaxis = `yaxis${trace.yaxis.replace("y", "")}`;
}
get_all_yaxis_traces[trace.yaxis] =
get_all_yaxis_traces[trace.yaxis] || [];
get_all_yaxis_traces[trace.yaxis].push(trace);
return trace.yaxis;
}
}),
),
];

const get_all_yaxis_traces = (yaxis) => {
return graphs.data.filter(
(trace) =>
trace.yaxis === yaxis && (trace.y || trace.type === "candlestick"),
);
};
graphs.layout.annotations.map((annotation, i) => {
if (annotation.yref !== undefined && annotation.yref !== "paper") {
annotation.index = i;
const yaxis = `yaxis${annotation.yref.replace("y", "")}`;
get_all_yaxis_annotations[yaxis] =
get_all_yaxis_annotations[yaxis] || [];
get_all_yaxis_annotations[yaxis].push(annotation);
}
});

yaxis_unique.forEach((unique) => {
yaxis_unique.map((unique) => {
if (typeof unique !== "string") {
return;
}
Expand All @@ -44,7 +57,7 @@ export default async function autoScaling(
let y_values = [];
let log_scale = graphs.layout[yaxis].type === "log";

get_all_yaxis_traces(unique).forEach((trace2) => {
get_all_yaxis_traces[unique].map((trace2) => {
const x = trace2.x;
log_scale = graphs.layout[yaxis].type === "log";

Expand All @@ -62,7 +75,23 @@ export default async function autoScaling(

const yx_values = x.map((x, i) => {
let out = null;
if (x >= x_min && x <= x_max) {
const isoDateRegex = new RegExp(
"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}",
);
if (isoDateRegex.test(x)) {
const x_time = new Date(x).getTime();
const x0_min = new Date(x_min.replace(" ", "T")).getTime();
const x1_max = new Date(x_max.replace(" ", "T")).getTime();
if (x_time >= x0_min && x_time <= x1_max) {
if (trace2.y !== undefined) {
out = y[i];
}
if (trace2.type === "candlestick") {
y_candle.push(y_low[i]);
y_candle.push(y_high[i]);
}
}
} else if (x >= x_min && x <= x_max) {
if (trace2.y !== undefined) {
out = y[i];
}
Expand All @@ -88,10 +117,6 @@ export default async function autoScaling(
}

const org_y_max = y_max;
const is_volume =
graphs.layout[yaxis].fixedrange !== undefined &&
yaxis !== "yaxis" &&
graphs.layout[yaxis].fixedrange === true;

if (y_min !== undefined && y_max !== undefined) {
const y_range = y_max - y_min;
Expand All @@ -103,7 +128,7 @@ export default async function autoScaling(
y_min -= y_range * y_mult;
y_max += y_range * y_mult;

if (is_volume) {
if (yaxis === volumeTraceYaxis) {
if (graphs.layout[yaxis].tickvals !== undefined) {
const range_x = 7;
const volume_ticks = org_y_max;
Expand Down Expand Up @@ -137,6 +162,20 @@ export default async function autoScaling(
to_update[`${yaxis}.range`] = [y_min, y_max];
to_update[`${yaxis}.fixedrange`] = true;
yaxis_fixedrange.push(yaxis);

if (get_all_yaxis_annotations[yaxis] !== undefined) {
get_all_yaxis_annotations[yaxis].map((annotation) => {
if (annotation.ay !== undefined) {
const yshift = annotation.ay;
const yshift_new = Math.min(
Math.max(yshift, y_min + y_range * 0.2),
y_max - y_range * 0.2,
);

to_update[`annotations[${annotation.index}].ay`] = yshift_new;
}
});
}
}
});

Expand Down
Loading