Skip to content

Commit

Permalink
Merge pull request #7 from ivanfrolovmd/fix-width-calc-2
Browse files Browse the repository at this point in the history
Fix width calculations
  • Loading branch information
ivanfrolovmd committed Jul 27, 2018
2 parents 1a450f9 + 737a6aa commit 6a99fab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ allprojects {
}
dependencies {
compile 'com.github.ivanfrolovmd:asciitable:0.0.4'
compile 'com.github.ivanfrolovmd:asciitable:0.0.5'
}
```

Expand All @@ -52,12 +52,12 @@ dependencies {
<dependency>
<groupId>com.github.ivanfrolovmd</groupId>
<artifactId>asciitable</artifactId>
<version>0.0.4</version>
<version>0.0.5</version>
</dependency>
```

### SBT
```
resolvers += "jitpack" at "https://jitpack.io"
libraryDependencies += "com.github.ivanfrolovmd" % "asciitable" % "0.0.4"
libraryDependencies += "com.github.ivanfrolovmd" % "asciitable" % "0.0.5"
```
10 changes: 5 additions & 5 deletions src/main/scala/io/github/asciitable/AsciiTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package io.github.asciitable
import java.io.{ByteArrayOutputStream, PrintWriter}

import io.github.asciitable.AsciiTable._
import io.github.asciitable.Maths._

import scala.collection.immutable.Stream.StreamBuilder
import Maths._

import scala.language.postfixOps

class AsciiTable {
Expand Down Expand Up @@ -134,9 +133,10 @@ class AsciiTable {
.foldLeft((Seq.empty[(Int, Int)], availableWidth, 1.0)) {
// calculate actual apportioned widths
case ((ws, avWidth, avRatio), ((colRatio, colMax), ix)) =>
val proportionalWidth = if (avRatio > 0) Math.ceil(avWidth * colRatio / avRatio).toInt else 0
val minWidth = columnMinWidth min colMax
val actualWidth = proportionalWidth max minWidth
val proportionalWidth =
if (avRatio > 0 && avWidth > 0) Math.floor(avWidth * colRatio / avRatio).toInt else 0
val minWidth = columnMinWidth min (1 max colMax)
val actualWidth = proportionalWidth max minWidth
(ws :+ (actualWidth, ix), avWidth - actualWidth, avRatio - colRatio)
}
._1
Expand Down

0 comments on commit 6a99fab

Please sign in to comment.