我正在尝试在d3.js中构建一个矩形网格.
网格为7行(一周中的天数)和24列(一天中的小时数).
以下代码仅绘制(行:列):day0:hour0,day1:hour1,day2:hour2,day3:hour3,day4:hour4,day5:hour5,day6:hour6,day7:hour7
问题:为什么以下代码不起作用的任何想法?
/**
* calendarWeekHour Setup a week-hour grid:
* 7 Rows (days), 24 Columns (hours)
* @param id div id tag starting with #
* @param width width of the grid in pixels
* @param height height of the grid in pixels
* @param square true/false if you want the height to
* match the (calculated first) width
*/
function calendarWeekHour(id, width, height, square)
{
var calData = randomData(width, height, square);
var grid = d3.select(id).append("svg")
.attr("width", …
Run Code Online (Sandbox Code Playgroud) 我按照以下说明操作:http://bost.ocks.org/mike/path/,用单行创建和动画单个图形.
并且,弄清楚如何在图形中创建多条线:在D3.js中绘制多条线
主要问题:在我将新数据移入我的数据阵列后,我很难转换多行.
我创建N行:(时间:纪元时间,前进步骤)
var seriesData = [[{time:1335972631000, value:23}, {time:1335972631500, value:42},...],
[{time:1335972631000, value:45}, {time:1335972631500, value:13},...],
[{time:1335972631000, value:33}, {time:1335972631500, value:23},...}],
[...],[...],...
];
var seriesColors = ['red', 'green', 'blue',...];
line = d3.svg.line()
.interpolate(interpolation)
.x(function(d) { return x(d.time); })
.y(function(d) { return y(d.value); });
graphGroup.selectAll(".line")
.data(seriesData)
.enter().append("path")
.attr("class", "line")
.attr("d", line)
.style('stroke', function(d, i) { return seriesColors[i]; })
.style('stroke-width', 1)
.style('fill', 'none');
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用Javascript setInterval(...)更新N行,调用方法:
graph.selectAll("path")
.data(seriesData)
.attr("transform", "translate(" + x(1) + ")")
.attr("d", …
Run Code Online (Sandbox Code Playgroud) 更新02有一个可行的解决方案...
我正在尝试使用UIBezierPath的笔触作为另一个UIView上的蒙版。有很多示例,但是它们都使用填充来剪辑视图。
我试图仅使用路径的笔触,但显示不正确。
以下是我目前在Swift 3.x中拥有的功能:
let bezierPath = UIBezierPath()
bezierPath.move(to: CGPoint(x: 0, y: 0))
bezierPath.addLine(to: CGPoint(x: 100, y: 100))
bezierPath.addLine(to: CGPoint(x: 200, y: 50))
bezierPath.addLine(to: CGPoint(x: 300, y: 100))
bezierPath.lineWidth = 5.0
bezierPath.stroke()
let gradient = Gradient(frame: self.bounds)
let mask = CAShapeLayer()
mask.path = bezierPath.cgPath
gradient.layer.mask = mask
self.addSubview(gradient)
Run Code Online (Sandbox Code Playgroud)
但是,上面的代码可以做到这一点。我正在寻找仅将笔划用作蒙版...这是代码当前正在执行的操作
(此comp快照中还有更多点)
我意识到,可能会有更好的方法,欢迎任何想法或替代方案!
-更新01--
我的最新作品,但掩盖了一切:
let bezierPath = UIBezierPath()
bezierPath.move(to: CGPoint(x: 0, y: 0))
bezierPath.addLine(to: CGPoint(x: 100, y: 100))
bezierPath.addLine(to: CGPoint(x: 200, y: 50))
bezierPath.addLine(to: CGPoint(x: 300, y: 100))
bezierPath.lineWidth …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 iOS SpriteKit 使用内置物理以编程方式构建一个钟摆。
目前,我有摆枢轴、重物和允许重物摆动的有限关节...但是,我不知道如何在枢轴和重物之间编写一条线(杆)。
我认为用 SKShapeNode 画一条线将是一个开始......?
-(void)setupPendulum
{
pivot = [SKSpriteNode spriteNodeWithImageNamed:@"pivot.png"];
pivot.position = CGPointMake(self.size.width / 2, self.size.height / 2);
pivot.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:1.0];
pivot.physicsBody.dynamic = NO;
pivot.physicsBody.affectedByGravity = NO;
pivot.xScale = 0.25;
pivot.yScale = 0.25;
[self addChild:pivot];
weight = [SKSpriteNode spriteNodeWithImageNamed:@"weight.png"];
weight.position = CGPointMake(150, 512);
weight.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:100.0];
weight.physicsBody.dynamic = YES;
weight.physicsBody.affectedByGravity = YES;
weight.physicsBody.mass = 0.5;
weight.xScale = 0.75;
weight.yScale = 0.75;
[self addChild:weight];
SKPhysicsBody *ab = pivot.physicsBody;
SKPhysicsBody *bb = weight.physicsBody;
CGPoint ap = …
Run Code Online (Sandbox Code Playgroud) #include <iostream>
#include <sstream>
#include <numeric>
#include <math.h>
using namespace std;
int64_t splitAdd(int64_t value) {
ostringstream intStream;
intStream << value;
string intString(intStream.str());
return accumulate(intString.begin(), intString.end(), 0) - (intString.size() * int64_t('0'));
}
int main(int argc, char *argv[]) {
int64_t maxPower = 50;
int64_t results[maxPower];
for (int64_t tuple = 0; tuple <= maxPower; tuple++) {
for(int64_t power = 0; power <= maxPower; power++) {
int64_t value = pow(tuple, power);
while (value > 9) {
value = splitAdd(value);
}
results[power] = value;
} …
Run Code Online (Sandbox Code Playgroud)