• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eweitz / ideogram / 12131714885

03 Dec 2024 02:21AM UTC coverage: 82.273% (-1.1%) from 83.356%
12131714885

push

github

web-flow
Merge pull request #375 from eweitz/smooth-repeat-hover

Avoid hiding tooltip on first hover of previous clicked annotation

2359 of 3225 branches covered (73.15%)

Branch coverage included in aggregate %.

10 of 15 new or added lines in 3 files covered. (66.67%)

455 existing lines in 18 files now uncovered.

5410 of 6218 relevant lines covered (87.01%)

27653.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/src/js/init/write-container.js
1
import {d3} from '../lib';
2
import {Ploidy} from '../ploidy';
3
import {getLayout} from '../layouts/layout-adapter';
4

5
/**
6
 * If ploidy description is a string, then convert it to the canonical
7
 * array format.  String ploidyDesc is used when depicting e.g. parental
8
 * origin each member of chromosome pair in a human genome.
9
 * See ploidy-basic.html for usage example.
10
 */
11
function setPloidy(ideo) {
12
  if (
88✔
13
    'ploidyDesc' in ideo.config &&
92✔
14
    typeof ideo.config.ploidyDesc === 'string'
15
  ) {
16
    var tmp = [];
2✔
17
    for (var i = 0; i < ideo.numChromosomes; i++) {
2✔
18
      tmp.push(ideo.config.ploidyDesc);
50✔
19
    }
20
    ideo.config.ploidyDesc = tmp;
2✔
21
  }
22
  // Organism ploidy description
23
  ideo._ploidy = new Ploidy(ideo.config);
88✔
24
}
25

26
function getContainerSvgClass(ideo) {
27
  var svgClass = '';
88✔
28
  if (ideo.config.showChromosomeLabels) {
88!
29
    if (ideo.config.orientation === 'horizontal') {
88✔
30
      svgClass += 'labeledLeft ';
16✔
31
    } else {
32
      svgClass += 'labeled ';
72✔
33
    }
34
  }
35

36
  if (ideo.config.rotatable === false) {
88✔
37
    svgClass += 'no-rotate ';
20✔
38
  }
39

40
  if (
88✔
41
    ideo.config.annotationsLayout &&
102✔
42
    ideo.config.annotationsLayout === 'overlay'
43
  ) {
44
    svgClass += 'faint';
3✔
45
  }
46

47
  return svgClass;
88✔
48
}
49

50
/** Hide tooltip upon pressing "esc" on keyboard */
51
function handleEscape(event) {
52
  if (event.keyCode === 27) { // "Escape" key pressed
5!
UNCOV
53
    const tooltip = document.querySelector('#_ideogramTooltip');
×
UNCOV
54
    if (tooltip) {
×
UNCOV
55
      tooltip.style.opacity = 0;
×
56
    }
UNCOV
57
    const pathwayContainer = document.querySelector('#ideo-pathway-container');
×
UNCOV
58
    if (pathwayContainer) {
×
UNCOV
59
      pathwayContainer.remove();
×
60
    }
61
  }
62
}
63

64
/**
65
 * Write tooltip div setup with default styling.
66
 */
67
function writeTooltipContainer(ideo) {
68
  d3.select(ideo.config.container + ' #_ideogramOuterWrap').append('div')
88✔
69
    .attr('class', '_ideogramTooltip')
70
    .attr('id', '_ideogramTooltip')
71
    .style('opacity', 0)
72
    .style('position', 'fixed')
73
    .style('text-align', 'center')
74
    .style('padding', '4px')
75
    .style('font', '12px sans-serif')
76
    .style('background', 'white')
77
    .style('border', '1px solid black')
78
    .style('border-radius', '5px')
79
    .style('z-index', '1000')
80
    .style('margin-left', '-2px'); // Mitigate crowding, e.g. BRCA1 for RAD51
81

82
  document.removeEventListener('keydown', handleEscape);
88✔
83
  document.addEventListener('keydown', handleEscape);
88✔
84
}
85

86
function writeContainerDom(ideo) {
87

88
  // Remove any previous container content
89
  d3.selectAll(ideo.config.container + ' #_ideogramOuterWrap').remove();
88✔
90

91
  d3.select(ideo.config.container)
88✔
92
    .append('div')
93
    .attr('id', '_ideogramOuterWrap')
94
    .append('div')
95
    .attr('id', '_ideogramTrackLabelContainer')
96
    .style('position', 'absolute');
97

98
  d3.select(ideo.config.container + ' #_ideogramOuterWrap').append('div')
88✔
99
    .attr('id', '_ideogramMiddleWrap') // needed for overflow and scrolling
100
    .style('position', 'relative')
101
    .style('overflow-x', 'auto')
102
    .style('transform', 'translateZ(0)') // add compositing layer for ideogram
103
    .append('div')
104
    .attr('id', '_ideogramInnerWrap') // needed for overflow and scrolling
105
    .append('svg')
106
    .attr('id', '_ideogram')
107
    .attr('class', getContainerSvgClass(ideo))
108
    .attr('width', ideo._layout.getWidth())
109
    .attr('height', ideo._layout.getHeight())
110
    .html(ideo.getBandColorGradients());
111
}
112

113
/**
114
 * Writes the HTML elements that contain this ideogram instance.
115
 */
116
function writeContainer(t0) {
117
  var ideo = this;
89✔
118

119
  if (ideo.config.annotationsPath) {
89✔
120
    ideo.fetchAnnots(ideo.config.annotationsPath);
23✔
121
  }
122

123
  setPloidy(ideo);
88✔
124

125
  ideo._layout = getLayout(ideo);
88✔
126

127
  writeContainerDom(ideo);
88✔
128

129
  ideo.isOnlyIdeogram = document.querySelectorAll('#_ideogram').length === 1;
88✔
130
  writeTooltipContainer(ideo);
88✔
131
  ideo.finishInit(t0);
88✔
132
}
133

134
export {writeContainer};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc