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

Offset, Orientation and other config ergonomict tweaks #20

Merged
merged 3 commits into from
Dec 17, 2024

Conversation

jentfoo
Copy link
Member

@jentfoo jentfoo commented Dec 17, 2024

This PR continues trying to tweak the chart configuration to be easier and hopefully more obvious. Changes included:

  • This PR moves the Top and Left configuration options for a Legend or Title under the OffsetStr struct. In cases where only Left was being set with PositionLeft / PositionCenter / PositionRight, now OffsetLeft / OffsetCenter / OffsetRight can be used to set the Offset field.
  • Configuration sub-structs (like OffsetStr or FontStyle) should consistently have WithX functions to allow easy modifications or a builder pattern.
  • Orient string, which previously could only have values horizontal and vertical is now a boolean named Vertical, resulting in OrientationHorizontal and OrientationVertical constants being no longer needed and thus removed.
  • Functions NewLegendOption NewXAxisOption NewYAxisOptions were removed. In general we expect the configuration structs to be made directly by the user. These helper functions were not well documented and outside of how other configuration structs are initialized. For that reason we removed these three functions, and instead expect the struct to be initialized directly.

See examples for examples on how to update your implementations. The changes here are similar to how most people are expected to update:
https://github.com/go-analyze/charts/pull/20/files#diff-0a8fe8d29976febc4342e445372f0f0c7e7322acfaab81562ed1595f0f8d2f98R62-R67

Thoughts on the API:
I agonized over these API changes pretty heavily. I dislike having both an OffsetStr and OffsetInt, however there are two cases needed. OffsetInt is used in cases where an absolute offset is provided, and a relative offset (for example 50%) does not make sense.

Additionally I dislike for the Legend how there are multiple configuration values which determine the position (Offset and Padding both). However I am unsure how to reduce these fields while keeping the configuration easy to understand.

If you have thoughts on the above please put a comment on this PR or open an Issue. I want to continue to make chart configuration simpler and obvious while still being highly flexible!

This change moves the `Top` and `Left` configuration options for a Legend or Title under the `OffsetStr` struct.
In cases where only `Left` was being set with `PositionLeft` / `PositionCenter` / `PositionRight`, now `OffsetLeft` / `OffsetCenter` / `OffsetRight` can be used to set the `Offset` field.
In addition sub-structs in configurations should consistently have `WithX` functions to allow easy modifications or a builder pattern.
Instead of specifying "vertical" as a string, the boolean can now be set directly.
@jentfoo jentfoo self-assigned this Dec 17, 2024
In general we expect the configuration structs to be made directly by the user. These helper functions were not well documented and outside of how other configuration structs are initialized. For that reason we removed these three functions, and instead expect the struct to be initialized directly.
@jentfoo jentfoo changed the title Offset and Orientation Config Ergonomic Tweaks Offset and Orientation and Other Config Ergonomic Tweaks Dec 17, 2024
@jentfoo jentfoo changed the title Offset and Orientation and Other Config Ergonomic Tweaks Offset, Orientation and other config ergonomict tweaks Dec 17, 2024
@jentfoo jentfoo merged commit f84fa28 into main Dec 17, 2024
6 checks passed
@jentfoo jentfoo deleted the jent/v0.3_config_tweaks branch December 18, 2024 15:36
@jentfoo jentfoo added the enhancement New feature or request label Dec 29, 2024
jentfoo added a commit that referenced this pull request Jan 1, 2025
v0.4.0 will be focused on minimizing and simplifying the public API so that our module is easier to learn.  This will include removing public structs and functions not expected to be utilized by the user, as well as making sure the public API presented is consistent.

