Skip to content

Commit

Permalink
Merge from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
eweitz committed Dec 7, 2024
2 parents 669eda2 + 36ca987 commit 77247f0
Show file tree
Hide file tree
Showing 18 changed files with 1,920 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on:
push:
branches:
- github-actions
- '*'
pull_request:
branches:
- main
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A [broader overview](https://speakerdeck.com/eweitz/ideogramjs-chromosome-visual

To link directly to the latest release, copy this snippet:
```
<script src="https://cdn.jsdelivr.net/npm/ideogram@1.48.0/dist/js/ideogram.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ideogram@1.49.0/dist/js/ideogram.min.js"></script>
```

You can also easily use the library locally:
Expand All @@ -43,7 +43,7 @@ import Ideogram from 'ideogram';
# Usage
```html
<head>
<script src="https://cdn.jsdelivr.net/npm/ideogram@1.48.0/dist/js/ideogram.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ideogram@1.49.0/dist/js/ideogram.min.js"></script>
</head>
<body>
<script>
Expand Down
2 changes: 1 addition & 1 deletion dist/js/ideogram.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/ideogram.min.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/*! Ideogram.js, version 1.48.0. Developed by Eric Weitz. https://github.com/eweitz/ideogram. Public domain (CC0 1.0). */
/*! Ideogram.js, version 1.49.0. Developed by Eric Weitz. https://github.com/eweitz/ideogram. Public domain (CC0 1.0). */
2 changes: 1 addition & 1 deletion dist/js/ideogram.min.js.map

Large diffs are not rendered by default.

Binary file added examples/vanilla/img/gene_leads_ideogram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ideogram",
"version": "1.48.0",
"version": "1.49.0",
"description": "Chromosome visualization for the web",
"main": "src/js/index.js",
"preferGlobal": true,
Expand Down
7 changes: 4 additions & 3 deletions src/js/annotations/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ function getContentAndYOffset(annot, includeLength=false) {
/**
* Optional callback, invoked before showing annotation tooltip
*/
function onWillShowAnnotTooltip(annot) {
call(this.onWillShowAnnotTooltipCallback, annot);
function onWillShowAnnotTooltip(event, context) {
call(this.onWillShowAnnotTooltipCallback, event, context);
}

function onDidShowAnnotTooltip() {
Expand All @@ -118,6 +118,7 @@ function onDidShowAnnotTooltip() {
*/
function onClickAnnot(annot) {
this.prevClickedAnnot = annot;
this.hasShownAnnotSinceClick = false;
this.onClickAnnotCallback(annot);
}

Expand Down Expand Up @@ -145,7 +146,7 @@ function showAnnotTooltip(annot, context) {
clearTimeout(ideo.hideAnnotTooltipTimeout);

if (ideo.onWillShowAnnotTooltipCallback) {
annot = ideo.onWillShowAnnotTooltipCallback(annot);
annot = ideo.onWillShowAnnotTooltipCallback(annot, context);
}

// Enable onWillShowAnnotTooltipCallback to cancel showing tooltip
Expand Down
29 changes: 22 additions & 7 deletions src/js/annotations/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ const allLabelStyle = `
stroke-linejoin: bevel;
}
#_ideogram ._ideogramLabel._ideoActive {
#_ideogram .annot ._ideogramLabel._ideoActive {
fill: #77F !important;
stroke: #F0F0FF !important;
}
#_ideogram .annot > ._ideoActive {
#_ideogram .annot > path._ideoActive {
stroke: #D0D0DD !important;
stroke-width: 1.5px;
}
#_ideogram ._ideogramLabel {
#_ideogram .annot ._ideogramLabel {
stroke: white;
stroke-width: 5px;
stroke-linejoin: round;
Expand Down Expand Up @@ -59,6 +59,10 @@ function triggerAnnotEvent(event, ideo) {
const annotElement = target.parentElement;
labelId = 'ideogramLabel_' + annotElement.id;
annotId = annotElement.id;

if (targetClasses.includes('_ideogramLabelRect')) {
d3.select('#' + annotId + ' path').dispatch(type);
}
}

