io.docops.asciidoc.buttons.ButtonMaker.kt Maven / Gradle / Ivy
/*
* Copyright 2020 The DocOps Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.docops.asciidoc.buttons
import io.docops.asciidoc.buttons.models.Button
import io.docops.asciidoc.buttons.theme.Theme
abstract class ButtonMaker {
abstract fun makeButtons(buttons: MutableList>, theme: Theme): String
protected val types = mutableMapOf()
private var startLegendHeight = 0
private fun height(
buttons: MutableList>,
heightFactor: Int,
defaultHeight: Int,
theme: Theme
): Int {
var height = defaultHeight
if (buttons.size > 1) {
height = heightFactor * buttons.size
}
if (theme.legendOn) {
startLegendHeight = height + 30
val unique = buttonTypes(buttons = buttons, theme = theme)
height += 20 * (unique.size)
height += 20
}
return height
}
private fun buttonTypes(buttons: MutableList>, theme: Theme): MutableMap {
buttons.forEach {
it.forEach { btn ->
types[theme.buttonColor(btn)] = (btn.type)
}
}
return types
}
fun makeSvgHead(
buttons: MutableList>,
heightFactor: Int = 170,
defaultHeight: Int = 250,
widthFactor: Int = 100,
theme: Theme
): String {
val height = height(buttons, heightFactor = heightFactor, defaultHeight = defaultHeight, theme = theme)
val maxWidth = theme.columns * widthFactor + theme.columns * 10
// language=svg
return """
"
}
fun drawLegend(types: MutableMap): String {
val sb = StringBuilder("")
return sb.toString()
}
}