Maker.js, a Microsoft Garage project, is a JavaScript library for creating and sharing modular line drawings for CNC and laser cutters.

View project on GitHub Star

Api - layout Namespace

Index

Functions

childrenOnChain

  • childrenOnChain(parentModel: IModel, onChain: IChain, baseline?: number, reversed?: boolean, contain?: boolean, rotated?: boolean): IModel
  • Layout the children of a model along a chain. The x-position of each child will be projected onto the chain so that the proportion between children is maintained. The projected positions of the children will become an array of points that approximate the chain. Each child will be rotated such that it will be mitered according to the vertex angles formed by this series of points.

    Parameters

    • parentModel: IModel

      The model containing children to lay out.

    • onChain: IChain

      The chain on which to lay out.

    • Default value baseline: number = 0

      Numeric percentage value of vertical displacement from the chain. Default is zero.

    • Default value reversed: boolean = false

      Flag to travel along the chain in reverse. Default is false.

    • Default value contain: boolean = false

      Flag to contain the children layout within the length of the chain. Default is false.

    • Default value rotated: boolean = true

    Returns IModel

    The parentModel, for cascading.

childrenOnPath

  • childrenOnPath(parentModel: IModel, onPath: IPath, baseline?: number, reversed?: boolean, contain?: boolean, rotate?: boolean): IModel
  • Layout the children of a model along a path. The x-position of each child will be projected onto the path so that the proportion between children is maintained. Each child will be rotated such that it will be perpendicular to the path at the child's x-center.

    Parameters

    • parentModel: IModel

      The model containing children to lay out.

    • onPath: IPath

      The path on which to lay out.

    • Default value baseline: number = 0

      Numeric percentage value of vertical displacement from the path. Default is zero.

    • Default value reversed: boolean = false

      Flag to travel along the path in reverse. Default is false.

    • Default value contain: boolean = false

      Flag to contain the children layout within the length of the path. Default is false.

    • Default value rotate: boolean = true

      Flag to rotate the child to perpendicular. Default is true.

    Returns IModel

    The parentModel, for cascading.

cloneToBrick

  • Layout clones in a brick format. Alternating rows will have an additional item in each row.

    Examples:

    //Brick wall
    var m = require('makerjs');
    var brick = new m.models.RoundRectangle(50, 30, 4);
    var wall = m.layout.cloneToBrick(brick, 8, 6, 3);
    document.write(m.exporter.toSVG(wall));
    
    //Fish scales
    var m = require('makerjs');
    var arc = new m.paths.Arc([0, 0], 50, 20, 160);
    var scales = m.layout.cloneToBrick(arc, 8, 20);
    document.write(m.exporter.toSVG(scales));
    

    Parameters

    • itemToClone: IModel | IPath
    • xCount: number

      Number of columns in the brick grid.

    • yCount: number

      Number of rows in the brick grid.

    • Optional margin: number | IPoint

      Optional numeric distance between each clone. Can also be a 2 dimensional array of numbers, to specify distances in x and y dimensions.

    Returns IModel

    A new model with clones in a brick layout.

cloneToColumn

  • Layout clones in a column format.

    Example:

    //Grooves for a finger joint
    var m = require('makerjs');
    
    var dogbone = new m.models.Dogbone(50, 20, 2, -1, false);
    
    var grooves = m.layout.cloneToColumn(dogbone, 5, 20);
    
    document.write(m.exporter.toSVG(grooves));
    

    Parameters

    • itemToClone: IModel | IPath
    • count: number

      Number of clones in the column.

    • Default value margin: number = 0

      Optional distance between each clone.

    Returns IModel

    A new model with clones in a column.

cloneToGrid

  • Layout clones in a grid format.

    Example:

    //Grid of squares
    var m = require('makerjs');
    var square = new m.models.Square(43);
    var grid = m.layout.cloneToGrid(square, 5, 5, 7);
    document.write(m.exporter.toSVG(grid));
    

    Parameters

    • itemToClone: IModel | IPath
    • xCount: number

      Number of columns in the grid.

    • yCount: number

      Number of rows in the grid.

    • Optional margin: number | IPoint

      Optional numeric distance between each clone. Can also be a 2 dimensional array of numbers, to specify distances in x and y dimensions.

    Returns IModel

    A new model with clones in a grid layout.

cloneToHoneycomb

  • cloneToHoneycomb(itemToClone: IModel | IPath, xCount: number, yCount: number, margin?: number): IModel
  • Layout clones in a honeycomb format. Alternating rows will have an additional item in each row.

    Examples:

    //Honeycomb
    var m = require('makerjs');
    var hex = new m.models.Polygon(6, 50, 30);
    var pattern = m.layout.cloneToHoneycomb(hex, 8, 9, 10);
    document.write(m.exporter.toSVG(pattern));
    

    Parameters

    • itemToClone: IModel | IPath
    • xCount: number

      Number of columns in the honeycomb grid.

    • yCount: number

      Number of rows in the honeycomb grid.

    • Default value margin: number = 0

      Optional distance between each clone.

    Returns IModel

    A new model with clones in a honeycomb layout.

cloneToRadial

  • cloneToRadial(itemToClone: IModel | IPath, count: number, angleInDegrees: number, rotationOrigin?: IPoint): IModel
  • Layout clones in a radial format.

    Example:

    //daisy petals
    var makerjs = require('makerjs');
    
    var belt = new makerjs.models.Belt(5, 50, 20);
    
    makerjs.model.move(belt, [25, 0]);
    
    var petals = makerjs.layout.cloneToRadial(belt, 8, 45);
    
    document.write(makerjs.exporter.toSVG(petals));
    

    Parameters

    • itemToClone: IModel | IPath
    • count: number

      Number of clones in the radial result.

    • angleInDegrees: number

      angle of rotation between clones..

    • Optional rotationOrigin: IPoint

    Returns IModel

    A new model with clones in a radial format.

cloneToRow

  • Layout clones in a row format.

    Example:

    //Tongue and grooves for a box joint
    var m = require('makerjs');
    var tongueWidth = 60;
    var grooveWidth = 50;
    var grooveDepth = 30;
    var groove = new m.models.Dogbone(grooveWidth, grooveDepth, 5, 0, true);
    
    groove.paths['leftTongue'] = new m.paths.Line([-tongueWidth / 2, 0], [0, 0]);
    groove.paths['rightTongue'] = new m.paths.Line([grooveWidth, 0], [grooveWidth + tongueWidth / 2, 0]);
    
    var tongueAndGrooves = m.layout.cloneToRow(groove, 3);
    
    document.write(m.exporter.toSVG(tongueAndGrooves));
    

    Parameters

    • itemToClone: IModel | IPath
    • count: number

      Number of clones in the row.

    • Default value margin: number = 0

      Optional distance between each clone.

    Returns IModel

    A new model with clones in a row.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc