Skip to content

Commit

Permalink
fixed timeline zoom (fixed #54)
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerbrandl committed Nov 4, 2023
1 parent eefc65a commit 5ac787b
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 23 deletions.
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ dependencies {
api("io.github.oshai:kotlin-logging-jvm:5.1.0")

testImplementation("org.jetbrains.kotlin:kotlin-test-junit:1.9.20")
testImplementation("io.kotest:kotest-assertions-core:\t5.7.2")
testImplementation("io.kotest:kotest-assertions-core:5.7.2")

// **TODO** move to api to require users to pull it in if needed
implementation("com.github.holgerbrandl:krangl:0.18.4") // must needed for kravis
implementation("com.github.holgerbrandl:kdfutils:1.2")
testImplementation("com.github.holgerbrandl:kdfutils:1.2")
implementation("com.github.holgerbrandl:kdfutils:1.3.3")
testImplementation("com.github.holgerbrandl:kdfutils:1.3.3")

compileOnly("com.github.holgerbrandl:kravis:0.9.95")
testImplementation("com.github.holgerbrandl:kravis:0.9.95")
compileOnly("com.github.holgerbrandl:kravis:0.9.96")
testImplementation("com.github.holgerbrandl:kravis:0.9.96")

compileOnly("org.jetbrains.lets-plot:lets-plot-kotlin-jvm:4.4.3")
testImplementation("org.jetbrains.lets-plot:lets-plot-batik:4.0.1")
Expand Down
1 change: 1 addition & 0 deletions docs/userguide/docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Minor improvements
* [#56](https://github.com/holgerbrandl/kalasim/issues/56) Improved support for [duration distributions](basics.md#duration-distributions)
* Expose `Environment.getOrNull<T>()` from [koin](https://github.com/InsertKoinIO/koin/issues/182) to check for presence of registered dependencies in simulation environment
* [#46](https://github.com/holgerbrandl/kalasim/issues/46) clarify use of collect with filter
* [#52](https://github.com/holgerbrandl/kalasim/issues/54) Improved visualization of metric timelines to support zoom range

Starting with this release we have switched to calendar versioning for better clarity regarding our release density, timing and schedule.

Expand Down
2 changes: 1 addition & 1 deletion docs/userguide/docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MyEvent(time : SimTime) : Event(time)
// run the sim which create many events including some MyEvents
env.run()

val myEvents :List<MyEvent> = collect<MyEvent>()
val myEvents : List<MyEvent> = collect<MyEvent>()

// or collect with an additional filter condition
val myFilteredEvents :List<MyEvent> = collect<MyEvent> {
Expand Down
12 changes: 0 additions & 12 deletions src/main/kotlin/org/kalasim/plot/kravis/KravisVis.kt
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,3 @@ internal fun List<Component>.clistTimeline() = flatMap { eqn ->
.statsData().asList().map { eqn to it }
}



// todo move to kravis library
fun GGPlot.showFile() {
val file = Files.createTempFile("kravis" + Instant.now().toString().replace(":", ""), ".png")

save(file, Dimension(1000, 800))

Desktop.getDesktop().open(file.toFile())
}


Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package org.kalasim.scratch.callcenter
import kravis.GGPlot
import kravis.SessionPrefs
import kravis.device.SwingPlottingDevice
import kravis.device.showFile
import org.kalasim.*
import org.kalasim.plot.kravis.display
import org.kalasim.plot.kravis.showFile
import java.awt.Desktop
import java.awt.Dimension
import java.nio.file.Files
Expand Down
19 changes: 15 additions & 4 deletions src/test/kotlin/org/kalasim/test/DisplayTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package org.kalasim.test
import io.kotest.assertions.fail
import kravis.GGPlot
import kravis.SessionPrefs
import kravis.device.showFile
import kravis.render.LocalR
import org.junit.*
import org.junit.Assert.assertEquals
import org.junit.rules.TestName
import org.kalasim.asSimTime
import org.kalasim.examples.MM1Queue
import org.kalasim.misc.AmbiguousDuration
import org.kalasim.plot.kravis.*
Expand All @@ -27,18 +29,27 @@ class DisplayTests : AbstractSvgPlotRegression() {
fun beforeMethod() {
// Only run tests that rely on for brandl or if users has exported KALASIM_RUN_DISPLAY_TESTS as 'true'
// https://stackoverflow.com/questions/1689242/conditionally-ignoring-tests-in-junit-4
val runDisplaytests =
val runDisplayTests =
System.getProperty("KALASIM_RUN_DISPLAY_TESTS").toBoolean() || System.getProperty("user.name") == "brandl"
Assume.assumeTrue(runDisplaytests);
Assume.assumeTrue(runDisplayTests)
}

@OptIn(AmbiguousDuration::class)
@Test
fun `is should display the mm1 server utilization`() {
val mm1 = MM1Queue()

mm1.run(50.minutes)
// mm1.customers

mm1.server.requesters.queueLengthTimeline
.display("Trimmed queue timeline", mm1.asSimTime(5), mm1.asSimTime(10))
// .showFile()
.apply {
assertExpected(this, "trimmed_queue_timeline")
}


// USE_KRAVIS_VIEWER = true

// mm1.server.activities.display("MM1 Server Utilization")
Expand Down Expand Up @@ -71,7 +82,6 @@ class DisplayTests : AbstractSvgPlotRegression() {

}

@OptIn(AmbiguousDuration::class)
@Test
fun `is should display the mm1 server utilization with walltime`() {

Expand Down Expand Up @@ -139,7 +149,8 @@ abstract class AbstractSvgPlotRegression {
// note assertEquals would be cleaner but since its printing the complete diff, it's polluting the travis logs
assertEquals(expected, svgDoc)
val failMsg = "svg mismatch got:\n${svgDoc.lines().take(30).joinToString("\n")}"
Assert.assertTrue(failMsg, expected.equals(svgDoc))
@Suppress("HttpUrlsUsage")
Assert.assertTrue(failMsg, expected == svgDoc)

// compare actual images
// saveImage(File(testDataDir, name.methodName.replace(" ", "_") + ".png"))
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5ac787b

Please sign in to comment.