Spaces:
Running
Running
Julien Chaumond
commited on
Commit
·
e4685f5
1
Parent(s):
001aa75
Checkpoint 4
Browse files- index.html +3 -1
- js-src/coref.ts +16 -2
- js-src/zController.ts +6 -4
- less/style.less +12 -1
index.html
CHANGED
@@ -38,7 +38,9 @@
|
|
38 |
</div>
|
39 |
</div>
|
40 |
|
41 |
-
<div class="container">
|
|
|
|
|
42 |
</div>
|
43 |
|
44 |
<script src="/dist/script.js"></script>
|
|
|
38 |
</div>
|
39 |
</div>
|
40 |
|
41 |
+
<div class="container-wrapper">
|
42 |
+
<svg class="svg-container"></svg>
|
43 |
+
<div class="container"></div>
|
44 |
</div>
|
45 |
|
46 |
<script src="/dist/script.js"></script>
|
js-src/coref.ts
CHANGED
@@ -32,6 +32,7 @@ class Coref {
|
|
32 |
onStart = () => {};
|
33 |
onSuccess = () => {};
|
34 |
container?: HTMLElement;
|
|
|
35 |
|
36 |
constructor(endpoint: string, opts: any) {
|
37 |
this.endpoint = endpoint;
|
@@ -41,6 +42,14 @@ class Coref {
|
|
41 |
if (opts.onSuccess) {
|
42 |
(<any>this).onSuccess = opts.onSuccess;
|
43 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
}
|
45 |
|
46 |
parse(text: string) {
|
@@ -69,8 +78,13 @@ class Coref {
|
|
69 |
m.singleScore = res.singleScores[m.index] || undefined;
|
70 |
}
|
71 |
const markup = Displacy.render(res.cleanedText, mentions);
|
72 |
-
if (!this.container) { return ; }
|
73 |
-
|
74 |
this.container.innerHTML = `<div class="text">${markup}</div>`;
|
|
|
|
|
|
|
|
|
|
|
75 |
}
|
76 |
}
|
|
|
32 |
onStart = () => {};
|
33 |
onSuccess = () => {};
|
34 |
container?: HTMLElement;
|
35 |
+
svgContainer?: SVGSVGElement;
|
36 |
|
37 |
constructor(endpoint: string, opts: any) {
|
38 |
this.endpoint = endpoint;
|
|
|
42 |
if (opts.onSuccess) {
|
43 |
(<any>this).onSuccess = opts.onSuccess;
|
44 |
}
|
45 |
+
|
46 |
+
window.addEventListener('resize', this.svgResize);
|
47 |
+
}
|
48 |
+
|
49 |
+
svgResize() {
|
50 |
+
if (!this.container || !this.svgContainer) { return ; }
|
51 |
+
this.svgContainer.setAttribute('width', `${this.container.scrollWidth}`); /// Caution: not offsetWidth.
|
52 |
+
this.svgContainer.setAttribute('height', `${this.container.scrollHeight}`);
|
53 |
}
|
54 |
|
55 |
parse(text: string) {
|
|
|
78 |
m.singleScore = res.singleScores[m.index] || undefined;
|
79 |
}
|
80 |
const markup = Displacy.render(res.cleanedText, mentions);
|
81 |
+
if (!this.container || !this.svgContainer) { return ; }
|
82 |
+
|
83 |
this.container.innerHTML = `<div class="text">${markup}</div>`;
|
84 |
+
/// SVG
|
85 |
+
this.svgResize();
|
86 |
+
// this.svgContainer.width = this.container
|
87 |
+
window.container = this.container;
|
88 |
+
window.svgContainer = this.svgContainer;
|
89 |
}
|
90 |
}
|
js-src/zController.ts
CHANGED
@@ -33,10 +33,12 @@ const updateURL = (text) => {
|
|
33 |
}
|
34 |
|
35 |
document.addEventListener('DOMContentLoaded', () => {
|
36 |
-
const $input
|
37 |
-
const $form
|
38 |
-
const $checkbox
|
39 |
-
|
|
|
|
|
40 |
|
41 |
{
|
42 |
// Initial text
|
|
|
33 |
}
|
34 |
|
35 |
document.addEventListener('DOMContentLoaded', () => {
|
36 |
+
const $input = document.querySelector('input.input-message') as HTMLInputElement;
|
37 |
+
const $form = document.querySelector('form.js-form') as HTMLFormElement;
|
38 |
+
const $checkbox = document.querySelector('.js-checkbox') as HTMLElement;
|
39 |
+
const $svgContainer = document.querySelector('.svg-container') as SVGSVGElement;
|
40 |
+
coref.container = document.querySelector('.container') as HTMLElement;
|
41 |
+
coref.svgContainer = $svgContainer;
|
42 |
|
43 |
{
|
44 |
// Initial text
|
less/style.less
CHANGED
@@ -84,9 +84,13 @@ code, pre {
|
|
84 |
}
|
85 |
}
|
86 |
|
|
|
|
|
|
|
|
|
|
|
87 |
.container {
|
88 |
font-size: 20px;
|
89 |
-
overflow-x: auto;
|
90 |
white-space: nowrap;
|
91 |
padding: 180px 40px;
|
92 |
mark {
|
@@ -114,6 +118,13 @@ body.debug {
|
|
114 |
}
|
115 |
}
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
/**
|
118 |
* Elements from Displacy
|
119 |
*/
|
|
|
84 |
}
|
85 |
}
|
86 |
|
87 |
+
.container-wrapper {
|
88 |
+
overflow-x: auto;
|
89 |
+
position: relative;
|
90 |
+
}
|
91 |
+
|
92 |
.container {
|
93 |
font-size: 20px;
|
|
|
94 |
white-space: nowrap;
|
95 |
padding: 180px 40px;
|
96 |
mark {
|
|
|
118 |
}
|
119 |
}
|
120 |
|
121 |
+
.svg-container {
|
122 |
+
position: absolute;
|
123 |
+
top: 0; left: 0; right: 0; bottom: 0;
|
124 |
+
z-index: -1;
|
125 |
+
background-color: pink;
|
126 |
+
}
|
127 |
+
|
128 |
/**
|
129 |
* Elements from Displacy
|
130 |
*/
|