github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/elm/src/Dashboard/PipelineGrid/Layout.elm (about)

     1  module Dashboard.PipelineGrid.Layout exposing (Card, cardSize, layout)
     2  
     3  
     4  type alias GridSpan =
     5      Int
     6  
     7  
     8  type alias Card =
     9      { spannedColumns : GridSpan
    10      , spannedRows : GridSpan
    11      , column : Int
    12      , row : Int
    13      }
    14  
    15  
    16  countToSpan : Int -> GridSpan
    17  countToSpan count =
    18      if count > 24 then
    19          3
    20  
    21      else if count > 12 then
    22          2
    23  
    24      else
    25          1
    26  
    27  
    28  cardSize : ( Int, Int ) -> ( GridSpan, GridSpan )
    29  cardSize ( w, h ) =
    30      ( countToSpan w
    31      , countToSpan h
    32      )
    33  
    34  
    35  layout : Int -> List ( GridSpan, GridSpan ) -> List Card
    36  layout numColumns cardSizes =
    37      cardSizes
    38          |> List.foldl
    39              (\( w, h ) { cards, column, row, rowHeight } ->
    40                  let
    41                      breaksRow =
    42                          (column + w > numColumns + 1)
    43                              && (column /= 1)
    44  
    45                      newColumn =
    46                          if breaksRow then
    47                              1
    48  
    49                          else
    50                              column
    51  
    52                      newRow =
    53                          if breaksRow then
    54                              row + rowHeight
    55  
    56                          else
    57                              row
    58  
    59                      newRowHeight =
    60                          if breaksRow then
    61                              h
    62  
    63                          else
    64                              max rowHeight h
    65                  in
    66                  { cards = { spannedColumns = w, spannedRows = h, column = newColumn, row = newRow } :: cards
    67                  , column = newColumn + w
    68                  , row = newRow
    69                  , rowHeight = newRowHeight
    70                  }
    71              )
    72              { cards = [], column = 1, row = 1, rowHeight = 1 }
    73          |> .cards
    74          |> List.reverse