我正在实施热图以显示所有用户使用Patrick Wied的heatmaps.js点击我的页面.Heatmap是从每个元素的"datapoints"集合加载的.但是加载需要太长时间......
问题描述:
每个数据点都有页面上HTML元素的X,Y坐标和选择器(使用selectorator.js检索).目前我每页得到大约5k点,我需要检查是否有一些元素没有隐藏,所以我们不会显示隐藏元素的热图.
目前我正在使用:
element = $(data.points[i].Element);
element.is(":hidden"))
Run Code Online (Sandbox Code Playgroud)
但这需要大约7秒来检查所有那些很长的点.我已经没有想法如何避免/优化这个问题.
数据点细节:
元素:#pageData> tbody> tr:eq(3)> td:eq(4)> a:eq(0)
Y:0.6546159
X:0.4444231
伪脚本流程描述:
FOREACH(point in allDatapoints)
{
...
calculation of some parameters needed to show on heamapat
...
if (point.element.is(":hidden"))
{
continue;
}
pointsToDisplay.push(point)
}
Run Code Online (Sandbox Code Playgroud)
我也试图获取所有隐藏元素GetSelector()的选择器,但是在selectorator.js中然后只是通过该数组,但它几乎与is(:hidden)函数相同.
我希望这是有道理的.
事实:获取元素的选择器可能需要一些时间,但是反向过程(获取和基于选择器的元素)几乎没有时间. - >所以我不能简单地发送隐藏元素的选择器数组并过滤那些会快得多的元素.
我正在尝试在我的Node Express服务器上处理POST请求以处理多部分表单上传,在我的情况下,用户正在上传图像.
我想通过我的Express应用程序将上传管道传输到另一台服务器,该应用程序当前设置为使用body解析器,我也看到它不支持多部分bodes,而是建议使用其他一些库.
我见过多方,但我不确定如何在我的客户端应用程序中使用它.
在我的客户端代码中,我发布了一个FormData对象,如下所示:
function create(data, name) {
var formData = new FormData();
formData.append('file', data, name);
return this.parentBase.one('photos').withHttpConfig({transformRequest: angular.identity}).customPOST(formData, undefined, undefined, {'Content-Type': undefined});
}
Run Code Online (Sandbox Code Playgroud)
注意:我正在使用AngularJS的Restangular库,如此处所述
因此,根据我对多方文档的理解,我必须处理表单上传事件,并在表单上传完成后再对其进行操作.
问题是,我希望我可以直接将上传管道传输到另一台服务器.事先我的客户端应用程序直接调用这个其他服务器,但我现在正试图通过Express获取所有路由,这是可能的,还是我必须使用像multiparty这样的东西?
请求文档提供了使用formData的示例,但我不确定这对于我看到的多方示例如何工作.例如,一旦使用mutliparty在Express中完成上传,那么我是否必须构造另一个formData对象然后再发出请求,或者我必须将每个部分传递给另一个服务器?
我很困惑,请有人帮我清理一下吗?
谢谢
编辑
好的,我看了一下multer跟随@yarons评论,这似乎是我想要使用的东西,我试图用我的快速路由器设置如下:
routes.js
var express = require('express'),
router = express.Router(),
customers = require('./customers.controller.js'),
multer = require('multer'),
upload = multer();
router.post('/customers/:customerId/photos/', upload.single('file'), customers.createPhoto);
Run Code Online (Sandbox Code Playgroud)
controller.js
module.exports.createPhoto = function(req, res) {
console.log(req.file);
var options = prepareCustomersAPIHeaders(req);
options.formData = req.file;
request(options).pipe(res);
};
Run Code Online (Sandbox Code Playgroud)
在上面的控制器中注销req.file属性我看到:
{ fieldname: 'file',
originalname: …Run Code Online (Sandbox Code Playgroud) 我怎样才能有一个函数接受或者命名参数(foo({a: 'hello', b: 'it is me'}))或位置参数(foo('hello', 'it is me'))?
我知道可以通过将对象传递给函数来模拟命名参数:
function foo(options) {
options = options || {};
var a = options.a || 'peanut'; // whatever default value
var b = options.b || 'butter'; // whatever default value
console.log(a, b);
}
// ES6 allows automatic destructuring
function foo({a = 'peanut', b = 'butter'} = {}) {
console.log(a, b);
}
Run Code Online (Sandbox Code Playgroud)
但这不允许我接受通过的位置论证.
我想使用ES6,但ES5的任何东西都可以.
这是一个新手问题,但我没有设法谷歌任何合理简洁但有启发性的主题.我有Sublime Text编辑器和一个优秀的插件DocBlockr https://github.com/spadgos/sublime-jsdocs,这使得正确的评论变得轻而易举.在完成评论后我该怎么做?至少,我希望能够在REPL中调用注释.还有哪些文档明智?对于中等脚本,我想要轻量级和简单的东西.
编辑:
var helper = exports.helper = (function() {
...
/**
* Reduces a sequence of names to initials.
* @param {String} name Space Delimited sequence of names.
* @param {String} sep A period separating the initials.
* @param {String} trail A period ending the initials.
* @param {String} hyph A hypen separating double names.
* @return {String} Properly formatted initials.
*/
function makeInits(name, sep, trail, hyph) {
function splitBySpace(nm) {
return nm.trim().split(/\s+/).map(function(x) {return …Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习J-Query,我正在尝试在我的网页中实现一个简单的点击事件,当你点击一个按钮时它将打开mobile-nav.
当我选择标题时,此按钮有效,例如它会隐藏标题,但不会显示mobile-nav?
ps我正在复制DICE主页仅用于学习目的,因为我知道我正在使用受版权保护的媒体;).
我认为这可能与我隐藏移动导航在我CSS所以J-query无法toogle /显示它.
@media screen and (max-width: 1024px) {
nav{
justify-content: space-around;
}
.bars{
display:block;
width: 50px;
height: 100px;
cursor: pointer;
}
ul{
display: none !important;
}
.mobile-nav{
display: none;
position:absolute;
z-index: 3;
left:-110px;
top:70px;
width: 100%;
height: 100%;
opacity: 0.8;
background-color:black;
}
.mobile-nav li{
height: 50px;
}
.mobile-nav a{
font-size: 2rem;
font-weight: 700;
}
}Run Code Online (Sandbox Code Playgroud)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Dice</title>
<meta name="description" content="">
<meta name="author" …Run Code Online (Sandbox Code Playgroud)我想在画布上相应地显示一些图像到屏幕尺寸而不会丢失图像分辨率.
如果我使用简单的png或jpeg,我会看到在大屏幕上像素化的图像.
我在想的是使用svg文件并在janvas上显示它们.有可能吗?(我尝试使用Apache Batik而没有可能的结果)
如果这是不可能的,你能想到其他任何选择吗?
下面是我的form.jsx文件
var React = require('react');
var Input = require('./input');
module.exports = React.createClass({
getInitialState: function() {
return {
focus: false
}
},
render: function () {
return <div className="info_input">
<div className="demo demo2 lll">
<div className={"css " + (this.state.focus ? "active" : "")}>
<label htmlFor="d3">{this.props.firstCol}</label>
<Input id="d3" type="text" handleFocus={this.addClass} handleBlur={this.removeClass} />
</div>
</div>
<div className="demo demo2">
<div className={"css " + (this.state.focus ? "active" : "")}>
<label htmlFor="d3">{this.props.secondCol}</label>
<Input id="d3" type="text" />
</div>
</div>
<div className="clear"></div>
</div>
},
addClass: function () {
this.setState({ …Run Code Online (Sandbox Code Playgroud) 不知道这个问题有没有得到解答。至少我没有找到答案。
所以这是一件事:我正在 Android 上制作一些以太空为主题的 2D 游戏,并且我正在屏幕尺寸 = 2560x1600 的模拟器上测试它。在这个游戏中有一个太空飞船正在飞行的场地。当然,它(一个字段)必须具有高分辨率的美丽背景。我的背景图像的分辨率是 4500x4500。我想让我的图像相对于相机运动向相反的方向移动,所以这就是为什么我不能使用小静态图像。此时该图像仅可见一部分:
当我尝试绘制它时,我得到 fps = 1-2 (当然,由于图像大小,它很低):
canvas.drawBitmap(getBigImage(), -x, -y, null);
/* getBigImage() method does nothing but returning
a Bitmap object (no calculation or decoding is performing in there) */
Run Code Online (Sandbox Code Playgroud)
我尝试从大图像中剪切出所需的图像,但 fps 仍然很低:
Bitmap b = Bitmap.createBitmap(getBigImage(), x, y, sw, sh);
canvas.drawBitmap(b, 0, 0, null);
Run Code Online (Sandbox Code Playgroud)
我怎样才能以高帧率绘制这个大位图?
我想在没有新的内存分配和复制的情况下在C或C++中连接2个字符串.可能吗?
可能的C代码:
char* str1 = (char*)malloc(100);
char* str2 = (char*)malloc(50);
char* str3 = /* some code that concatenates these 2 strings
without copying to occupy a continuous memory region */
Run Code Online (Sandbox Code Playgroud)
然后,当我不再需要它们时,我只是这样做:
free(str1);
free(str2);
Run Code Online (Sandbox Code Playgroud)
或者如果可能的话,我想在C++中实现相同的功能,使用std::string或者可能char*,但是在str3上使用new和delete(可能是void operator delete ( void* ptr, std::size_t sz )运算符(C++ 14)).
关于字符串连接有很多问题,但我没有找到一个问相同的问题.