d3.js diamond symbol size functionality - d3.js

I want to use "diamond" symbol in D3.
I am not sure how the sizing for symbols works in D3. My requirement is:
svg = d3.select("svg");
svg.append("g").append("path")
.attr("d", d3.svg.symbol()
.size( function(d) { return 15 })
.type( function(d) { return "diamond" }))
.attr("transform", "translate(250, 150)")
.style("fill", "black");
I want the height of the diamond to be set to 15px. Can anyone help me on this ? Thanks in advance.

Following on from the answer by Adam Pearce, I am using the following code, which appears to deliver consistent and accurate results across all of the available d3.svg.symbol shapes (e.g. diamond, cross, square etc.):
d3.svg.symbol().size(function(d) {
return (itemHeight * itemHeight) / 2;
}))
Where itemHeight refers to a fixed height for the shape.

Try:
.size( function(d) { return 15*15 })
From the documentation:
sets the size-accessor to the specified function or constant in square
pixels

Since I need a exact height / width, ended up using something like this to get the "d" attribute:
if (shape == "triangle") {
return "M " + dim / 2 + " 0 L " + dim + " " + dim + " L 0 " + dim + " " + dim / 2 + " 0";
}
if (shape == "diamond") {
return "M " + dim / 2 + " 0 L " + dim + " " + dim / 2 + " L " + dim / 2 + " " + dim + " L 0 " + dim / 2 + " L " + dim / 2 + " 0";
}
where "dim" is the height value.

Related

Visual Fox Pro file access

I have a function whitch creates .xml files with some data inside. Everytime firstly it deletes the old file. Everything works fine except it sometimes gets frozen and the file itself becomes locked. It's size is 0 kb and program can't even delete it. And I have to kill the process, delete the file by myself and then run the program again. Is it possible to kill all the processes of the same program before the begining of a new one? Or at least put some timer on it to make sure it turns off automatically after some time passes by?
Need some ideas, thanks.
fHandle = f_cFile("D:\Data\new_eur\Saskaitos.xml")
if fHandle < 0
**=messagebox("Can't create file!",16,"!!!")
=STRTOFILE("Can't create XML file" + CHR(13) + CHR(10), "d:\Log.txt", 1)
quit
ENDIF
** Header
if fputs(fHandle, '<?xml version="1.0" encoding="windows-1257"?>') < 0
=fclose(fHandle)
=STRTOFILE("Can't write to XML file" + CHR(13) + CHR(10), "d:\Log.txt", 1)
quit
endif
=STRTOFILE(TTOC(dateTIME()) + ": " + "XML ok"+CHR(13)+CHR(10), "d:\LogData.txt", 1)
=fputs(fHandle, "<Accounts>")
enteris = CHR(13)
DO WHILE NOT EOF()
=fputs(fHandle, "<Detali>")
=fputs(fHandle, "<Snr><![CDATA[" + ALLTRIM(Data.dok_nr) + "]]></Snr>" + enteris)
=fputs(fHandle, "<Code_ks><![CDATA[" + ALLTRIM(Data.Code_ks) + "]]></Code_ks>" + enteris)
=fputs(fHandle, "<Sdata>" + ALLTRIM(Data.dok_data) + "</Sdata>" + enteris)
=fputs(fHandle, "<Term>" + ALLTRIM(Duomenys.Terminas) + "</Term>" + enteris)
=fputs(fHandle, "<Manager><![CDATA[" + ALLTRIM(Data.Code_ms) + "]]></Manager>" + enteris)
IF Data.val_poz = 0
=fputs(fHandle, "<MokSuma>" + ALLTRIM(STR(Duomenys.SumaMok, 12, 2)) + "</MokSuma>" + enteris)
=fputs(fHandle, "<ApSuma>" + ALLTRIM(STR(Duomenys.ApSuma, 12, 2)) + "</ApSuma>" + enteris)
ELSE
=fputs(fHandle, "<MokSuma>" + ALLTRIM(STR(Duomenys.SumaVal, 12, 2)) + "</MokSuma>" + enteris)
=fputs(fHandle, "<ApSuma>" + ALLTRIM(STR(Duomenys.ApVal, 12, 2)) + "</ApSuma>" + enteris)
ENDIF
=fputs(fHandle, "</Detali>")
skip
ENDDO
fputs(fHandle, "</Accounts>")
=fclose(fHandle)
Now this is the code which puts xml data into the file. At some point it freezes and the next time program starts it is still using the same file.
Function f_cFile:
FUNCTION f_cFile
PARAMETERS fName
fHandle = fcreate(fName)
IF fHandle < 0
IF FILE(fName,1)
DELETE FILE fName
IF FILE(fName,1)
=STRTOFILE("Can't delete old file: " + fName + CHR(13) + CHR(10), " d:\Log.txt", 1)
ELSE
fHandle = fcreate(fName)
ENDIF
ENDIF
ENDIF
RETURN fHandle
ENDFUNC
Wow... many other options to simplify your locking issue. First without changing your stuff too much is to build via strings... Make a variable and keep appending to it until you are done, then write it with a single write command such as..
enteris = CHR(13)
myXML = '<?xml version="1.0" encoding="windows-1257"?>' + enteris;
+ "<Accounts>"
SCAN
myXML = myXML + "<Detali>";
+ "<Snr><![CDATA[" + ALLTRIM(Data.dok_nr) + "]]></Snr>" + enteris;
+ "<Code_ks><![CDATA[" + ALLTRIM(Data.Code_ks) + "]]></Code_ks>" + enteris;
+ "<Sdata>" + ALLTRIM(Data.dok_data) + "</Sdata>" + enteris;
+ "<Term>" + ALLTRIM(Duomenys.Terminas) + "</Term>" + enteris;
+ "<Manager><![CDATA[" + ALLTRIM(Data.Code_ms) + "]]></Manager>" + enteris
IF Data.val_poz = 0
myXML = myXML + "<MokSuma>" + ALLTRIM(STR(Duomenys.SumaMok, 12, 2)) + "</MokSuma>" + enteris;
+ "<ApSuma>" + ALLTRIM(STR(Duomenys.ApSuma, 12, 2)) + "</ApSuma>" + enteris
ELSE
myXML = myXML + "<MokSuma>" + ALLTRIM(STR(Duomenys.SumaVal, 12, 2)) + "</MokSuma>" + enteris;
+ "<ApSuma>" + ALLTRIM(STR(Duomenys.ApVal, 12, 2)) + "</ApSuma>" + enteris
ENDIF
myXML = myXML + "</Detali>";
ENDSCAN
myXML = myXML + "</Accounts>"
if StrToFile( myXML, "D:\Data\new_eur\Saskaitos.xml" ) = 0
=STRTOFILE("Can't create XML file" + CHR(13) + CHR(10), "d:\Log.txt", 1)
endif
Done... Let VFP handle the low level open and close of the writing.

