Skip to content

Commit

Permalink
Fix: reformat long seqs
Browse files Browse the repository at this point in the history
  • Loading branch information
joko3ono committed Oct 26, 2024
1 parent 57004bc commit 103b934
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion public/css/app.min.css

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions public/js/length_distribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,20 @@ class Graph {
}

tick_formatter(seq_type) {
var ticks = this._scale_x.ticks();
var prefix = d3.format('~s');
var suffixes = {amino_acid: 'aa', nucleic_acid: 'bp'};
return function (d) {
if (d === 0) { return ; }
if (_.indexOf(ticks,d) >= 0) {
if (suffixes[seq_type] == 'aa') {
return `${d} ${suffixes[seq_type]}`;
} else {
return `${prefix(d)}${suffixes[seq_type]}`.replace(/([a-zA-Z]+)/, ' $1');
}
const ticks = this._scale_x.ticks();
const prefix = d3.format('~s');
const suffixes = { amino_acid: 'aa', nucleic_acid: 'bp' };

return (d) => {
if (d === 0 || !ticks.includes(d)) return;

if (suffixes[seq_type] === 'aa') {
return `${d} ${suffixes[seq_type]}`;
} else {
return ;
const formatted = prefix(d);
const numericPart = Math.floor(parseFloat(formatted));
const suffix = formatted.replace(/[0-9.]/g, '');
return `${numericPart} ${suffix}${suffixes[seq_type]}`;
}
};
}
Expand Down
11 changes: 7 additions & 4 deletions public/js/visualisation_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ export function getPrefix(str) {
* Borrowed from Kablammo. Modified by Priyam based on https://github.com/mbostock/d3/issues/1722.
*/
export function tick_formatter(scale, seq_type) {
var prefix = d3.format('~s')
var suffixes = {amino_acid: 'aa', nucleic_acid: 'bp'};
const prefix = d3.format('~s')
const suffixes = {amino_acid: 'aa', nucleic_acid: 'bp'};

return function (d) {
return `${prefix(d)}${suffixes[seq_type]}`
.replace(/([a-zA-Z]+)/, ' $1')
const formatted = prefix(d);
const numericPart = Math.floor(parseFloat(formatted));
const suffix = formatted.replace(/[0-9.]/g, '');

return `${numericPart} ${suffix}${suffixes[seq_type]}`;
};
}

Expand Down
3 changes: 1 addition & 2 deletions public/sequenceserver-report.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/sequenceserver-report.min.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions public/sequenceserver-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/sequenceserver-search.min.js.map

Large diffs are not rendered by default.

0 comments on commit 103b934

Please sign in to comment.