Skip to content

Commit aa2b554

Browse files
committed
fixed camelCasing of format.kt #383. Sorry if this causes binary incompatibilities, but if we don't fix it before 1.0, we never will
1 parent 3e04d2f commit aa2b554

File tree

5 files changed

+51
-50
lines changed

5 files changed

+51
-50
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/format.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public fun <T> FormattedFrame<T>.format(): FormatClause<T, Any?> = FormatClause(
138138

139139
// endregion
140140

141-
public data class RGBColor(val r: Short, val g: Short, val b: Short)
141+
public data class RgbColor(val r: Short, val g: Short, val b: Short)
142142

143143
public interface CellAttributes {
144144

@@ -152,47 +152,47 @@ public infix fun CellAttributes?.and(other: CellAttributes?): CellAttributes? =
152152
else -> MergedAttributes(listOf(this, other))
153153
}
154154

155-
public object FormattingDSL {
156-
public fun rgb(r: Short, g: Short, b: Short): RGBColor = RGBColor(r, g, b)
155+
public object FormattingDsl {
156+
public fun rgb(r: Short, g: Short, b: Short): RgbColor = RgbColor(r, g, b)
157157

158-
public val black: RGBColor = rgb(0, 0, 0)
158+
public val black: RgbColor = rgb(0, 0, 0)
159159

160-
public val white: RGBColor = rgb(255, 255, 255)
160+
public val white: RgbColor = rgb(255, 255, 255)
161161

162-
public val green: RGBColor = rgb(0, 255, 0)
162+
public val green: RgbColor = rgb(0, 255, 0)
163163

164-
public val red: RGBColor = rgb(255, 0, 0)
164+
public val red: RgbColor = rgb(255, 0, 0)
165165

166-
public val blue: RGBColor = rgb(0, 0, 255)
166+
public val blue: RgbColor = rgb(0, 0, 255)
167167

168-
public val gray: RGBColor = rgb(128, 128, 128)
168+
public val gray: RgbColor = rgb(128, 128, 128)
169169

170-
public val darkGray: RGBColor = rgb(169, 169, 169)
170+
public val darkGray: RgbColor = rgb(169, 169, 169)
171171

172-
public val lightGray: RGBColor = rgb(211, 211, 211)
172+
public val lightGray: RgbColor = rgb(211, 211, 211)
173173

174174
public fun attr(name: String, value: String): CellAttributes = SingleAttribute(name, value)
175175

176-
public fun background(color: RGBColor): CellAttributes = attr("background-color", color.encode())
176+
public fun background(color: RgbColor): CellAttributes = attr("background-color", color.encode())
177177

178-
public fun background(r: Short, g: Short, b: Short): CellAttributes = background(RGBColor(r, g, b))
178+
public fun background(r: Short, g: Short, b: Short): CellAttributes = background(RgbColor(r, g, b))
179179

180-
public fun textColor(color: RGBColor): CellAttributes = attr("color", color.encode())
180+
public fun textColor(color: RgbColor): CellAttributes = attr("color", color.encode())
181181

182-
public fun textColor(r: Short, g: Short, b: Short): CellAttributes = textColor(RGBColor(r, g, b))
182+
public fun textColor(r: Short, g: Short, b: Short): CellAttributes = textColor(RgbColor(r, g, b))
183183

184184
public val italic: CellAttributes = attr("font-style", "italic")
185185

186186
public val bold: CellAttributes = attr("font-weight", "bold")
187187

188188
public val underline: CellAttributes = attr("text-decoration", "underline")
189189

190-
public fun linearBg(value: Number, from: Pair<Number, RGBColor>, to: Pair<Number, RGBColor>): CellAttributes =
190+
public fun linearBg(value: Number, from: Pair<Number, RgbColor>, to: Pair<Number, RgbColor>): CellAttributes =
191191
background(
192192
linear(value, from, to),
193193
)
194194

195-
public fun linear(value: Number, from: Pair<Number, RGBColor>, to: Pair<Number, RGBColor>): RGBColor {
195+
public fun linear(value: Number, from: Pair<Number, RgbColor>, to: Pair<Number, RgbColor>): RgbColor {
196196
val a = from.first.toDouble()
197197
val b = to.first.toDouble()
198198
if (a < b) return linearGradient(value.toDouble(), a, from.second, b, to.second)
@@ -257,8 +257,8 @@ public fun <T, C> FormattedFrame<T>.format(columns: ColumnsSelector<T, C>): Form
257257
public typealias CellFormatter<V> = FormattingDSL.(V) -> CellAttributes?
258258

259259
public fun <T, C : Number?> FormatClause<T, C>.linearBg(
260-
from: Pair<Number, RGBColor>,
261-
to: Pair<Number, RGBColor>,
260+
from: Pair<Number, RgbColor>,
261+
to: Pair<Number, RgbColor>,
262262
): FormattedFrame<T> =
263263
with {
264264
if (it != null) {

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/format.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package org.jetbrains.kotlinx.dataframe.impl.api
33
import org.jetbrains.kotlinx.dataframe.api.CellAttributes
44
import org.jetbrains.kotlinx.dataframe.api.FormatClause
55
import org.jetbrains.kotlinx.dataframe.api.FormattedFrame
6-
import org.jetbrains.kotlinx.dataframe.api.FormattingDSL
7-
import org.jetbrains.kotlinx.dataframe.api.RGBColor
6+
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl
7+
import org.jetbrains.kotlinx.dataframe.api.RgbColor
88
import org.jetbrains.kotlinx.dataframe.api.RowColFormatter
99
import org.jetbrains.kotlinx.dataframe.api.and
1010
import org.jetbrains.kotlinx.dataframe.api.cast
@@ -24,10 +24,10 @@ internal fun encRgb(r: Short, g: Short, b: Short): String = "#${encHex(r)}${encH
2424

2525
internal fun encHex(v: Short): String = "${(v / 16).toString(16)}${(v % 16).toString(16)}"
2626

27-
internal fun RGBColor.encode() = encRgb(r, g, b)
27+
internal fun RgbColor.encode() = encRgb(r, g, b)
2828

29-
internal fun componentWise(color1: RGBColor, color2: RGBColor, f: (Short, Short) -> Short) =
30-
RGBColor(
29+
internal fun componentWise(color1: RgbColor, color2: RgbColor, f: (Short, Short) -> Short) =
30+
RgbColor(
3131
f(color1.r, color2.r),
3232
f(color1.g, color2.g),
3333
f(color1.b, color2.b),
@@ -36,18 +36,19 @@ internal fun componentWise(color1: RGBColor, color2: RGBColor, f: (Short, Short)
3636
internal fun linearGradient(
3737
x: Double,
3838
minValue: Double,
39-
minColor: RGBColor,
39+
minColor: RgbColor,
4040
maxValue: Double,
41-
maxColor: RGBColor,
42-
): RGBColor {
41+
maxColor: RgbColor,
42+
): RgbColor {
4343
if (x < minValue) return minColor
4444
if (x > maxValue) return maxColor
4545
val t = (x - minValue) / (maxValue - minValue)
46-
return componentWise(minColor, maxColor) { cmin, cmax ->
47-
(cmin + t * (cmax - cmin)).toInt().toShort()
46+
return componentWise(minColor, maxColor) { cMin, cMax ->
47+
(cMin + t * (cMax - cMin)).toInt().toShort()
4848
}
4949
}
5050

51+
@Suppress("UNCHECKED_CAST")
5152
internal inline fun <T, C> FormatClause<T, C>.formatImpl(
5253
crossinline formatter: RowColFormatter<T, C>,
5354
): FormattedFrame<T> {
@@ -60,11 +61,11 @@ internal inline fun <T, C> FormatClause<T, C>.formatImpl(
6061
null
6162
}
6263
return FormattedFrame(df) { row, col ->
63-
val oldAttributes = oldFormatter?.invoke(FormattingDSL, row, col.cast())
64+
val oldAttributes = oldFormatter?.invoke(FormattingDsl, row, col.cast())
6465
if (columns == null || columns.contains(col.name())) {
6566
val value = row[col.name] as C
66-
if (filter == null || filter(row, value)) {
67-
oldAttributes and formatter(FormattingDSL, row.cast(), col.cast())
67+
if (filter(row, value)) {
68+
oldAttributes and formatter(FormattingDsl, row.cast(), col.cast())
6869
} else {
6970
oldAttributes
7071
}

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.jetbrains.kotlinx.dataframe.AnyFrame
66
import org.jetbrains.kotlinx.dataframe.AnyRow
77
import org.jetbrains.kotlinx.dataframe.DataFrame
88
import org.jetbrains.kotlinx.dataframe.api.FormattedFrame
9-
import org.jetbrains.kotlinx.dataframe.api.FormattingDSL
9+
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl
1010
import org.jetbrains.kotlinx.dataframe.api.RowColFormatter
1111
import org.jetbrains.kotlinx.dataframe.api.asColumnGroup
1212
import org.jetbrains.kotlinx.dataframe.api.asNumbers
@@ -186,7 +186,7 @@ internal fun AnyFrame.toHtmlData(
186186
val html =
187187
formatter.format(downsizeBufferedImageIfNeeded(value, renderConfig), cellRenderer, renderConfig)
188188
val style = renderConfig.cellFormatter
189-
?.invoke(FormattingDSL, it, col)
189+
?.invoke(FormattingDsl, it, col)
190190
?.attributes()
191191
?.ifEmpty { null }
192192
?.joinToString(";") { "${it.first}:${it.second}" }

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/JoinWith.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import kotlinx.datetime.toJavaLocalDate
88
import org.jetbrains.kotlinx.dataframe.AnyFrame
99
import org.jetbrains.kotlinx.dataframe.DataFrame
1010
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
11-
import org.jetbrains.kotlinx.dataframe.api.FormattingDSL
11+
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl
1212
import org.jetbrains.kotlinx.dataframe.api.Infer
1313
import org.jetbrains.kotlinx.dataframe.api.JoinedDataRow
14-
import org.jetbrains.kotlinx.dataframe.api.RGBColor
14+
import org.jetbrains.kotlinx.dataframe.api.RgbColor
1515
import org.jetbrains.kotlinx.dataframe.api.and
1616
import org.jetbrains.kotlinx.dataframe.api.cast
1717
import org.jetbrains.kotlinx.dataframe.api.colsOf
@@ -73,7 +73,7 @@ class JoinWith : TestBase() {
7373
LocalDate(2023, 7, 10), 2,
7474
).cast<Visits>()
7575

76-
class ColoredValue<T>(val value: T, val backgroundColor: RGBColor, val textColor: RGBColor) {
76+
class ColoredValue<T>(val value: T, val backgroundColor: RgbColor, val textColor: RgbColor) {
7777
override fun equals(other: Any?): Boolean {
7878
if (this === other) return true
7979
if (javaClass != other?.javaClass) return false
@@ -108,18 +108,18 @@ class JoinWith : TestBase() {
108108
colsAtAnyDepth().colsOf<ColoredValue<*>?>()
109109
}.with(Infer.Type) { it?.value }
110110

111-
private fun <T> T.colored(background: RGBColor, text: RGBColor) = ColoredValue(this, background, text)
111+
private fun <T> T.colored(background: RgbColor, text: RgbColor) = ColoredValue(this, background, text)
112112

113-
private fun <T> T.winter(background: RGBColor = RGBColor(179, 205, 224), text: RGBColor = RGBColor(0, 0, 51)) =
113+
private fun <T> T.winter(background: RgbColor = RgbColor(179, 205, 224), text: RgbColor = RgbColor(0, 0, 51)) =
114114
ColoredValue(this, background, text)
115115

116-
private fun <T> T.spring(background: RGBColor = RGBColor(204, 235, 197), text: RGBColor = RGBColor(0, 51, 0)) =
116+
private fun <T> T.spring(background: RgbColor = RgbColor(204, 235, 197), text: RgbColor = RgbColor(0, 51, 0)) =
117117
ColoredValue(this, background, text)
118118

119-
private fun <T> T.summer(background: RGBColor = RGBColor(176, 224, 230), text: RGBColor = RGBColor(25, 25, 112)) =
119+
private fun <T> T.summer(background: RgbColor = RgbColor(176, 224, 230), text: RgbColor = RgbColor(25, 25, 112)) =
120120
ColoredValue(this, background, text)
121121

122-
private fun <T> T.autumn(background: RGBColor = RGBColor(221, 160, 221), text: RGBColor = RGBColor(85, 26, 139)) =
122+
private fun <T> T.autumn(background: RgbColor = RgbColor(221, 160, 221), text: RgbColor = RgbColor(85, 26, 139)) =
123123
ColoredValue(this, background, text)
124124

125125
private val coloredCampaigns = dataFrameOf("name", "startDate", "endDate")(
@@ -134,7 +134,7 @@ class JoinWith : TestBase() {
134134
LocalDate(2023, 1, 10).winter(), 1.winter(),
135135
LocalDate(2023, 1, 20).winter(), 2.winter(),
136136
LocalDate(2023, 4, 15).spring(), 1.spring(),
137-
LocalDate(2023, 5, 1).colored(FormattingDSL.white, FormattingDSL.black), 3.colored(FormattingDSL.white, FormattingDSL.black),
137+
LocalDate(2023, 5, 1).colored(FormattingDsl.white, FormattingDsl.black), 3.colored(FormattingDsl.white, FormattingDsl.black),
138138
LocalDate(2023, 7, 10).summer(), 2.summer(),
139139
)
140140

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/FormattingTests.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package org.jetbrains.kotlinx.dataframe.testSets.person
22

33
import io.kotest.matchers.shouldBe
44
import io.kotest.matchers.string.shouldContain
5-
import org.jetbrains.kotlinx.dataframe.api.FormattingDSL
6-
import org.jetbrains.kotlinx.dataframe.api.FormattingDSL.gray
7-
import org.jetbrains.kotlinx.dataframe.api.FormattingDSL.green
8-
import org.jetbrains.kotlinx.dataframe.api.FormattingDSL.red
5+
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl
6+
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.gray
7+
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.green
8+
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.red
99
import org.jetbrains.kotlinx.dataframe.api.and
1010
import org.jetbrains.kotlinx.dataframe.api.colsOf
1111
import org.jetbrains.kotlinx.dataframe.api.format
@@ -33,7 +33,7 @@ class FormattingTests : BaseTest() {
3333

3434
val formatter = formattedFrame.formatter!!
3535
for (row in 0 until typed.nrow) {
36-
FormattingDSL.formatter(typed[row], typed.age)!!.attributes().size shouldBe
36+
FormattingDsl.formatter(typed[row], typed.age)!!.attributes().size shouldBe
3737
if (typed[row].age > 10) 3 else 2
3838
}
3939

@@ -48,12 +48,12 @@ class FormattingTests : BaseTest() {
4848
.formatter!!
4949

5050
for (row in 0 until typed.nrow step 2) {
51-
FormattingDSL.formatter(typed[row], typed.age)!!.attributes() shouldBe
51+
FormattingDsl.formatter(typed[row], typed.age)!!.attributes() shouldBe
5252
listOf("background-color" to gray.encode())
5353
}
5454

5555
for (row in 1 until typed.nrow step 2) {
56-
FormattingDSL.formatter(typed[row], typed.age)!!.attributes() shouldBe
56+
FormattingDsl.formatter(typed[row], typed.age)!!.attributes() shouldBe
5757
listOf("background-color" to linearGradient(typed[row].age.toDouble(), 20.0, green, 80.0, red).encode())
5858
}
5959
}

0 commit comments

Comments
 (0)