SciProgCentre / dataforge-core

A clean multi-platform re-implementation of dataforge concepts
Apache License 2.0
25 stars 3 forks source link

NumberList delegate does not work with empty lists #12

Closed altavir closed 5 years ago

altavir commented 5 years ago

Code:

    val x = emptyList<Double>()
    val y = emptyList<Double>()
    val plot = Plotly.plot2D {
        trace(x, y) {
            name = "for a single trace in graph its name would be hidden"
        }
        layout {
            title = "Graph name"
            xaxis {
                title = "x axis"
            }
            yaxis {
                title = "y axis"
            }
        }
    }

Error:

Exception in thread "main" java.lang.IllegalArgumentException: Can't create list value from empty list
    at hep.dataforge.values.ListValue.<init>(Value.kt:171)
    at hep.dataforge.values.Value$Companion.of(Value.kt:59)
    at hep.dataforge.meta.MutableValueDelegate$transform$1.invoke(Delegates.kt:187)
    at hep.dataforge.meta.MutableValueDelegate$transform$1.invoke(Delegates.kt:169)
    at hep.dataforge.meta.ReadWriteDelegateWrapper.setValue(Delegates.kt:371)
    at scientifik.plotly.models.Trace.setX(Trace.kt)
    at scientifik.plotly.models.Trace$Companion.build(Trace.kt:54)
    at scientifik.plotly.Plot2D.trace(Plot2D.kt:26)
    at scientifik.plotly.Plot2DKt.trace(Plot2D.kt:46)
    at StaticPlotKt$main$plot$1.invoke(staticPlot.kt:16)
    at StaticPlotKt$main$plot$1.invoke(staticPlot.kt)
    at scientifik.plotly.Plotly.plot2D(Plotly.kt:15)
    at StaticPlotKt.main(staticPlot.kt:15)
    at StaticPlotKt.main(staticPlot.kt)

Originally posted by @Zelenyy in https://github.com/mipt-npm/plotly.kt/issues/11#issuecomment-505080706