if (type === 'mouseout') {
Expand Down Expand Up @@ -96,15 +100,26 @@ function renderLabel(annot, style, ideo) {

fill = ensureContrast(fill);

d3.select('#_ideogram').append('text')
const translate = `translate(-${style.width + 9},${style.height/2 - 1.5})`;
d3.select('#' + annot.domId).append('text')
.attr('id', id)
.attr('class', '_ideogramLabel')
.attr('x', style.left)
.attr('y', style.top)
.attr('transform', `rotate(-90) ${translate}`)
.style('font', font)
.style('fill', fill)
.style('pointer-events', null) // Prevent bug in clicking chromosome
.html(annot.name);

const paralogNeighborhoodMargin = 10;
const rectWidth = style.width + paralogNeighborhoodMargin;
const rectTranslate = `translate(-${rectWidth}, -${style.height/2})`;

d3.select('#' + annot.domId).append('rect')
.attr('class', '_ideogramLabelRect')
.attr('transform', `rotate(-90) ${rectTranslate}`)
.attr('width', style.width + 10)
.attr('height', style.height)
.attr('style', 'opacity: 0');
}

/** Get annotation object by name, e.g. "BRCA1" */
Expand Down Expand Up @@ -445,7 +460,7 @@ function fillAnnotLabels(sortedAnnots=[], numLabels=10) {
ideo.addAnnotLabel(annot.name);
});

d3.selectAll('._ideogramLabel, .annot')
d3.selectAll('.annot')
.on('mouseover', (event) => triggerAnnotEvent(event))
.on('mouseout', (event) => triggerAnnotEvent(event, ideo))
.on('click', (event) => triggerAnnotEvent(event));
Expand Down
67 changes: 43 additions & 24 deletions src/js/kit/related-genes.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,36 +473,48 @@ function fetchGenesFromCache(names, type, ideo) {
const locusMap = isSymbol ? cache.lociByName : cache.lociById;
const nameMap = isSymbol ? cache.idsByName : cache.namesById;

const ensemblGeneIdRegex = /ENS[A-Z]{0,3}G\d{11}/;

const hits = names.map(name => {

const nameLc = name.toLowerCase();
let isSynonym = false;
let synonym = null;

if (
!locusMap[name] &&
!cache.nameCaseMap[nameLc] &&
!getGeneBySynonym(name, ideo)
) {
if (isSymbol) {
throwGeneNotFound(name, ideo);
} else {
return;
}
if (ensemblGeneIdRegex.test(name)) {
// Omit version if given Ensembl gene ID + version, e.g.
// ENSG00000010404.11 -> ENSG00000010404
name = name.split('.')[0];
}
const isIdentifier = name in cache.namesById;
if (isIdentifier && isSymbol) {
name = cache.namesById[name];
} else {
const nameLc = name.toLowerCase();

let isSynonym = false;
let synonym = null;
if (
!locusMap[name] &&
!cache.nameCaseMap[nameLc] &&
!getGeneBySynonym(name, ideo)
) {
if (isSymbol) {
throwGeneNotFound(name, ideo);
} else {
return;
}
}

// Canonicalize name if it is mistaken in upstream data source.
// This can sometimes happen in WikiPathways, e.g. when searching
// interactions for rat Pten, it includes a result for "PIK3CA".
// In that case, this would correct PIK3CA to be Pik3ca.
if (isSymbol && !locusMap[name]) {
if (cache.nameCaseMap[nameLc]) {
name = cache.nameCaseMap[nameLc];
} else {
synonym = name;
name = getGeneBySynonym(synonym, ideo);
isSynonym = true;
// Canonicalize name if it is mistaken in upstream data source.
// This can sometimes happen in WikiPathways, e.g. when searching
// interactions for rat Pten, it includes a result for "PIK3CA".
// In that case, this would correct PIK3CA to be Pik3ca.
if (isSymbol && !locusMap[name]) {
if (cache.nameCaseMap[nameLc]) {
name = cache.nameCaseMap[nameLc];
} else {
synonym = name;
name = getGeneBySynonym(synonym, ideo);
isSynonym = true;
}
}
}

Expand All @@ -522,6 +534,7 @@ function fetchGenesFromCache(names, type, ideo) {
ensemblgene: ensemblId
},
isSynonym,
isIdentifier,
synonym
};

Expand Down Expand Up @@ -1792,12 +1805,18 @@ function decorateAnnot(annot) {
const ideo = this;
if (
annot.name === ideo.prevClickedAnnot?.name &&
annot.name === ideo.prevShownAnnot?.name &&
!ideo.hasShownAnnotSinceClick &&
ideo.isTooltipCooling
) {
ideo.prevShownAnnot = annot;
// Cancels showing tooltip immediately after clicking gene
return null;
}

ideo.prevShownAnnot = annot;
ideo.hasShownAnnotSinceClick = true;

let descObj = ideo.annotDescriptions.annots[annot.name];

if (ideo.config.relatedGenesMode === 'related') {
Expand Down
2 changes: 1 addition & 1 deletion src/js/version.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var version = '1.48.0';
var version = '1.49.0';
export default version;
Loading

0 comments on commit 77247f0

Please sign in to comment.