提交 71591c63 编写于 作者: J Jason Park

Add println and printf to LogRenderer

上级 837fd3e3
...@@ -469,6 +469,14 @@ ...@@ -469,6 +469,14 @@
"dev": true, "dev": true,
"requires": { "requires": {
"sprintf-js": "~1.0.2" "sprintf-js": "~1.0.2"
},
"dependencies": {
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
"dev": true
}
} }
}, },
"aria-query": { "aria-query": {
...@@ -11670,9 +11678,9 @@ ...@@ -11670,9 +11678,9 @@
} }
}, },
"sprintf-js": { "sprintf-js": {
"version": "1.0.3", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==",
"dev": true "dev": true
}, },
"squeak": { "squeak": {
......
...@@ -19,7 +19,9 @@ ...@@ -19,7 +19,9 @@
}, },
"keywords": [ "keywords": [
"algorithm", "algorithm",
"visualizer" "data-structure",
"visualization",
"animation"
], ],
"author": { "author": {
"name": "Jinseo Jason Park", "name": "Jinseo Jason Park",
...@@ -94,6 +96,7 @@ ...@@ -94,6 +96,7 @@
"remove-markdown": "^0.3.0", "remove-markdown": "^0.3.0",
"sass-loader": "^7.0.3", "sass-loader": "^7.0.3",
"screenfull": "^3.3.2", "screenfull": "^3.3.2",
"sprintf-js": "^1.1.2",
"style-loader": "^0.21.0", "style-loader": "^0.21.0",
"uglifyjs-webpack-plugin": "^1.2.4", "uglifyjs-webpack-plugin": "^1.2.4",
"webpack": "^4.5.0", "webpack": "^4.5.0",
......
const process = { env: { ALGORITHM_VISUALIZER: '1' } }; const process = { env: { ALGORITHM_VISUALIZER: '1' } };
importScripts('https://unpkg.com/algorithm-visualizer/dist/algorithm-visualizer.js'); importScripts('https://unpkg.com/algorithm-visualizer@latest/dist/algorithm-visualizer.js');
importScripts('https://unpkg.com/babel-standalone@6/babel.min.js'); importScripts('https://unpkg.com/babel-standalone@6/babel.min.js');
const sandbox = code => { const sandbox = code => {
......
...@@ -231,7 +231,7 @@ class GraphData extends Data { ...@@ -231,7 +231,7 @@ class GraphData extends Data {
if (weight !== undefined) node.weight = weight; if (weight !== undefined) node.weight = weight;
node.visitedCount += visit ? 1 : -1; node.visitedCount += visit ? 1 : -1;
if (this.logData) { if (this.logData) {
this.logData.print(visit ? (source || '') + ' -> ' + target : (source || '') + ' <- ' + target); this.logData.println(visit ? (source || '') + ' -> ' + target : (source || '') + ' <- ' + target);
} }
} }
...@@ -249,7 +249,7 @@ class GraphData extends Data { ...@@ -249,7 +249,7 @@ class GraphData extends Data {
const node = this.findNode(target); const node = this.findNode(target);
node.selectedCount += select ? 1 : -1; node.selectedCount += select ? 1 : -1;
if (this.logData) { if (this.logData) {
this.logData.print(select ? (source || '') + ' => ' + target : (source || '') + ' <= ' + target); this.logData.println(select ? (source || '') + ' => ' + target : (source || '') + ' <= ' + target);
} }
} }
......
import { sprintf } from 'sprintf-js';
import { Data } from '/core/datas'; import { Data } from '/core/datas';
import { LogRenderer } from '/core/renderers'; import { LogRenderer } from '/core/renderers';
...@@ -6,13 +7,21 @@ class LogData extends Data { ...@@ -6,13 +7,21 @@ class LogData extends Data {
return LogRenderer; return LogRenderer;
} }
set(messages = []) { set(log = '') {
this.messages = messages; this.log = log;
super.set(); super.set();
} }
print(message) { print(message) {
this.messages.push(message); this.log += message;
}
println(message) {
this.print(message + '\n');
}
printf(format, ...args) {
this.print(sprintf(format, ...args));
} }
} }
......
...@@ -11,21 +11,15 @@ class LogRenderer extends Renderer { ...@@ -11,21 +11,15 @@ class LogRenderer extends Renderer {
componentDidUpdate(prevProps, prevState, snapshot) { componentDidUpdate(prevProps, prevState, snapshot) {
super.componentDidUpdate(prevProps, prevState, snapshot); super.componentDidUpdate(prevProps, prevState, snapshot);
const { lastChild } = this.element.current; const div = this.element.current;
if (lastChild) lastChild.scrollIntoView(); div.scrollTop = div.scrollHeight;
} }
renderData() { renderData() {
const { messages } = this.props.data; const { log } = this.props.data;
return ( return (
<div className={styles.log} ref={this.element}> <div className={styles.log} ref={this.element} dangerouslySetInnerHTML={{ __html: log }} />
{
messages.map((message, i) => (
<span className={styles.message} key={i} dangerouslySetInnerHTML={{ __html: message }} />
))
}
</div>
); );
} }
} }
......
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
flex-direction: column; flex-direction: column;
overflow-y: auto; overflow-y: auto;
font-family: $font-family-monospace; font-family: $font-family-monospace;
white-space: pre-wrap;
.message { line-height: 1.6;
margin: 2px 0; }
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册