Calculate new release time for files

We have some code that checks each incoming file against 3 different criteria before processing (Not a weekend, not after 6pm, not a holiday). This being said, I need to figure out how to have it check for a half hour now (bolded part). I have tried adding a + mRelease > 30 as well as AND mRelease > 30 and both have failed. I have been altering this line
Do While (WeekDay(dRelease) = 1) OR (WeekDay(dRelease) = 7) OR (UBound(fHoliday) > -1) OR (tRelease >17)
Here is the code currently in place:
result = ""
dRelease = Now
tRelease = CStr(Hour(Now))
mRelease = CStr(Minute(Now))
aHoliday = Array("01/02/2017","01/16/2017","05/29/2017","07/04/2017","09/04/2017","10/09/2017","11/23/2017","11/24/2017","12/25/2017","12/26/2017")
dNow = CStr(DatePart("m",Date)) + "/" + CStr(DatePart("d",Date)) + "/" + CStr(DatePart("yyyy",Date))
dMonth = "0" + CStr(Month(dRelease))
dDay = "0" + CStr(Day(dRelease))
dYear = CStr(Year(dRelease))
fHoliday = Filter(aHoliday,Right(dMonth,2) + "/" + Right(dDay,2) + "/" + dYear)
'fHoliday = Filter(aHoliday,dNow)
'result = UBound(fHoliday)
'result = Left(dRelease,10)
'result = CStr(DatePart("m",Date)) + "/" + CStr(DatePart("d",Date)) + "/" + CStr(DatePart("yyyy",Date))
'While release date is a weekend, or release date is a holiday
Do While (WeekDay(dRelease) = 1) OR (WeekDay(dRelease) = 7) OR (UBound(fHoliday) > -1) OR (tRelease >17)
'increase release date by 1
dRelease = dRelease + 1
'result = dRelease
'check for holiday
dMonth = "0" + CStr(Month(dRelease))
dDay = "0" + CStr(Day(dRelease))
dYear = CStr(Year(dRelease))
'fHoliday = Filter(aHoliday,Left(dRelease,10))
fHoliday = Filter(aHoliday,Right(dMonth,2) + "/" + Right(dDay,2) + "/" + dYear)
tRelease = 00
Loop
'Format the release date to the Esker deferred date/time standard.
dMonth = "0" + CStr(Month(dRelease))
dDay = "0" + CStr(Day(dRelease))
dYear = CStr(Year(dRelease))
dtCurrent = Right(dMonth,2) + "/" + Right(dDay,2) + "/" + dYear
If dRelease > Now Then
tRelease = "00:" + mRelease
Else
tRelease = CStr(Hour(Now)) + ":" + CStr(Minute(Now))
End If
result = dtCurrent + " " + tRelease
Change this:
Do While (WeekDay(dRelease) = 1) OR (WeekDay(dRelease) = 7) OR (UBound(fHoliday) > -1) OR (tRelease >17)
...
Loop
into this:
If (WeekDay(dRelease) = 1) Or (WeekDay(dRelease) = 7) Or (UBound(fHoliday) > -1) Or (Time > CDate("16:30")) Then
...
End If

