我使用以下示例作为基础,并希望使其成为动态词云 https://github.com/jasondavies/d3-cloud
数据被添加到数组中,但我的word-cloud没有反映新添加的单词:
<script>
var fill = d3.scale.category20();
var data = [{word:"Hello",weight:20},{word:"World",weight:10},{word:"Normally",weight:25},{word:"You",weight:15},{word:"Want",weight:30},{word:"More",weight:12},{word:"Words",weight:8},{word:"But",weight:18},{word:"Who",weight:22},{word:"Cares",weight:27}];
d3.layout.cloud().size([500, 500])
.words(data.map(function(d) {
return {text: d.word, size: d.weight};
}))
.padding(5)
.rotate(function() { return ~~(Math.random() * 2) * 90; })
.font("Impact")
.fontSize(function(d) { return d.size; })
.on("end", draw)
.start();
function draw(words) {
d3.select("body").append("svg")
.attr("width", 300)
.attr("height", 300)
.append("g")
.attr("transform", "translate(150,150)")
.selectAll("text")
.data(words)
.enter().append("text")
.style("font-size", function(d) { return d.size + "px"; })
.style("font-family", "Impact")
.style("fill", function(d, i) { return fill(i); })
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + …Run Code Online (Sandbox Code Playgroud) 我正在尝试将用户登录模块添加到 node.js 中的现有应用程序。它为每个模块使用单独的路由文件,并使用一个主路由文件来使用最终在 server.js 中使用的所有子路由。这是我的应用程序代码和结构:
app
views
user
index.ejs
login.ejs
signup.ejs
profile.ejs
routes
docs
index.js
user
index.js
index.js
config
passport.js
server.js
Run Code Online (Sandbox Code Playgroud)
服务器.js
const express = require('express')
const app = express()
const path = require('path')
const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')
const passport = require('passport')
const flash = require('connect-flash')
const session = require('express-session')
const routes = require('./routes/')
const port = process.env.PORT || 3000;
app.use(express.static(path.join(__dirname, 'public')));
require('./config/passport')(passport);
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(cookieParser());
app.use(bodyParser.json());
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(session({ …Run Code Online (Sandbox Code Playgroud) d3.js ×1
dynamic ×1
express ×1
javascript ×1
json ×1
node.js ×1
passport.js ×1
routing ×1
word-cloud ×1