SciProgCentre / plotly.kt

An interactive Kotlin wrapper for plotly visualization tools
https://sciprogcentre.github.io/plotly.kt/
Apache License 2.0
149 stars 21 forks source link

Checking of input value #11

Closed Zelenyy closed 4 years ago

Zelenyy commented 5 years ago

An error occurs if pass emptyList in trace.

natanfudge commented 5 years ago

I suggest to provide the error.

altavir commented 5 years ago

@Zelenyy Could you specify the error? It should work as long as you pass the typed list. As far as I remember, current design of DataForge numberlist delegate accepts Any in order to work both with arrays and lists. I do not like this solution. Maybe we should hide direct access to those field by custom setters?

Zelenyy commented 5 years ago

@altavir @natanfudge 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)
altavir commented 5 years ago

OK, it is a DataForge issue. I will fix it in next release.

altavir commented 4 years ago

Fixed via b27a4fd