47 | {tokens.map(({ token, strength, normalized_strength }, i) => {
48 | const color = getInterpolatedColor(colors, boundaries, normalized_strength || strength);
49 | return
57 | {token}
58 |
59 | })}
60 |
61 | >
62 | )
63 | }
64 |
65 | export function SimulationSequences({ sequences, simulated_sequences, overlay_activations, colors = DEFAULT_COLORS, boundaries = DEFAULT_BOUNDARIES }) {
66 | if (overlay_activations) {
67 | return <>
68 | {
69 | sequences.map((tokens, i) => {
70 | let simulated_tokens = simulated_sequences[i];
71 | return (
72 |
73 | {tokens.map(({ token, strength, normalized_strength }, j) => {
74 | const { token: simulated_token, strength: simulated_strength, normalized_strength: simulated_normalized_strength } = simulated_tokens[j];
75 | if (simulated_token !== token) {
76 | throw new Error('simulated tokens not matching')
77 | }
78 | const color = getInterpolatedColor(colors, boundaries, normalized_strength || strength);
79 | const simcolor = getInterpolatedColor(colors, boundaries, simulated_normalized_strength || simulated_strength);
80 |
81 | return
82 |
83 | {token}
91 | {token}
98 |
99 |
100 | })}
101 |
102 | )
103 | })
104 | }
105 | >
106 | }
107 | return
108 |
109 |
Real activations:
115 | {
116 | sequences.map((tokens, i) =>
117 |
118 | {tokens.map(({ token, strength, normalized_strength }, j) => {
119 | const color = getInterpolatedColor(colors, boundaries, normalized_strength || strength);
120 | return {token}
128 | })}
129 |
130 | )
131 | }
132 |
133 |
134 |
Simulated activations:
140 | {
141 | simulated_sequences.map((simulated_tokens, i) =>
142 |
143 | {simulated_tokens.map(({ token, strength, normalized_strength }, j) => {
144 | const color = getInterpolatedColor(colors, boundaries, normalized_strength || strength);
145 | return {token}
153 | })}
154 |
155 | )
156 | }
157 |
158 |
159 | }
160 |
161 |
162 |
--------------------------------------------------------------------------------
/src/components/ui.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "lodash";
2 | import React from "react";
3 |
4 | export class HoverZoom extends React.Component {
5 | state = {
6 | isActive: false,
7 | isBig: false,
8 | width: undefined,
9 | height: undefined,
10 | };
11 |
12 | onRef = (el) => {
13 | if (!el) {
14 | return;
15 | }
16 | const { width, height } = el.getBoundingClientRect();
17 | if (!width || !height) return;
18 | this.setState({ width, height });
19 | };
20 |
21 | render() {
22 | const { width, height } = this.state;
23 | let {
24 | scale = 2,
25 | isPointer = undefined,
26 | children,
27 | isActive,
28 | allowClick = false,
29 | onExpand,
30 | ...props
31 | } = this.props;
32 |
33 | if (!props.onMouseEnter) {
34 | props.onMouseEnter = () => {
35 | this.setState({ isActive: true });
36 | onExpand && onExpand();
37 | };
38 | }
39 |
40 | if (!props.onMouseLeave) {
41 | props.onMouseLeave = () => {
42 | this.setState({ isActive: false });
43 | };
44 | }
45 |
46 | const activeVal =
47 | typeof isActive !== "undefined" ? isActive : this.state.isActive;
48 |
49 | const activeWidth = this.props.width || width;
50 | const activeHeight = this.props.height || height;
51 |
52 | return (
53 |
148 | {isFunction(children) ? children(isHovering) : children}
149 |
150 | );
151 | }
152 | }
153 |
154 | export const Placeholder = ({ figure = "", children }) => {
155 | return (
156 |