小编max*_*022的帖子

如何使用d3.js更新轴

我试图在图表上显示不同的数据.用户可以单击单选按钮更改显示的数据.我正在使用"气泡图"来渲染数据.

对于每种类型的数据,我需要更新Yaxis(域不同).这就是我现在所做的:

图表初始化

var svg = d3.select("body .main-content").append("svg")
    .attr("class", "chart")
    .attr("width", width)
    .attr("height", height);
Run Code Online (Sandbox Code Playgroud)

初始化轴

initAxis();
function initAxis()
{
    var y = d3.scale.linear().domain([0,1000]).range([height-margin, margin]).nice(),
        x = d3.scale.linear().domain([0,23]).range([margin,width-margin]),
        yAxis = d3.svg.axis().scale(y).orient("left"),
        xAxis = d3.svg.axis().scale(x).orient("bottom");

    svg.append("g")
        .attr("class", "y axis")
        .attr("transform", "translate(" + margin + ",0)")
        .call(yAxis);

    svg.append("g")
        .attr("class", "x axis")
        .attr("transform", "translate(0," + (height - margin) + ")")
        .call(xAxis);
}
Run Code Online (Sandbox Code Playgroud)

更新图表

    function update(type)
    {
        // Get the data
        type = type || 'default';
        var m = max[type],
            mi = min[type]+0.1,
            data = …
Run Code Online (Sandbox Code Playgroud)

d3.js

48
推荐指数
2
解决办法
4万
查看次数

根据路径方向更改Google地图标记方向

我想知道是否可以根据地图上绘制的路径更改标记方向.这是一个例子:

在此输入图像描述

正如您所看到的那样,标记是一辆汽车(带前保险杠和尾灯).我想让汽车朝着路径方向前进(在这个例子中,汽车将向右转45度).

我正在使用DirectionsService绘制路径,我有一个随机数点.有时只有一个,有时10点.我在绘制路径之前添加标记.以下是我绘制路径的方法:

// Intialize the Path Array
var path = new google.maps.MVCArray();

// Intialise the Direction Service
var service = new google.maps.DirectionsService();

// Set the Path Stroke Color
var poly = new google.maps.Polyline({ map: gmap, strokeColor: '#dd0000' }); // #4986E7

// Draw the path for this vehicle
for (var i = 0; i < pathPoints.length; i++) {
    if ((i + 1) < pathPoints.length) {
        var src = pathPoints[i];
        var des = pathPoints[i + 1];
        path.push(src);
        poly.setPath(path);
        service.route({ …
Run Code Online (Sandbox Code Playgroud)

google-maps google-maps-markers google-directions-api

29
推荐指数
1
解决办法
3万
查看次数

Redis如何存储关联数组?设置或哈希还是列表?

我对Redis的所有可用存储选项感到困惑.我想做一些简单的事情,我不想过度设计它.我正phpredis和我一起工作Redis v2.8.6.

我有这个简单的关联数组,我需要存储.我还需要能够通过其键检索项目并循环遍历所有项目.

$a = array(
    '12345' => array(
        'name' => 'Post A',
        'val2' => 'blah blah',
        'val3' => 'blah blah blah',
    ),
    '54321' => array(
        'name' => 'Post B',
        'val2' => 'blah blah',
        'val3' => 'blah blah blah',
    ),
    '998877' => array(
        'name' => 'Post C',
        'val2' => 'blah blah',
        'val3' => 'blah blah blah',
    )
);
Run Code Online (Sandbox Code Playgroud)

所以我到现在所做的是使用hash类型.像这样存储我的数组:

foreach ($a as $key => $value) {
    $this->redis->hSet('posts', $key, json_encode($value));
}
Run Code Online (Sandbox Code Playgroud)

就像我可以轻松地像这样访问密钥:

public function getPost($postId) …
Run Code Online (Sandbox Code Playgroud)

associative-array redis phpredis

28
推荐指数
3
解决办法
4万
查看次数

如何在backbone.js中创建基本视图?

我需要创建一个基本视图,我的所有视图都将扩展.我不确定在何时何地宣布这个观点.

基本上,我需要注入global variables我的所有模板,而不是在每个render()方法中都这样做.

这是我现在的树形结构:

|-main.js
|-app.js
|-require.js
|-App
|  |-View
|  |   |-Dashboard.js
|  |   |-Header.js
|  |   |-Content.js
|  |-Model
|  |-Collection
|  |-Template
|
|-Libs
   |-...
Run Code Online (Sandbox Code Playgroud)

这是我的app.js

var App = {
    ApiURL: "http://domain.local",
    View: {},
    Model: {},
    Collection: {},
    Registry: {},
    Router: null
};

define(['backbone', 'View/Dashboard'], function(Backbone){
    var AppRouter = Backbone.Router.extend({
        routes : {
            "dashboard": "index",
        },

        index: function() {
            console.log('routing index route...');
            var x = new App.View.Dashboard({el:$('#main-content'), type:'other'});
        }
    });

    var initialize = …
Run Code Online (Sandbox Code Playgroud)

extends backbone.js backbone-views

9
推荐指数
1
解决办法
5291
查看次数

socket.io握手返回错误"传输未知"

我正在尝试使用elephant.io将事件从我的PHP脚本发送到我的nodejs服务器.使用此库执行测试我注意到握手没有按预期发生.

阅读了有关 socket.io的客户端 - 服务器握手的规范之后,我测试了一个简单的握手请求到我的nodejs服务器:

POST "http://acme.local:3700/socket.io/1"
Run Code Online (Sandbox Code Playgroud)

但是这会返回以下JSON消息:

{
    "code": 0,
    "message": "Transport unknown"
}
Run Code Online (Sandbox Code Playgroud)

我不确定这个错误是由于我正在使用的socket.io版本(v1.0.2)还是握手请求只是格式错误.

handshake socket.io

9
推荐指数
2
解决办法
1万
查看次数

RequireJS + AngularJS + Module:依赖性问题

我在本地安装了angularjs应用程序,一切正常,直到我将代码上传到登台服务器.我现在遇到了不受尊重的依赖项问题,但我不明白为什么.我想这是在本地工作,因为它加载了更快的库.我现在修改了我的应用程序以尝试解决此问题,但无法设法使其工作.

我的应用程序加载一个页面的应用程序中,3次组成(main,mapmap-data).我正在使用AngularJS模块结构来启动这个应用程序.这是我的目录结构:

在此输入图像描述

index.html是非常基本的:

<!DOCTYPE HTML>
<html lang="en-US">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, minimum-scale=1.0" />
        <title>Map Application</title>
        <link rel="icon" sizes="16x16" href="/favicon.ico" />

        <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key={{ map_key }}&sensor=false"></script>
        <script type="text/javascript" src="/js/bower_components/requirejs/require.js"></script>

        <link rel="stylesheet" href="/css/main.css" media="screen" type="text/css">
        <link rel="stylesheet" href="/js/bower_components/bootstrap/dist/css/bootstrap.css">
    </head>
    <body>
        <!-- Content -->
        <div id="content" data-ui-view></div>

        <script>
            // obtain requirejs config
            require(['require', 'js/require-config'], function (require, config) {

                // set cache beater
                config.urlArgs = 'bust=v{{ version }}';

                // update global require config …
Run Code Online (Sandbox Code Playgroud)

requirejs angularjs angular-ui-router angular-google-maps

7
推荐指数
1
解决办法
4606
查看次数

将AWS S3 success_action_redirect策略与XHR一起使用

我正在使用signed POST将文件直接上传到amazon S3.我在使用PHP签署策略时遇到了一些麻烦,但最终修复了它,这里是代码示例.

这个xhr请求是用javascript发送的,我正在等待亚马逊的回答.起初我使用success_action_status它设置为201来获取XML响应.

我想做的是使用success_action_redirect我的服务器上的脚本来调用数据库中的记录.

原因是我可以在数据库中创建记录,如果在此阶段发生任何错误,我可以直接返回错误消息.它还为我的服务器节省了另一个ajax请求.

所以我试图设置此指定success_action_redirecthttp:\\localhost\callback.php在那里我有一个正在等待某些参数的脚本.

但看起来这个脚本永远不会被调用,而且它的响应xhr.send()是空的.

我认为这是一个跨浏览器的问题,我想知道是否有可能以某种方式使用jsonp来传递这个?有任何想法吗?

UPDATE

显然xhr本身就是重定向所以它应该可以工作但是当我指定success_action_redirect它返回时error Server responded with 0 code.

起初我以为是因为重定向URL在我的本地服务器上,所以我已将其更改为可访问的服务器,但没有机会.

任何人都知道为什么它会返回此错误消息?

jsonp xmlhttprequest amazon-s3 dropzone.js

6
推荐指数
1
解决办法
1670
查看次数

为什么PHPunit使用Silex要求KERNEL_DIR?

我正在尝试为我的Silex应用程序设置单元测试,但我不断收到此错误消息:

RuntimeException:根据http://symfony.com/doc/current/book/testing.html#your-first-functional-test在phpunit.xml中设置KERNEL_DIR 或覆盖WebTestCase :: createKernel()方法.

这是我的./app/phpunit.xml.dist:

<?xml version="1.0" encoding="UTF-8"?>

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
    backupGlobals="false"
    backupStaticAttributes="false"
    colors="true"
    convertErrorsToExceptions="true"
    convertNoticesToExceptions="true"
    convertWarningsToExceptions="true"
    processIsolation="false"
    stopOnFailure="false"
    syntaxCheck="false"
    bootstrap="phpunit_bootstrap.php"
>
    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>../src/Acme/*/Tests</directory>
        </testsuite>
    </testsuites>

    <!--<php>-->
        <!--<server name="KERNEL_DIR" value="/var/www/acme/api/app/" />-->
    <!--</php>-->
</phpunit>
Run Code Online (Sandbox Code Playgroud)

这是我的./app/phpunit_bootstrap.php(包括作曲家的自动加载器):

<?php

if (!@include __DIR__ . '/../../vendor/autoload.php') {
    die(<<<'EOT'
You must set up the project dependencies, run the following commands:
wget http://getcomposer.org/composer.phar
php composer.phar install
EOT
    );
}
Run Code Online (Sandbox Code Playgroud)

我的目录结构如下:

Silex应用程序树结构

它看起来像是phpunit在找,*Kernel.php但我不知道为什么.

这是我的单元测试: …

phpunit unit-testing silex

6
推荐指数
1
解决办法
3076
查看次数

如果启用了cookie,Symfony ESI会中断Varnish缓存

我不知道我在做什么了.我有很多问题,我不知道从哪里开始.这是我的配置:

varnishd (varnish-3.0.3 revision 9e6a70f)
Server version: Apache/2.2.22 (Unix)
Symfony 2.3.1
Run Code Online (Sandbox Code Playgroud)

首先,我AppCache在app.php文件中禁用了Symfony ,该文件被用作反向代理而不是Varnish.

这是我的清漆配置:

Varnish (80) <--> Apache (8080)

# /etc/varnish/default.vcl
backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

sub vcl_recv {
    if (req.http.Cache-Control ~ "no-cache") {
        return (pass);
    }

    if (!(req.url ~ "^/dashboard/")) {
        unset req.http.Cookie;
    }

    # Remove has_js and Google Analytics __* cookies.
    set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(_[_a-z]+|has_js)=[^;]*", "");
    # Remove a ";" prefix, if present.
    set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");

    #set …
Run Code Online (Sandbox Code Playgroud)

varnish session-cookies esi symfony-2.3

5
推荐指数
1
解决办法
3690
查看次数

htaccess 重定向 URI 到父目录

我有一个网站托管在/var/www/thesite(apache 服务器)中,它是一个Symfony2网站,所以在这个文件夹中我有一个web我的虚拟主机指向的文件夹。

所以我的虚拟主机是 www.mysite.com -> /var/www/thesite/web

在这个 web 文件夹中,我有一个.htaccess很好地格式化 URL。

现在,我在 中添加了一个 API /var/www/thesite/api,该 API 是使用Silex. 我想将所有请求重定向http://www.mysite.com/api到这个新框架。

所以我添加了 /var/www/thesite/web/.htaccess

RewriteCond %{REQUEST_URI} ^/api
RewriteRule ^api(.*)$ ../api/web/index.php [NC,QSA,L]
Run Code Online (Sandbox Code Playgroud)

但我得到:

错误的请求

您的浏览器发送了此服务器无法理解的请求。

我不确定是否可以访问.htaccess. 我不想更改我的虚拟主机目标目录以避免安全漏洞。

我该如何解决这个问题?

apache .htaccess mod-rewrite web-hosting symfony

5
推荐指数
1
解决办法
9660
查看次数