import io.data2viz.charts.*
import io.data2viz.charts.core.Padding
import io.data2viz.charts.core.*
import io.data2viz.charts.dimension.*
import io.data2viz.charts.chart.*
import io.data2viz.charts.chart.mark.*
import io.data2viz.charts.viz.*
import io.data2viz.charts.layout.*
import io.data2viz.charts.config.configs.*
import io.data2viz.geom.*
private val width = 600.0
private val height = 400.0
fun main() {
val vc = newVizContainer().apply {
size = Size(width, height)
}
vc.chart(breaches) {
title = "Cybersecurity breaches on the US Dep. of HHS"
config {
title {
padding = Padding(5.0, 5.0, 8.0, 5.0)
}
}
val maxCount = breaches.maxOf { it.cumulativeCount }
val typeDim = discrete({domain.type}) {
name = "Type of breach"
}
val countDim = quantitative({domain.count.toDouble()}) {
name = "Count"
}
val percentDim = quantitative({100 * domain.cumulativeCount.toDouble() / maxCount}) {
name = "Cumulative count"
formatter = { "${this.formatToInteger()}%" }
}
bar(typeDim, countDim) {
y {
end = 700.0
}
}
line(typeDim, percentDim) {
strokeWidth = constant(2.0)
showMarkers = true
y {
layoutPosition = LayoutPosition.Right
start = .0
end = 100.0
}
}
}
}
data class Breach(val type: String, val count: Int, val cumulativeCount: Int)
// Since October 2009 organizations in the U.S. that store data on human health are
// required to report any incident that compromises the confidentiality of 500 or more
// patients / human subjects (45 C.F.R. 164.408) These reports are publicly available.
// HHSCyberSecurityBreaches was downloaded from the Office for Civil Rights of the U.S.
// Department of Health and Human Services, 2015-02-26
val breaches = listOf(
Breach("Theft", 633, 633),
Breach("Loss", 111, 744),
Breach("Other", 111, 855),
Breach("IT Incident", 94, 949),
Breach("Improp. Disp.", 51, 1000),
Breach("Unknown", 16, 1016),
Breach("Unauthorized", 1, 1017)
)