Changes included so far:
* `LegendOptions.Vertical` introduced in #20 has been changed from a `bool` to `*bool`.  This makes the field more consistent to other configuration, and provides more future flexibility for dynamic defaults.
* Public `NewXPainter` functions are made private, these are only expected to be used internally.
* Public structs `AxisOption`, `GridPainterOption`, `SeriesLabelPainter`, `SeriesLabelPainterParams`, have been made private or removed.  These are expected to only be used internally.
* `LabelFormatter` has been removed (not to be confused with `ValueFormatter`, which remains)
jentfoo added a commit that referenced this pull request Jan 1, 2025
v0.4.0 will be focused on minimizing and simplifying the public API so that our module is easier to learn.  This will include removing public structs and functions not expected to be utilized by the user, as well as making sure the public API presented is consistent.

Changes included so far:
  * `LegendOptions.Vertical` introduced in #20 has been changed from a `bool` to `*bool`.  This makes the field more consistent to other configuration, and provides more future flexibility for dynamic defaults.
  * Public `NewXPainter` functions are made private, these are only expected to be used internally.
  * Public structs `AxisOption`, `GridPainterOption`, `SeriesLabelPainter`, `SeriesLabelPainterParams`, have been made private or removed.  These are expected to only be used internally.
  * `LabelFormatter` has been removed (not to be confused with `ValueFormatter`, which remains)
  * Additional functions expected to be internal only: `NewRange`, `NewLeftYAxis`, `NewRightYAxis`, `NewBottomXAxis`, `NewEChartsSeriesDataValue` (struct is still public if needed)
jentfoo added a commit that referenced this pull request Jan 2, 2025
v0.4.0 will be focused on minimizing and simplifying the public API so that our module is easier to learn.  This will include removing public structs and functions not expected to be utilized by the user, as well as making sure the public API presented is consistent.

Changes included so far:
  * `LegendOptions.Vertical` introduced in #20 has been changed from a `bool` to `*bool`.  This makes the field more consistent to other configuration, and provides more future flexibility for dynamic defaults.
  * Public `NewXPainter` functions are made private, these are only expected to be used internally.
  * Public structs `AxisOption`, `GridPainterOption`, `SeriesLabelPainter`, `SeriesLabelPainterParams`, have been made private or removed.  These are expected to only be used internally.
  * `LabelFormatter` has been removed (not to be confused with `ValueFormatter`, which remains)
  * Additional functions expected to be internal only: `NewRange`, `NewLeftYAxis`, `NewRightYAxis`, `NewBottomXAxis`, `NewEChartsSeriesDataValue` (struct is still public if needed)
jentfoo added a commit that referenced this pull request Jan 2, 2025
v0.4.0 will be focused on minimizing and simplifying the public API so that our module is easier to learn.  This will include removing public structs and functions not expected to be utilized by the user, as well as making sure the public API presented is consistent.

Changes included so far:
  * `LegendOptions.Vertical` introduced in #20 has been changed from a `bool` to `*bool`.  This makes the field more consistent to other configuration, and provides more future flexibility for dynamic defaults.
  * Public `NewXPainter` functions are made private, these are only expected to be used internally.
  * Public structs `AxisOption`, `GridPainterOption`, `SeriesLabelPainter`, `SeriesLabelPainterParams`, have been made private or removed.  These are expected to only be used internally.
  * `LabelFormatter` has been removed (not to be confused with `ValueFormatter`, which remains)
  * Additional functions expected to be internal only: `NewRange`, `NewLeftYAxis`, `NewRightYAxis`, `NewBottomXAxis`, `NewEChartsSeriesDataValue` (struct is still public if needed)
jentfoo added a commit that referenced this pull request Jan 3, 2025
v0.4.0 will be focused on minimizing and simplifying the public API so that our module is easier to learn.  This will include removing public structs and functions not expected to be utilized by the user, as well as making sure the public API presented is consistent.