Quaternion product is different from the quaternion extracted from the matrix product

Yesterday I have been trying to solve the following problem: calculate the local rotation quaternion for a bone given its global rotation quaternion and the skeleton state.
I figured that the global quaternion equals to the parent bone global multiplied by the bone's local quaternion:
global = globalParent * local
After a couple of simple manipulations, I got the following:
local = (globalParent)-1 * global
I did some tests on that equation and, to my surprise, it sometimes yields the correct answer and sometimes I get the correct answer multiplied by -1. Not the local quaternion's conjugate, but the whole quaternion multiplied by -1.
So I went back to the original equation (global = globalParent * local) and tested it too. The same thing happened, sometimes the right answer and sometimes the right answer multiplied by -1.
I found that really strange and went further to make the matrix product (globalParent * local) and extract the quaternion for the result. In this situation, I always got the right answer.
Finally, my question is pretty simple. Where is the mistake in my thought process when manipulating the quaternions?
The code I used to check the things I said is the following:
{
var p = new THREE.Vector3();
var s = new THREE.Vector3();
var bone = this.get_model_bone(label);
var gm = bone.matrixWorld;
var g = new THREE.Quaternion();
gm.decompose(p, g, s);
console.log(label + " - GLOBAL: (" + g.x + ", " + g.y + ", " + g.z + ", " + g.w + ")");
var m = bone.matrix;
var q = new THREE.Quaternion();
m.decompose(p, q, s);
console.log(label + " - LOCAL: (" + q.x + ", " + q.y + ", " + q.z + ", " + q.w + ")");
if(bone.parent !== null)
{
var gpm = bone.parent.matrixWorld;
var gp = new THREE.Quaternion();
gpm.decompose(p, gp, s);
console.log(label + " - PARENT GLOBAL: (" + gp.x + ", " + gp.y + ", " + gp.z + ", " + gp.w + ")");
var productMatrix = new THREE.Matrix4().multiplyMatrices(gpm, m);
var qprod = new THREE.Quaternion();
productMatrix.decompose(p, qprod, s);
console.log(label + " - MATRIX PROD: (" + qprod.x + ", " + qprod.y + ", " + qprod.z + ", " + qprod.w + ")");
var gpq = new THREE.Quaternion().multiplyQuaternions(gp, q);
console.log(label + " - QUAT PROD: (" + gpq.x + ", " + gpq.y + ", " + gpq.z + ", " + gpq.w + ")");
}
}
In my logs, sometimes "MATRIX PROD" is different than "QUAT PROD". The model I am using can be found at:
https://raw.githubusercontent.com/poli-libras/virtual-jonah2/master/resources/model/human.js
I did some tests on that equation and, to my surprise, it sometimes yields the correct answer and sometimes I get the correct answer multiplied by -1.
Quaternion and quaternion multiplied by -1 represent exact same transformation (rotation).

