shpsec-blaisep / canviz

Automatically exported from code.google.com/p/canviz
0 stars 0 forks source link

Path should have a draw() method that actually draws the path #53

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Currently, Path has a draw() method that merely constructs the path on the 
canvas context, and it's 
still up to the user of Path to beginPath() before and fill() and/or stroke() 
after.

The existing draw() (and drawDashed() and drawDotted()) methods should be 
renamed to something 
better matching their purpose. Then a new draw() method should be created which 
actually draws 
(fills and/or strokes) the path. The drawPath() method in Canviz could be the 
starting point for 
Path's new draw() method. The Path class will need to gain a place to store the 
context attributes 
that are important to it, such as stroke style (color string or gradient or 
pattern); fill style; line 
width; line cap; etc. This could be implemented as a settings object which 
directly maps to variables 
in the context (e.g. strokeStyle, fillStyle, lineWidth, lineCap). Path could 
further infer that if you set 
strokeStyle, you would like the path to be stroked, and if you set fillStyle, 
you would like the path to 
be filled.

That leaves the parameters for dashed and dotted lines, for which there are no 
context variable 
since this feature is unique to Path. The needed parameters include whether to 
draw solid, dashed 
or dotted lines; the dash or dot spacing; the distance to the first dot or dash 
("firstDistance"), and 
(for dashed lines) whether the first section of line is drawn or skipped 
("drawFirst"). The latter two 
would be optional and would probably not be used much in practice (they aren't 
used by Canviz), 
but Path does need to keep track of them for properly drawing paths composed of 
multiple 
segments, and example 1 sets them directly to animate the dashed and dotted 
lines. These custom 
properties could also be stored in the same settings object but with special 
names that Path knows 
to look for and handle itself. Possibly these keys should be prefixed with "x" 
or "x_" to indicate they 
are eXperimental and not part of the spec.

Original issue reported on code.google.com by ryandesi...@gmail.com on 19 May 2009 at 11:46

GoogleCodeExporter commented 8 years ago
r262: Renamed draw => makePath, drawDotted => makeDottedPath, drawDashed => 
makeDashedPath, 
drawCommands => pathCommands.

Original comment by ryandesi...@gmail.com on 19 May 2009 at 11:57

GoogleCodeExporter commented 8 years ago
r265: Updated Canviz to take these changes into account.

Original comment by ryandesi...@gmail.com on 19 May 2009 at 1:35

GoogleCodeExporter commented 8 years ago
r269: Path now has a draw() method that actually draws. Path constructors now 
take an
optional argument options, where you can specify anything that could apply to a
context, and also the "x_" options that are unique to Path:

  * x_fill (do you want it filled? default: false)
  * x_stroke (do you want it stroked? default: true)
  * x_strokeType ('solid' (default), 'dashed' or 'dotted')
  * x_dashLength (for dashed strokes; default: 6, measured in pixels)
  * x_dotSpacing (for dotted strokes; default: 4, measured in pixels)

The defaults for dash length and dot spacing may change. I opted not to do 
anything
clever, so if you want a Path filled, you do have to set both x_fill and 
(unless you
want black) fillStyle.

Original comment by ryandesi...@gmail.com on 24 May 2009 at 5:43

GoogleCodeExporter commented 8 years ago
firstDistance and drawFirst have not been dealt with, but I can add those later 
if
necessary.

Original comment by ryandesi...@gmail.com on 24 May 2009 at 6:33