Changes included so far:
  * `LegendOptions.Vertical` introduced in #20 has been changed from a `bool` to `*bool`.  This makes the field more consistent to other configuration, and provides more future flexibility for dynamic defaults.
  * Public `NewXPainter` functions are made private, these are only expected to be used internally.
  * Public structs `AxisOption`, `GridPainterOption`, `SeriesLabelPainter`, `SeriesLabelPainterParams`, have been made private or removed.  These are expected to only be used internally.
  * `LabelFormatter` has been removed (not to be confused with `ValueFormatter`, which remains)
  * Additional functions expected to be internal only: `NewRange`, `NewLeftYAxis`, `NewRightYAxis`, `NewBottomXAxis`, `NewEChartsSeriesDataValue` (struct is still public if needed)
jentfoo added a commit that referenced this pull request Jan 3, 2025
v0.4.0 will be focused on minimizing and simplifying the public API so that our module is easier to learn.  This will include removing public structs and functions not expected to be utilized by the user, as well as making sure the public API presented is consistent.

Changes included so far:
  * `LegendOptions.Vertical` introduced in #20 has been changed from a `bool` to `*bool`.  This makes the field more consistent to other configuration, and provides more future flexibility for dynamic defaults.
  * Public `NewXPainter` functions are made private, these are only expected to be used internally.
  * Public structs `AxisOption`, `GridPainterOption`, `SeriesLabelPainter`, `SeriesLabelPainterParams`, have been made private or removed.  These are expected to only be used internally.
  * `LabelFormatter` has been removed (not to be confused with `ValueFormatter`, which remains)
  * Additional functions expected to be internal only: `NewRange`, `NewLeftYAxis`, `NewRightYAxis`, `NewBottomXAxis`, `NewEChartsSeriesDataValue` (struct is still public if needed)
jentfoo added a commit that referenced this pull request Jan 3, 2025
v0.4.0 will be focused on minimizing and simplifying the public API so that our module is easier to learn.  This will include removing public structs and functions not expected to be utilized by the user, as well as making sure the public API presented is consistent.

Changes included so far:
  * `LegendOptions.Vertical` introduced in #20 has been changed from a `bool` to `*bool`.  This makes the field more consistent to other configuration, and provides more future flexibility for dynamic defaults.
  * Public `NewXPainter` functions are made private, these are only expected to be used internally.
  * Public structs `AxisOption`, `GridPainterOption`, `SeriesLabelPainter`, `SeriesLabelPainterParams`, have been made private or removed.  These are expected to only be used internally.
  * `LabelFormatter` has been removed (not to be confused with `ValueFormatter`, which remains)
  * Additional functions expected to be internal only: `NewRange`, `NewLeftYAxis`, `NewRightYAxis`, `NewBottomXAxis`, `NewEChartsSeriesDataValue` (struct is still public if needed)
  * `PainterOption` function has been renamed to `PainterOptionFunc`
  * Removed `OutputFormatOptionFunc`, instead use `SVGOutputOptionFunc()` or `PNGOutputOptionFunc()`
  * Dimensions are now always set together, `WidthOptionFunc` and `HeightOptionFunc` are now set with `DimensionsOptionFunc`.  Similar `SetDefaultWidth` and `SetDefaultHeight` were replaced with `SetDefaultChartDimensions`.
  * `BoxOptionFunc` was removed, we don't currently have a clear example of where this is useful.
jentfoo added a commit that referenced this pull request Jan 10, 2025
v0.4.0 will be focused on minimizing and simplifying the public API so that our module is easier to learn.  This will include removing public structs and functions not expected to be utilized by the user, as well as making sure the public API presented is consistent.

