Skip to content
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
preattentive symbols
Symbols with preattentive features aid pattern detection and reduce overlap.  This symbol set implements ideas of Cleveland, Wilkinson, and others, and has been tested for popularity and discriminability, and adjusted for approximately equal weight.

Many products support up to a dozen different symbol sets.  This is analogous to multiple color schemes, such as Dr. Cindy Brewer's recently supported in d3.

Not knowing d3's plans for symbol sets, I've only made a bare attempt at integrating these, but would be happy to continue this work along whatever lines are appropriate.
  • Loading branch information
hemanrobinson committed Mar 28, 2021
commit 953dd74db0894613fe439d100767d09372d12733
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();
}}
};