Difference between revisions of "Diagrams/Dev/Migrate1.2"

From HaskellWiki
< Diagrams‎ | Dev
Jump to navigation Jump to search
(write about removal of freeze)
(Too many simple markup syntaxes confuse me)
 
(10 intermediate revisions by 4 users not shown)
Line 3: Line 3:
 
== Attributes using Measure ==
 
== Attributes using Measure ==
   
<code>LineWidth</code> is now specified using <code>Measure</code>. This replaces former uses of <code>freeze</code>. See [http://projects.haskell.org/diagrams/doc/manual.html the manual] for full details. The old behavior of <code>lw</code> (in diagrams not using <code>freeze</code>) can be had by using <code>lwL</code>.
+
Many distances are now specified using values of type <code>Measure</code>. See the [http://projects.haskell.org/diagrams/doc/manual.html#measurement-units user manual] for full details. The most noticeable effects of this change in porting diagrams code to 1.2 will be type errors on uses of attribute functions like <code>lw</code>, <code>dashing</code>, and <code>fontSize</code>.
   
However, in many simple cases, we recommend instead using named line weights provided in <code>Diagrams.TwoD.Attributes</code>. These include <code>thin</code>, <code>thick</code, and <code>none</code>.
+
* To simply retain the existing behavior, replace <code>lw</code> with <code>lwG</code>, <code>dashing</code> with <code>dashingG</code>, and <code>fontSize</code> with <code>fontSizeL</code>.
  +
* In many cases, you can simply remove calls to <code>lw</code>, since the default behavior is much more sensible. You can also use the named line weights provided in <code>Diagrams.TwoD.Attributes</code>: <code>none</code>, <code>ultraThin</code>, <code>veryThin</code>, <code>thin</code>, <code>medium</code>, <code>thick</code>, <code>veryThick</code>, or <code>ultraThick</code>. For example, replace <code>lw 0</code> with <code>lw none</code>, and replace (say) <code>lw 0.2</code> with <code>lw veryThick</code> (though note that the relationship between the number used previously and the proper choice of line weight depends on the context, because the old semantics was not very sensible).
  +
* While we think the new default line weight will work for more people more of the time, diagrams which used the old default will compile without error and may render quite differently. You can express the old default as <code>lwG 0.01</code>, or add <code>lw</code> with the named line weights as necessary.
   
 
== Removal of <code>freeze</code> ==
 
== Removal of <code>freeze</code> ==
Line 16: Line 18:
 
== Arrows ==
 
== Arrows ==
   
  +
=== Head and tail size ===
The size of arrow heads and tails is now specified in terms of length instead of the radius of their circumcircle.
 
   
  +
The size of arrow heads and tails is now specified in terms of length instead of the radius of their circumcircle. In addition, the lengths are specified using <code>Measure</code>. For convenience, aliases <code>tiny</code>, <code>verySmall</code>, <code>small</code>, <code>normal</code>, <code>large</code>, <code>veryLarge</code>, and <code>huge</code> have been provided. For example,
Gaps at the ends of arrows are now specified using <code>Measure R2</code>.
 
   
  +
<code> ... & headSize .~ 0.7</code>
The <code>gap</code> traversal has been replaced by `gaps` for consistency in naming, though <code>gap</code> is still provided for backwards compatibility.
 
  +
  +
might be replaced with
  +
  +
<code> ... & headLength .~ large</code>
  +
  +
=== Gaps ===
  +
 
Gaps at the ends of arrows are also specified using <code>Measure R2</code>. Also, the <code>gap</code> traversal has been replaced by <code>gaps</code> for consistency in naming, though <code>gap</code> is still provided for backwards compatibility. For example, replace
  +
  +
<code> ... & gap .~ 1</code>
  +
  +
by
  +
  +
<code> ... & gaps .~ Local 1</code>
  +
  +
=== Head and tail color ===
  +
  +
The lenses <code>headColor</code> and <code>tailColor</code> have been replaced by <code>headTexture</code> and <code>tailTexture</code>. These can now handle more general textures, ''e.g.'' gradients. To get a solid color, use the <code>solid</code> function, e.g. replace
  +
  +
<code> ... & headColor blue</code>
  +
  +
by
  +
  +
<code> ... & headTexture (solid blue)</code>
  +
  +
== Images ==
  +
If you were using the cairo backend to include PNG images in your diagrams then you will need to make some small changes to your code using the new Image API. Diagrams now distinguishes between external and embedded images, cairo (as it has done in previous versions) only supports external images.
  +
For example if you were creating a diagram from a PNG called "myImage.png" using
  +
  +
<code>image "~/myImage.png" 1 1</code>
  +
  +
then you can replace it with
  +
  +
<code>image (uncheckedImageRef "~/myImage.png" 1 1)</code>
  +
  +
and get exactly the same behavior as with 1.1. Additionally, you can now create a "checked" external image with the function <code>loadImageExt</code> which will utilize the Juicy Pixels library to make sure the image exists and calculate its dimension so you don't need to provide a width and height. See the [http://projects.haskell.org/diagrams/doc/manual.html#images user manual] for full details
   
 
== Reorganization ==
 
== Reorganization ==
   
  +
These changes will not affect most users, but are listed here for completeness.
The <code>avgScale</code> function has been moved from <code>Diagrams.TwoD.Transform</code> to <code>Diagrams.Core.Transform</code>.
 
  +
 
* The <code>avgScale</code> function has been moved from <code>Diagrams.TwoD.Transform</code> to <code>Diagrams.Core.Transform</code>.
   
Most (all?) 2D attributes have been moved from <code>Diagrams.Attributes</code> to <code>Diagrams.TwoD.Attributes</code>.
+
* Most 2D attributes have been moved from <code>Diagrams.Attributes</code> to <code>Diagrams.TwoD.Attributes</code>.
   
The <code>Angle</code> definition and related functions have moved to a separate module, <code>Diagrams.Angle</code>.
+
* The <code>Angle</code> definition and related functions have moved to a separate module, <code>Diagrams.Angle</code>.

Latest revision as of 19:36, 30 June 2014

This page describes breaking API changes between diagrams 1.1 and 1.2, along with explanations of how to migrate to the new 1.2 API.

Attributes using Measure

Many distances are now specified using values of type Measure. See the user manual for full details. The most noticeable effects of this change in porting diagrams code to 1.2 will be type errors on uses of attribute functions like lw, dashing, and fontSize.

  • To simply retain the existing behavior, replace lw with lwG, dashing with dashingG, and fontSize with fontSizeL.
  • In many cases, you can simply remove calls to lw, since the default behavior is much more sensible. You can also use the named line weights provided in Diagrams.TwoD.Attributes: none, ultraThin, veryThin, thin, medium, thick, veryThick, or ultraThick. For example, replace lw 0 with lw none, and replace (say) lw 0.2 with lw veryThick (though note that the relationship between the number used previously and the proper choice of line weight depends on the context, because the old semantics was not very sensible).
  • While we think the new default line weight will work for more people more of the time, diagrams which used the old default will compile without error and may render quite differently. You can express the old default as lwG 0.01, or add lw with the named line weights as necessary.

Removal of freeze

The freeze function has been removed. Most users probably were not using it; if you were, you have several options for replacing it, depending on how you were using it:

  • If you were just using it to get some lines to scale along with a diagram, use a Local line width (e.g. ... # lw (Local 2) or ... # lwL 2).
  • The above will not work if you were doing non-uniform scaling and really care that the lines should come out looking squished and stretched. In that case, use functions in Diagrams.TwoD.Offset to create a path corresponding to the stroked line, and then fill and transform it normally.

Arrows

Head and tail size

The size of arrow heads and tails is now specified in terms of length instead of the radius of their circumcircle. In addition, the lengths are specified using Measure. For convenience, aliases tiny, verySmall, small, normal, large, veryLarge, and huge have been provided. For example,

... & headSize .~ 0.7

might be replaced with

... & headLength .~ large

Gaps

Gaps at the ends of arrows are also specified using Measure R2. Also, the gap traversal has been replaced by gaps for consistency in naming, though gap is still provided for backwards compatibility. For example, replace

... & gap .~ 1

by

... & gaps .~ Local 1

Head and tail color

The lenses headColor and tailColor have been replaced by headTexture and tailTexture. These can now handle more general textures, e.g. gradients. To get a solid color, use the solid function, e.g. replace

... & headColor blue

by

... & headTexture (solid blue)

Images

If you were using the cairo backend to include PNG images in your diagrams then you will need to make some small changes to your code using the new Image API. Diagrams now distinguishes between external and embedded images, cairo (as it has done in previous versions) only supports external images. For example if you were creating a diagram from a PNG called "myImage.png" using

image "~/myImage.png" 1 1

then you can replace it with

image (uncheckedImageRef "~/myImage.png" 1 1)

and get exactly the same behavior as with 1.1. Additionally, you can now create a "checked" external image with the function loadImageExt which will utilize the Juicy Pixels library to make sure the image exists and calculate its dimension so you don't need to provide a width and height. See the user manual for full details

Reorganization

These changes will not affect most users, but are listed here for completeness.

  • The avgScale function has been moved from Diagrams.TwoD.Transform to Diagrams.Core.Transform.
  • Most 2D attributes have been moved from Diagrams.Attributes to Diagrams.TwoD.Attributes.
  • The Angle definition and related functions have moved to a separate module, Diagrams.Angle.