Changes included so far:
  * `LegendOptions.Vertical` introduced in #20 has been changed from a `bool` to `*bool`.  This makes the field more consistent to other configuration, and provides more future flexibility for dynamic defaults.
  * Public `NewXPainter` functions are made private, these are only expected to be used internally.
  * Public structs `AxisOption`, `GridPainterOption`, `SeriesLabelPainter`, `SeriesLabelPainterParams`, have been made private or removed.  These are expected to only be used internally.
  * `LabelFormatter` has been removed (not to be confused with `ValueFormatter`, which remains)
  * Additional functions expected to be internal only: `NewRange`, `NewLeftYAxis`, `NewRightYAxis`, `NewBottomXAxis`, `NewEChartsSeriesDataValue` (struct is still public if needed)
  * `PainterOption` function has been renamed to `PainterOptionFunc`
  * Removed `OutputFormatOptionFunc`, instead use `SVGOutputOptionFunc()` or `PNGOutputOptionFunc()`
  * Dimensions are now always set together, `WidthOptionFunc` and `HeightOptionFunc` are now set with `DimensionsOptionFunc`.  Similar `SetDefaultWidth` and `SetDefaultHeight` were replaced with `SetDefaultChartDimensions`.
  * `BoxOptionFunc` was removed, we don't currently have a clear example of where this is useful.
jentfoo added a commit that referenced this pull request Jan 10, 2025
v0.4.0 will be focused on minimizing and simplifying the public API so that our module is easier to learn.  This will include removing public structs and functions not expected to be utilized by the user, as well as making sure the public API presented is consistent.

Changes included so far:
  * `LegendOptions.Vertical` introduced in #20 has been changed from a `bool` to `*bool`.  This makes the field more consistent to other configuration, and provides more future flexibility for dynamic defaults.
  * Public `NewXPainter` functions are made private, these are only expected to be used internally.
  * Public structs `AxisOption`, `GridPainterOption`, `SeriesLabelPainter`, `SeriesLabelPainterParams`, have been made private or removed.  These are expected to only be used internally.
  * `LabelFormatter` has been removed (not to be confused with `ValueFormatter`, which remains)
  * Additional functions expected to be internal only: `NewRange`, `NewLeftYAxis`, `NewRightYAxis`, `NewBottomXAxis`, `NewEChartsSeriesDataValue` (struct is still public if needed)
  * `PainterOption` function has been renamed to `PainterOptionFunc`
  * Removed `OutputFormatOptionFunc`, instead use `SVGOutputOptionFunc()` or `PNGOutputOptionFunc()`
  * Dimensions are now always set together, `WidthOptionFunc` and `HeightOptionFunc` are now set with `DimensionsOptionFunc`.  Similar `SetDefaultWidth` and `SetDefaultHeight` were replaced with `SetDefaultChartDimensions`.
  * `BoxOptionFunc` was removed, we don't currently have a clear example of where this is useful.
jentfoo added a commit that referenced this pull request Jan 12, 2025
v0.4.0 will be focused on minimizing and simplifying the public API so that our module is easier to learn.  This will include removing public structs and functions not expected to be utilized by the user, as well as making sure the public API presented is consistent.

Changes included so far:
  * `LegendOptions.Vertical` introduced in #20 has been changed from a `bool` to `*bool`.  This makes the field more consistent to other configuration, and provides more future flexibility for dynamic defaults.
  * Public `NewXPainter` functions are made private, these are only expected to be used internally.
  * Public structs `AxisOption`, `GridPainterOption`, `SeriesLabelPainter`, `SeriesLabelPainterParams`, have been made private or removed.  These are expected to only be used internally.
  * `LabelFormatter` has been removed (not to be confused with `ValueFormatter`, which remains)
  * Additional functions expected to be internal only: `NewRange`, `NewLeftYAxis`, `NewRightYAxis`, `NewBottomXAxis`, `NewEChartsSeriesDataValue` (struct is still public if needed)
  * `PainterOption` function has been renamed to `PainterOptionFunc`
  * Removed `OutputFormatOptionFunc`, instead use `SVGOutputOptionFunc()` or `PNGOutputOptionFunc()`
  * Dimensions are now always set together, `WidthOptionFunc` and `HeightOptionFunc` are now set with `DimensionsOptionFunc`.  Similar `SetDefaultWidth` and `SetDefaultHeight` were replaced with `SetDefaultChartDimensions`.
  * `BoxOptionFunc` was removed, we don't currently have a clear example of where this is useful.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant