- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这段代码在PC网站上鼠标移动和滚轮移动时可以成功显示,但是当我想在移动webview中使用它时,只需移动它就可以成功。但是当我尝试缩放它时,d3.event.scale 将是 NaN,之后所有 event.scale 将是 NaN,我该如何解决这个问题?
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
;(function(w, d3, undefined){
"use strict";
var width, height;
function getSize(){
width = w.innerWidth,
height = w.innerHeight;
if(width === 0 || height === 0){
setTimeout(function(){
getSize();
}, 100);
}
else {
init();
}
}
function init(){
//Setup path for outerspace
var space = d3.geo.azimuthal()
.mode("equidistant")
.translate([width / 2, height / 2]);
space.scale(space.scale() * 3);
var spacePath = d3.geo.path()
.projection(space)
.pointRadius(1);
//Setup path for globe
var projection = d3.geo.azimuthal()
.mode("orthographic")
.translate([width / 2, height / 2]);
var scale0 = projection.scale();
var path = d3.geo.path()
.projection(projection)
.pointRadius(2);
//Setup zoom behavior
var zoom = d3.behavior.zoom(true)
.translate(projection.origin())
.scale(projection.scale())
.scaleExtent([100, 800])
.on("zoom", move);
var circle = d3.geo.greatCircle();
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.call(zoom)
.on("dblclick.zoom", null);
//Create a list of random stars and add them to outerspace
var starList = createStars(500);
var stars = svg.append("g")
.selectAll("g")
.data(starList)
.enter()
.append("path")
.attr("class", "star")
.attr("d", function(d){
spacePath.pointRadius(d.properties.radius);
return spacePath(d);
});
svg.append("rect")
.attr("class", "frame")
.attr("width", width)
.attr("height", height);
//Create the base globe
var backgroundCircle = svg.append("circle")
.attr('cx', width / 2)
.attr('cy', height / 2)
.attr('r', projection.scale())
.attr('class', 'globe')
.attr("filter", "url(#glow)")
.attr("fill", "url(#gradBlue)");
var g = svg.append("g"),
features;
//Add all of the countries to the globe
d3.json("world-countries.json", function(collection) {
features = g.selectAll(".feature").data(collection.features);
features.enter().append("path")
.attr("class", "feature")
.attr("d", function(d){ return path(circle.clip(d)); });
});
//Redraw all items with new projections
function redraw(){
features.attr("d", function(d){
return path(circle.clip(d));
});
stars.attr("d", function(d){
spacePath.pointRadius(d.properties.radius);
return spacePath(d);
});
}
function move() {
if(d3.event ){
//var r=d3.event.scale;
console.log(d3.event.sourceEvent.type);
if(**d3.event.scale.toString() != "NaN"**)
{
console.log(d3.event.scale);
//console.log(r);
console.log("hahahah");
var scale = d3.event.scale;
var origin = [d3.event.translate[0] * -1, d3.event.translate[1]];
projection.scale(scale);
space.scale(scale * 3);
backgroundCircle.attr('r', scale);
path.pointRadius(2 * scale / scale0);
projection.origin(origin);
circle.origin(origin);
//globe and stars spin in the opposite direction because of the projection mode
var spaceOrigin = [origin[0] * -1, origin[1] * -1];
space.origin(spaceOrigin);
redraw();
}
}
}
function createStars(number){
var data = [];
for(var i = 0; i < number; i++){
data.push({
geometry: {
type: 'Point',
coordinates: randomLonLat()
},
type: 'Feature',
properties: {
radius: Math.random() * 1.5
}
});
}
return data;
}
function randomLonLat(){
return [Math.random() * 360 - 180, Math.random() * 180 - 90];
}
}
getSize();
}(window, d3));
最佳答案
此问题在 2.5.0 版本的 d3 中已解决,请参阅 https://github.com/d3/d3/issues/341 。检查您的 d3 版本。
关于javascript - d3.event.scale 在触摸设备的缩放上包含 NaN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36886640/
我正在尝试在 View 中同时使用 scalegesture 监听器和 gesturelistener。如果比例为 1,则一切正常,但如果将比例设置为其他值,图像会跳到一个新位置,然后平滑缩放。 我的
我在使用 Canvas 和 canvas.scale(Scale, Scale) 时遇到图像质量问题;它们看起来完全像下面这样: android:运行时调整大小的图像质量 我相信我已经阅读了所有关于调
我有一个使用 svg 过滤器附加阴影的 svg 图形。我需要缩放阴影,但找不到可以执行此操作的过滤器。有谁知道这是否可能?
我正在构建一个逻辑回归分类器。 我从一组 500.000 条记录开始,我只想使用其中的一个样本。 你有什么建议: 1) 缩放总体然后采样2)缩放样本3) 仅缩放样本的 X_TRAIN 分割? 为什么?
我有一个功能,我用它在鼠标进入时放大图片并在鼠标离开时返回到正常大小。问题是,如果我在允许图片返回正常大小之前快速将鼠标移出然后将鼠标移入,那么图片将从鼠标输入时当前的任何大小放大(x2.7) (并且
可以在 scale-y-2 中使用 zoomtovalues 吗?我在多个 y 轴上有几个系列,我想将每个 scale-y-n 缩放到特定值,但我不知道如何... 谢谢和问候, 最佳答案 我们在最近的
我正在尝试在 Android 中创建(我认为是)一个相对简单的动画。也就是说,我想让某个 TextView 在单击按钮时缩小到 0 并返回到 1。当我单击该按钮时实际发生的是 TextView 立即缩
我有一个元素需要缩放到父元素的 100%。因为该元素包含基于像素的动画和可以缩放的图像,所以我不能使用百分比。有没有办法使用 css transform scale 来做到这一点? 最佳答案 相对 c
我在 ChartJS 中遇到一个奇怪的错误并且不知道如何修复它,由于这个错误我无法更改比例的任何内容。 我的代码(Sensor.tsx): import { useParams } from "sol
我有一些数据,我正试图通过不断增加的分母来准确和精确地处理这些数据。 请假设分子总是有小数。 我在 docs 中看到divide(BigDecimal divisor) 实际上会减小比例,这看起来很奇
喂, https://jsfiddle.net/jbwq6y87/7/ #box { width: 500px; height: 500px; transition: 0.5s; ov
几个 Tk 小部件也存在于 Ttk 版本中。通常它们具有相同的一般行为,但使用“样式”和“主题”而不是每个实例的外观属性(例如 bg 等)。这很好,因为 Ttk 小部件默认采用操作系统窗口管理器的“标
我尝试转换视频并使用 scale=-1:720 调整其大小,但出现错误“宽度不能被 2 整除”。我解决了这个问题:scale=-2:720。 之间有什么区别 scale=-1:720 和 scale=
我正在尝试重新创建此 codepen变换:我网站上特定页面的缩放转换,但它没有按预期工作 - 正如您在此代码片段中看到的那样(在整页上查看) - 图像覆盖/覆盖不足和不稳定而不是平滑。 /* Part
我有 3 个 Scale 小部件 scale1、scale2 和 scale3。我想使用 scale1 按以下方式控制 scale2 和 scale3 的值: 我不希望 scale2 和 scale3
我目前正在将我的数据分析从 R 转移到 Python。在 R 中缩放数据集时,我会使用 R.scale(),据我所知,它会执行以下操作:(x-mean(x))/sd(x) 为了替换该函数,我尝试使用
从文档中,定义为: 量化 ..a variant of linear scales with a discrete rather than continuous range. The input do
我有一个时基折线图,我正在尝试获取点击坐标处每个刻度的值。 我在 ChartJS 选项中指定的 onClick 函数: onClick: function(event, elementsAtEvent
我见过这样写的代码: ,但我也看到过这样写的代码: initial-scale=1 和 initial-scale=1.0 有区别吗? 最佳答案 没有。 specification描述视口(viewp
给定 y 轴 (s) 上的缩放和 x 轴 (t) 上的平移参数,当目的是最大化曲线叠加(而不是最小化距离)时,如何缩放和对齐两条不重合的曲线? 正如 @DWin 所指出的,这可能会被重新命名为“如何使
我是一名优秀的程序员,十分优秀!