如何在d3.js中为路径上的多个圆圈制作动画?(How to animate multiple circles on a path in d3.js?)
我试图把它作为参考https://bl.ocks.org/mbostock/1705868 。
我想将多个圆圈旋转为点而不是无限旋转的单个圆圈。
function translateAlong(path) { var l = path.getTotalLength(); return function(i) { return function(t) { var p = path.getPointAtLength(t * l); return "translate(" + p.x + "," + p.y + ")";//Move marker } } }
我最初在路径上绘制了所有必需的点,如https://jsfiddle.net/tzbd9r1f/2/
我在这里遇到两个问题:
1:当我尝试为所有圆圈设置动画时,我看到只有一个圆形动画而不是5个圆圈,如https://jsfiddle.net/tzbd9r1f/1/ 。
2:如果我试图调用所有5个圆圈的结束转换,我会得到最大的堆栈错误,以防万一这样无限旋转,如https://jsfiddle.net/tzbd9r1f/3/
请指导。
Im trying to take this as reference https://bl.ocks.org/mbostock/1705868.
I want to rotate multiple circle as points instead of single circle rotating above infinitely.
function translateAlong(path) { var l = path.getTotalLength(); return function(i) { return function(t) { var p = path.getPointAtLength(t * l); return "translate(" + p.x + "," + p.y + ")";//Move marker } } }
I initially plotted all the required points on path as https://jsfiddle.net/tzbd9r1f/2/
Im facing two problems here :
1 : When I try to animate all the circles I see only one circle animating and not 5 circles as here https://jsfiddle.net/tzbd9r1f/1/.
2 : If I try to call end transition for all 5 circle I get maximum stack error in case making this as infinitely rotating as here https://jsfiddle.net/tzbd9r1f/3/
Please guide.
原文:https://stackoverflow.com/questions/39308514
最满意答案
读取文件时可以这样做:
// create a placeholder for processed lines List<List<string>> _output = new List<List<string>>(); using (StreamReader reader = new StreamReader(File.OpenRead(filePath))) { int i = 0; // create indexer _output.Add(new List<string>()); // add new sequence _output.Last().Add(i.ToString() + "."); // insert sequence indexer string line = string.Empty; while( (line = reader.ReadLine()) != null) { if(string.IsNullOrWhiteSpace(line)) { i++; _output.Add(newList<string>()); _output.Last().Add(i.ToString() + "."); } else { _output.Last().Add(line); } } }
然后,您可以使用以下内容将其写入文本文件中:
using (StreamWriter writer = new StreamWriter(File.OpenWrite(filePath))) { foreach(List<string> lines in _output) { foreach(string line in lines) { writer.WriteLine(line); } writer.WriteLine(line); } }
如果这不是一个文件(没有指定),而是
string
,你可以使用StringReader
而不是StreamReader
和StringWriter
来代替StreamWriter
。对于因“非正则表达式”回答或其他某些其他原因而想要downvote的其他人...
You can do this while reading the file :
// create a placeholder for processed lines List<List<string>> _output = new List<List<string>>(); using (StreamReader reader = new StreamReader(File.OpenRead(filePath))) { int i = 0; // create indexer _output.Add(new List<string>()); // add new sequence _output.Last().Add(i.ToString() + "."); // insert sequence indexer string line = string.Empty; while( (line = reader.ReadLine()) != null) { if(string.IsNullOrWhiteSpace(line)) { i++; _output.Add(newList<string>()); _output.Last().Add(i.ToString() + "."); } else { _output.Last().Add(line); } } }
Then you can write this into a text file using :
using (StreamWriter writer = new StreamWriter(File.OpenWrite(filePath))) { foreach(List<string> lines in _output) { foreach(string line in lines) { writer.WriteLine(line); } writer.WriteLine(line); } }
If that's not a file ( which was not specified ) but
string
instead, you can useStringReader
instead ofStreamReader
andStringWriter
instead ofStreamWriter
.For everyone else that want to downvote because of "non-regex" answer or some other b....
相关问答
更多-
如何匹配恰好两个空行(How to match exactly two empty lines)[2023-05-22]
新答案 在排除> 2空行后出现问题之后,在这里睡个好觉是更好的方法,甚至不需要啜食。 #!/usr/bin/perl use strict; use warnings; my $file = 'yu'; my @blocks; #each element will be an arrayref, one per block #that referenced array will hold lines in that block open(my $fh, '<', $fi ... -
使用StringBuilder并根据需要附加到它。 在将每个TextBox添加到StringBuilder之前测试每个TextBox是否为空。 var P9811A = new StringBuilder("G65Y9811"); if (textBox1.Text != "") P9811A.Append("X" + textBox1.Text); if (textBox2.Text != "") P9811A.Append("C" + textBox2.Text); // and ...
-
兄弟..让我们循环进入这些excel线并尝试验证线条是否为空...对于每个非空行,我们应该再次通过TAB字符拆分它(你必须注意到当你复制时从excel,它通过TAB分隔列... ...让你从第一个变量,“矢量”工作: //First, you are splitting your text by a line break. Each array position is one Excel line: String[] vector = textBox1.Text.Split(new String[] { E ...
-
仅在存在时从行首开始删除指定的文本(C#)(Remove specified text from beginning of lines only if present (C#))[2022-07-28]
他最简单的方法是一次完成整个文本块的以下操作: string uncommentedText = yourText.Trim().Replace("-- ", ""); 您也可以将整个文本分割成一行文本行,然后逐行执行以确保中间某处的"-- "不会被删除: string uncommentedLine = yourLine.Trim().StartsWith("-- ") ? yourLine.Trim().Replace("-- ", "") : yourLine; He simplest m ... -
你没有在第二个链接上学习答案 - 它有一个非常好的解决方案。 我更喜欢使用*]=替换而不是substring的那种技术的变体: @echo off setlocal enableextensions disabledelayedexpansion set "search=
" set "replace=XYZ" set "textFile=C:\abc.txt" for /f "delims=" %%i in ('type "%textFile%" ^| find /v /n "" ^& b ... -
匹配空行之间的文本C#(Match text between empty lines C#)[2023-06-28]
读取文件时可以这样做: // create a placeholder for processed lines List- > _output = new List
- >();
using (StreamReader reader = new StreamReader(File.OpenRead(filePath)))
{
int i = 0; // create indexer
_output.Add(new List
()); ... -
假设你的意思是由无偿的回车创建的不需要的空白行,这是一种方式。 为了清晰起见,我把它弄得很冗长,但如果你愿意,可以将它减少到一行。 private function stripLinesFromTextArea (textArea:TextArea) : void { var txt:String = textArea.text; var re:RegExp = /\n+/g; txt = txt.replace(re,"\n"); textArea.text = txt; } Assum ...
-
如何删除文本文件中句子之间空行的空行?(How to remove empty lines to one empty line between sentences in text files?)[2022-02-20]
您可以使用awk : awk 'BEGIN{prev="x"} /^$/ {if (prev==""){next}} {prev=$0;print}' inputFile 或压缩的一个衬垫: awk 'BEGIN{p="x"}/^$/{if(p==""){next}}{p=$0;print}' inFl 这是一个简单的状态机,可将多个空白行折叠为单个行。 基本的想法是这样的。 首先,将上一行设置为非空。 然后,对于文件中的每一行,如果它和前一行是空白的,则将其丢 ... -
由于对标签使用正则表达式的不满,我将回答我自己的问题,说我已经避免使用正则表达式,只是使用了子串方法; int startIndex = line.IndexOf(">") + 1; line = line.Substring(startIndex, line.IndexOf("<", startIndex)); 至于修复Regex匹配问题,@ nhahtdh给出的关于SingleLine选项的建议就行了。 谢谢你们的评论。 Due to the frowned upon usage of Regex w ...
-
这是一个空洞的陈述 。 它作为循环体很有用: while(!Condition()) ; 在for循环中更常见,其中循环体完全嵌入循环头中。 让我们遍历链表的最后一个元素: Node current = head; for (; current.Next != null; current = current.Next) ; return current; 它看起来有点讨厌,通常我更喜欢编写一个更长但更易读的循环。 C ++人员倾向于将东西塞进循环标题中。 我相信它在代码生成场景中也会派上用场。 It's ...