4x4 Fixed point matrix multiplication doesn't work

I have this function which concatenates two matrices:
out->_11 = MAT_MUL(b->_11, a->_11) + MAT_MUL(b->_21, a->_12) + MAT_MUL(b->_31, a->_13) + MAT_MUL(b->_41, a->_14);
out->_12 = MAT_MUL(b->_12, a->_11) + MAT_MUL(b->_22, a->_12) + MAT_MUL(b->_32, a->_13) + MAT_MUL(b->_42, a->_14);
out->_13 = MAT_MUL(b->_13, a->_11) + MAT_MUL(b->_23, a->_12) + MAT_MUL(b->_33, a->_13) + MAT_MUL(b->_43, a->_14);
out->_14 = MAT_MUL(b->_14, a->_11) + MAT_MUL(b->_24, a->_12) + MAT_MUL(b->_34, a->_13) + MAT_MUL(b->_44, a->_14);
out->_21 = MAT_MUL(b->_11, a->_21) + MAT_MUL(b->_21, a->_22) + MAT_MUL(b->_31, a->_23) + MAT_MUL(b->_41, a->_24);
out->_22 = MAT_MUL(b->_12, a->_21) + MAT_MUL(b->_22, a->_22) + MAT_MUL(b->_32, a->_23) + MAT_MUL(b->_42, a->_24);
out->_23 = MAT_MUL(b->_13, a->_21) + MAT_MUL(b->_23, a->_22) + MAT_MUL(b->_33, a->_23) + MAT_MUL(b->_43, a->_24);
out->_24 = MAT_MUL(b->_14, a->_21) + MAT_MUL(b->_24, a->_22) + MAT_MUL(b->_34, a->_23) + MAT_MUL(b->_44, a->_24);
out->_31 = MAT_MUL(b->_11, a->_31) + MAT_MUL(b->_21, a->_32) + MAT_MUL(b->_31, a->_33) + MAT_MUL(b->_41, a->_34);
out->_32 = MAT_MUL(b->_12, a->_31) + MAT_MUL(b->_22, a->_32) + MAT_MUL(b->_32, a->_33) + MAT_MUL(b->_42, a->_34);
out->_33 = MAT_MUL(b->_13, a->_31) + MAT_MUL(b->_23, a->_32) + MAT_MUL(b->_33, a->_33) + MAT_MUL(b->_43, a->_34);
out->_34 = MAT_MUL(b->_14, a->_31) + MAT_MUL(b->_24, a->_32) + MAT_MUL(b->_34, a->_33) + MAT_MUL(b->_44, a->_34);
out->_41 = MAT_MUL(b->_11, a->_41) + MAT_MUL(b->_21, a->_42) + MAT_MUL(b->_31, a->_43) + MAT_MUL(b->_41, a->_44);
out->_42 = MAT_MUL(b->_12, a->_41) + MAT_MUL(b->_22, a->_42) + MAT_MUL(b->_32, a->_43) + MAT_MUL(b->_42, a->_44);
out->_43 = MAT_MUL(b->_13, a->_41) + MAT_MUL(b->_23, a->_42) + MAT_MUL(b->_33, a->_43) + MAT_MUL(b->_43, a->_44);
out->_44 = MAT_MUL(b->_14, a->_41) + MAT_MUL(b->_24, a->_42) + MAT_MUL(b->_34, a->_43) + MAT_MUL(b->_44, a->_44);
MAT_MUL looks like this:
#define MAT_MUL(o1,o2) ((GLfixed)((long)(o1)*(long)(o2))>>16)
The odd thing is that it doesn't work with fixed point values but with float values (MAT_MUL(o1,o2) (o1)*(o2) in this case). I traced the error down to this bit of code.
Any ideas? Thanks

How to jump forward/backward from Xcode split window?

I used to split my Xcode window to 4 sub windows (not popup). I wonder if there's shortcut key to move cursor from one sub window to another ?
+++++++++++++++++++++++++++++
+ + + +
+ G / + F1 + F2 +
+ r F + + +
+ o i +++++++++++++++++++++++
+ u l + + +
+ p e + F3 + F4 +
+ + + +
+++++++++++++++++++++++++++++

Resources