Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime format support in tooltips #421

Merged
merged 8 commits into from
Aug 18, 2021
Prev Previous commit
Next Next commit
Minor code cleanup.
  • Loading branch information
OLarionova-HORIS committed Aug 16, 2021
commit b853796dcaa8d2b3bb7005178098a394f946ed8c
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,10 @@ class StringFormat private constructor(

fun forNArgs(
pattern: String,
type: FormatType? = null,
argCount: Int,
formatFor: String? = null
): StringFormat {
return create(pattern, type, formatFor, argCount)
return create(pattern, STRING_FORMAT, formatFor, argCount)
}

private fun detectFormatType(pattern: String): FormatType {
Expand All @@ -154,7 +153,7 @@ class StringFormat private constructor(
}
}

fun create(
internal fun create(
pattern: String,
type: FormatType? = null,
formatFor: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class ScaleProviderBuilder<T>(private val aes: Aes<T>) {
with.labels(myLabels)
}
if (myLabelFormat != null) {
with.labelFormatter(StringFormat.create(myLabelFormat)::format)
with.labelFormatter(StringFormat.forOneArg(myLabelFormat)::format)
}
if (myMultiplicativeExpand != null) {
with.multiplicativeExpand(myMultiplicativeExpand)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ConstantValue(
) : ValueSource {

private val myDataValue = if (format != null) {
StringFormat.create(format).format(value)
StringFormat.forOneArg(format).format(value)
} else {
value.toString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ class DataFrameValue(
private lateinit var myDataFrame: DataFrame
private lateinit var myVariable: DataFrame.Variable
private val myFormatter = format?.let {
// StringFormat(format).also {
// require(it.argsNumber == 1) { "Wrong number of arguments in pattern \'$format\' to format \'$name\'. Expected 1 argument instead of ${it.argsNumber}" }
// }
StringFormat.forOneArg(format, formatFor = name)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ class MappingValue(
private lateinit var myDataAccess: MappedDataAccess
private var myDataLabel: String? = null
private val myFormatter = format?.let {
// StringFormat(format).also {
// require(it.argsNumber == 1) { "Wrong number of arguments in pattern \'$format\' to format \'${aes.name}\'. Expected 1 argument instead of ${it.argsNumber}" }
// }
StringFormat.forOneArg(format, formatFor = aes.name)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ class TooltipLine(
) : TooltipLineSpec {
constructor(other: TooltipLine) : this(other.label, other.pattern, other.fields.map(ValueSource::copy))

// private val myLineFormatter = StringFormat(pattern, STRING_FORMAT).also {
// require(it.argsNumber == fields.size) { "Wrong number of arguments in pattern \'$pattern\' to format fields. Expected ${fields.size} arguments instead of ${it.argsNumber}" }
// }
private val myLineFormatter = StringFormat.forNArgs(pattern, STRING_FORMAT, fields.size, "fields")
private val myLineFormatter = StringFormat.forNArgs(pattern, fields.size, "fields")

fun initDataContext(dataContext: DataContext) {
fields.forEach { it.initDataContext(dataContext) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ internal class FacetConfig(options: Map<String, Any>) : OptionsAccessor(options)
return when (optionVal) {
null -> DEF_FORMATTER
else -> {
val fmt = StringFormat.create(optionVal.toString())
val fmt = StringFormat.forOneArg(optionVal.toString())
return { value: Any -> fmt.format(value) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ class GeomProtoClientSide(geomKind: GeomKind) : GeomProto(geomKind) {

if (labelFormat != null) {
geom.formatter = StringFormat.forOneArg(labelFormat)
// require(geom.formatter!!.argsNumber == 1) {
// "Wrong number of arguments in pattern \'$labelFormat\' to format label. Expected 1 argument instead of ${geom.formatter!!.argsNumber}"
// }
} else {
throw IllegalArgumentException("Expected: label_format = 'format string'")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class ScaleConfig<T>(options: Map<String, Any>) : OptionsAccessor(options) {

if (getBoolean(Option.Scale.DATE_TIME)) {
val dateTimeFormatter = getString(FORMAT)?.let { pattern ->
val stringFormat = StringFormat.create(pattern, type = DATETIME_FORMAT)
val stringFormat = StringFormat.forOneArg(pattern, type = DATETIME_FORMAT)
return@let { value: Any -> stringFormat.format(value) }
}
b.breaksGenerator(DateTimeBreaksGen(dateTimeFormatter))
Expand Down