Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preattentive symbols #176

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
dist/
node_modules
npm-debug.log
d3-shape.xcodeproj/xcuserdata/hemanrobinson.xcuserdatad/xcschemes/xcschememanagement.plist
d3-shape.xcodeproj/project.xcworkspace/xcuserdata/hemanrobinson.xcuserdatad/UserInterfaceState.xcuserstate
d3-shape.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
d3-shape.xcodeproj/project.xcworkspace/contents.xcworkspacedata
d3-shape.xcodeproj/project.pbxproj
18 changes: 18 additions & 0 deletions src/pSymbol/asterisk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Asterisk */
export default {
draw: function( g, size ) { if( size > 0 ) {
let r = Math.sqrt( size / Math.PI ); // radius
let s = Math.max( 1.5, r * Math.PI / 3 + 0.5 ); // +0.5 accounts for overlap.
let t = s * Math.sin( Math.PI / 6 ),
u = s * Math.cos( Math.PI / 6 );
g.moveTo( 0, s );
g.lineTo( 0, -s );
g.closePath();
g.moveTo( -u, -t );
g.lineTo( u, t );
g.closePath();
g.moveTo( -u, t );
g.lineTo( u, -t );
g.closePath();
}}
};
8 changes: 8 additions & 0 deletions src/pSymbol/circle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Circle */
export default {
draw: function( g, size ) { if( size > 0 ) {
let s = Math.sqrt( size / Math.PI ); // radius
g.arc( 0, 0, s, 0, 2 * Math.PI );
g.closePath();
}}
};
20 changes: 20 additions & 0 deletions src/pSymbol/diamond.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Diamond */
export default {
draw: function( g, size ) { if( size > 0 ) {
let r = Math.sqrt( size / Math.PI ); // radius
let s = r * Math.PI / ( 2 * Math.SQRT2 ) + 0.5; // +0.5 accounts for overlap.
let t = 1 / ( 2 * Math.SQRT2 ); // t accounts for line width.
g.moveTo( -t, - s - t );
g.lineTo( s + t, t );
g.closePath();
g.moveTo( s + t, -t );
g.lineTo( -t, s + t );
g.closePath();
g.moveTo( t, s + t );
g.lineTo( - s - t, -t );
g.closePath();
g.moveTo( - s - t, t );
g.lineTo( t, - s - t );
g.closePath();
}}
};
31 changes: 31 additions & 0 deletions src/pSymbol/pSymbol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Popular symbols with preattentive features.
*
* Preattentive features aid pattern detection and reduce overlap.
* These symbols are adjusted to have approximately equal weight.
*
* Symbols are centered at (0,0). When translating,
* round to the center of the pixel to minimize anti-aliasing, e.g.
* .attr( "transform", "translate( " + ( Math.floor( x ) + 0.5 ) + ", " + ( Math.floor( y ) + 0.5 ) + " )" )
*/
import circle from "./pSymbol/circle.js";
import plus from "./pSymbol/plus.js";
import x from "./pSymbol/x.js";
import triangle from "./pSymbol/triangle.js";
import asterisk from "./pSymbol/asterisk.js";
import square from "./pSymbol/square.js";
import diamond from "./pSymbol/diamond.js";
export var pSymbols = [
circle,
plus,
x,
triangle,
asterisk,
square,
diamond
];

/**
* Symbol sets.
*/
export var symbolSets = [ "geometric": symbols, "preattentive": pSymbols ];
13 changes: 13 additions & 0 deletions src/pSymbol/plus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Plus */
export default {
draw: function( g, size ) { if( size > 0 ) {
let r = Math.sqrt( size / Math.PI ); // radius
let s = Math.max( 1.5, r * Math.PI / 2 - 0.25 ); // -0.25 accounts for center pixel.
g.moveTo( -s, 0 );
g.lineTo( s, 0 );
g.closePath();
g.moveTo( 0, s );
g.lineTo( 0, -s );
g.closePath();
}}
};
12 changes: 12 additions & 0 deletions src/pSymbol/square.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Square */
export default {
draw: function( g, size ) { if( size > 0 ) {
let r = Math.sqrt( size / Math.PI ); // radius
let s = r * Math.PI / 4 + 0.25; // +0.25 accounts for overlap.
g.moveTo( s, s );
g.lineTo( s, -s );
g.lineTo( -s, -s );
g.lineTo( -s, s );
g.closePath();
}}
};
13 changes: 13 additions & 0 deletions src/pSymbol/triangle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Triangle */
export default {
draw: function( g, size ) { if( size > 0 ) {
let r = Math.sqrt( size / Math.PI ); // radius
let s = r * Math.PI / 3 + 0.5; // +0.5 accounts for overlap.
let t = s * Math.sin( Math.PI / 6 ),
u = s * Math.cos( Math.PI / 6 );
g.moveTo( 0, -s );
g.lineTo( u, t );
g.lineTo( -u, t );
g.closePath();
}}
};
14 changes: 14 additions & 0 deletions src/pSymbol/x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* X */
export default {
draw: function( g, size ) { if( size > 0 ) {
let r = Math.sqrt( size / Math.PI ); // radius
let s = r * Math.PI / 2 + 0.25; // +0.25 accounts for center pixel and line width.
let t = Math.max( 1, s / Math.SQRT2 );
g.moveTo( -t, -t );
g.lineTo( t, t );
g.closePath();
g.moveTo( -t, t );
g.lineTo( t, -t );
g.closePath();
}}
};