Words now interpolate along bezier curve between points instead of only at exact positions
Browse files- static/index.html +36 -5
static/index.html
CHANGED
|
@@ -440,14 +440,45 @@
|
|
| 440 |
const emotionData = {};
|
| 441 |
|
| 442 |
if (entry.emotional_flow && entry.emotional_flow.length > 0) {
|
|
|
|
| 443 |
entry.emotional_flow.forEach(flow => {
|
| 444 |
const color = getColorForEmotion(flow.label);
|
| 445 |
-
flow.curves.
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
}
|
| 450 |
-
}
|
| 451 |
});
|
| 452 |
}
|
| 453 |
|
|
|
|
| 440 |
const emotionData = {};
|
| 441 |
|
| 442 |
if (entry.emotional_flow && entry.emotional_flow.length > 0) {
|
| 443 |
+
const maxWordIdx = words.length - 1;
|
| 444 |
entry.emotional_flow.forEach(flow => {
|
| 445 |
const color = getColorForEmotion(flow.label);
|
| 446 |
+
const sorted = [...flow.curves].sort((a, b) => a.start_word - b.start_word);
|
| 447 |
+
if (sorted.length === 0) return;
|
| 448 |
+
|
| 449 |
+
// Bezier interpolation between consecutive curves
|
| 450 |
+
for (let i = 0; i < sorted.length; i++) {
|
| 451 |
+
const curve = sorted[i];
|
| 452 |
+
const end = Math.min(curve.end_word, maxWordIdx);
|
| 453 |
+
|
| 454 |
+
if (i < sorted.length - 1) {
|
| 455 |
+
const next = sorted[i + 1];
|
| 456 |
+
const interpEnd = Math.min(next.start_word, end);
|
| 457 |
+
|
| 458 |
+
for (let w = curve.start_word; w <= interpEnd; w++) {
|
| 459 |
+
const t = (next.start_word === curve.start_word) ? 0
|
| 460 |
+
: (w - curve.start_word) / (next.start_word - curve.start_word);
|
| 461 |
+
const u = 1 - t;
|
| 462 |
+
const intensity = u*u*u*curve.peak_intensity
|
| 463 |
+
+ 3*u*u*t*curve.peak_intensity
|
| 464 |
+
+ 3*u*t*t*next.peak_intensity
|
| 465 |
+
+ t*t*t*next.peak_intensity;
|
| 466 |
+
if (!emotionData[w]) emotionData[w] = [];
|
| 467 |
+
emotionData[w].push({ label: flow.label, intensity, color });
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
// Flat tail beyond next start_word until this curve's end_word
|
| 471 |
+
for (let w = Math.max(interpEnd + 1, curve.start_word); w <= end; w++) {
|
| 472 |
+
if (!emotionData[w]) emotionData[w] = [];
|
| 473 |
+
emotionData[w].push({ label: flow.label, intensity: curve.peak_intensity, color });
|
| 474 |
+
}
|
| 475 |
+
} else {
|
| 476 |
+
for (let w = curve.start_word; w <= end; w++) {
|
| 477 |
+
if (!emotionData[w]) emotionData[w] = [];
|
| 478 |
+
emotionData[w].push({ label: flow.label, intensity: curve.peak_intensity, color });
|
| 479 |
+
}
|
| 480 |
}
|
| 481 |
+
}
|
| 482 |
});
|
| 483 |
}
|
| 484 |
|