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

Add println and printf to LogRenderer

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