public class Symbol extends PathDataGenerator
PathDataGenerator
generating symbols shapes.
While the default accessors generate static symbols, it is common to set one or more of the accessors using a
function, such as setting the size proportional to a dimension of data for a scatterplot. The returned function
generates path data for various symbols (see Symbol.Type
for all the symbols).
Note that the symbol does not include accessors for x and y. Instead, you can use the path element's transform attribute to position the symbols, as in:
vis.selectAll("path") .data(data) .enter().append("path") .attr("transform", function(d) { return "translate(" + x(d.x) + "," + y(d.y) + ")"; }) .attr("d", d3.svg.symbol());In the future, we may add x- and y-accessors for parity with the line and area generators. The symbol will be centered at the origin (0,0) of the local coordinate system. You can also use SVG's built-in basic shapes to produce many of these symbol types, though D3's symbol generator is useful in conjunction with path elements because you can easily change the symbol type and size as a function of data.
Modifier and Type | Class and Description |
---|---|
static class |
Symbol.Type
Shape of the symbol.
|
Modifier | Constructor and Description |
---|---|
protected |
Symbol()
Constructs a new symbol generator with the default type- and
size-accessor functions (that make no assumptions about input data, and
produce a circle sized 64 square pixels).
|
Modifier and Type | Method and Description |
---|---|
Symbol |
size(DatumFunction<Integer> sizeAccessorFunction)
Set the size of the symbols using the specified function returning an
integer.
|
Symbol |
size(int sizeInSquarePixels)
Set the size of the symbols.
|
Symbol |
type(DatumFunction<Symbol.Type> typeAccessorFunction)
Set the type of the symbol using the specified function returning a
DragEventType.
|
Symbol |
type(Symbol.Type type)
Set the type of the symbol using the specified
Drag.DragEventType constant. |
generate, generate, generate, generate
protected Symbol()
public final Symbol type(Symbol.Type type)
Drag.DragEventType
constant.
The default type is DragEventType#CIRCLE
.
type
- public final Symbol type(DatumFunction<Symbol.Type> typeAccessorFunction)
typeAccessorFunction
- the function that return the Drag.DragEventType
of symbol.public final Symbol size(int sizeInSquarePixels)
The default size is 64.
sizeInSquarePixels
- the size in square pixelspublic final Symbol size(DatumFunction<Integer> sizeAccessorFunction)
sizeAccessorFunction
- the function that return the Drag.DragEventType
of symbol.Copyright © 2015 gwt-d3. All rights reserved.