In Rust, unlike in JavaScript, we are accustomed to using numbers to represent numbers, strings for strings, and Enums for enumerable data. In your code, I see a mix of the correct approach alongside some unidiomatic and incorrect patterns.
Example of the correct approach
The method Layout::bar_mode(self, value: BarMode) is a great example. One can easily navigate to the BarMode type to see all possible values. It is self-explaining, no additional documentation is needed.
Example of the Incorrect Approach
The method y_axis(self, value: AsRef<str>) in the trace structures is problematic. It is not at all obvious what should be passed as the value. It is only through examples that one discovers that "y2" is needed for the second y-axis, "y3" for the third, and so on. In this case, an Enum with variants such as Y1, Y2, Y3, etc., should be used instead.
In Rust, unlike in JavaScript, we are accustomed to using numbers to represent numbers, strings for strings, and Enums for enumerable data. In your code, I see a mix of the correct approach alongside some unidiomatic and incorrect patterns.
Example of the correct approach
The method
Layout::bar_mode(self, value: BarMode)is a great example. One can easily navigate to the BarMode type to see all possible values. It is self-explaining, no additional documentation is needed.Example of the Incorrect Approach
The method
y_axis(self, value: AsRef<str>)in the trace structures is problematic. It is not at all obvious what should be passed as the value. It is only through examples that one discovers that "y2" is needed for the second y-axis, "y3" for the third, and so on. In this case, an Enum with variants such asY1,Y2,Y3, etc., should be used instead.