我从d3js开始并尝试自己创建一个图表。 我想在两点之间画一条曲线。
/**
* serialized a form to a json object
*
* @usage: $("#myform").jsonSerialize();
*
*/
(function($) {
"use strict";
$.fn.jsonSerialize = function() {
var json = {};
var array = $(this).serializeArray();
$.each(array, function(key, obj) {
var value = (obj.value == "") ? false : obj.value;
if(value) {
// check if we have a number
var isNum = /^\d+$/.test(value);
if(isNum) value = parseFloat(value);
// check if we have a boolean
var isBool = /^(false|true)+$/.test(value);
if(isBool) value = (value!=="false");
}
json[obj.name] = value;
});
return json;
}
})(jQuery);
当我做我的研究时,我发现了一些使用对角函数绘制曲线的例子。比如this
有没有办法用对角线在两个已知点之间绘制一条简单的曲线?还是有一些替代方法?
答案 0 :(得分:7)
你可以这样做:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.12/d3.js"></script>
</head>
<body>
<svg width=500 height=500></svg>
</body>
</html>
func animate() {
heartImg.frame = CGRectMake(angryBedousImg.frame.size.width / 2, angryBedousImg.frame.size.height / 2, heartImg.frame.size.width, heartImg.frame.size.height)
let heartAnimation = CABasicAnimation(keyPath: "position")
heartAnimation.duration = 0.09
heartAnimation.repeatCount = .infinity
heartAnimation.autoreverses = true
heartAnimation.fromValue = NSValue(CGPoint: CGPointMake(heartImg.center.x - 1, heartImg.center.y))
heartAnimation.toValue = NSValue(CGPoint: CGPointMake(heartImg.center.x + 1, heartImg.center.y))
heartImg.layer.addAnimation(heartAnimation, forKey: "position")
}