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

Charts: Simplify pattern visibility #7542

Merged
merged 2 commits into from
Jun 14, 2022

Conversation

dlabrecq
Copy link
Member

@dlabrecq dlabrecq commented Jun 11, 2022

Refactored the pattern feature to eliminate the pattern IDs required to hide / show individual patterns. This helps to simplify a few chart examples.

Previously, individual patterns were hidden using null values. However, that required some knowledge of our generated pattern IDs. For example:

patternId="pattern_b"
patternScale={['url("#pattern_b:0")', 'url("#pattern_b:1")', null]} // hide the last pattern

I want to simplify this using boolean flags, like so:

hasPatterns={[ true, true, false ]} // hide the last pattern

And to show patterns for all chart segments, this reduces to:

hasPatterns

That said, if devs choose to create custom patterns, they can still provide their own IDs.

patternScale={[ 'url("#pattern1")', 'url("#pattern2")', null ]} // hide the last pattern

Design issue: patternfly/patternfly-org#4369
Closes #7541

@patternfly-build
Copy link
Contributor

patternfly-build commented Jun 11, 2022

@dlabrecq dlabrecq force-pushed the 7541-pattern-visibility branch from 54205bc to 0471596 Compare June 11, 2022 05:21
@dlabrecq dlabrecq requested review from tlabaj and nicolethoen June 11, 2022 05:27
@dlabrecq dlabrecq force-pushed the 7541-pattern-visibility branch 8 times, most recently from b862cf8 to f8617fa Compare June 13, 2022 02:47
Copy link
Contributor

@nicolethoen nicolethoen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prop description for patternScale reads, This prop should be given as an array of CSS colors, or as a string corresponding to a URL. Do you have an example of using an array of CSS colors?

And is patternScale still the most logical name for this prop? I wonder if something like patternDefs or patternOptions or something like that feels a little closer to its intended usage, possibly?

Copy link
Contributor

@nicolethoen nicolethoen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one other idea

import uniqueId from 'lodash/uniqueId';

// @beta
export interface PatternScaleInterface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be possible to include this interface in the prop description tables at the bottom of the Patterns page. We do that a lot with the more complex types for the Composable Table components like this one.

As long as the type is exported so it can be imported in the examples, the PatternScaleInterface can be added to the list of propComponents in patterns.md. And then you can give yourself more space to write prop descriptions in this interface rather than using the same long prop description on each chart example.

by default, adding the PatternScaleInterface should create a link in each Chart prop table to link to it on the docs page, as you can see done in the Tables docs

Copy link
Member Author

@dlabrecq dlabrecq Jun 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've fixed the patternScale description.

I'd like to stick with the patternScale name because it mimics behavior of the existing colorScale prop. Both define the order in which items are applied, while colors / patterns repeat when there are more children than items.

Copy link
Member Author

@dlabrecq dlabrecq Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolethoen I removed PatternScaleInterface and created hasPatterns. That should help make things more clear.

hasPatterns={[ true, true, false ]} // hide the last pattern

Devs only need to use patternScale when creating custom patterns.

@dlabrecq dlabrecq force-pushed the 7541-pattern-visibility branch from f8617fa to 699ae10 Compare June 13, 2022 18:55
@dlabrecq dlabrecq force-pushed the 7541-pattern-visibility branch 2 times, most recently from 2fc2849 to 3742fdf Compare June 14, 2022 05:18
@dlabrecq dlabrecq force-pushed the 7541-pattern-visibility branch from 3742fdf to a5e94b5 Compare June 14, 2022 05:49
Copy link
Contributor

@tlabaj tlabaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nicolethoen nicolethoen merged commit 82d13fd into patternfly:main Jun 14, 2022
@patternfly-build
Copy link
Contributor

Your changes have been released in:

Thanks for your contribution! 🎉

@dlabrecq dlabrecq deleted the 7541-pattern-visibility branch July 6, 2022 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Charts: Simplify pattern visibility
4 participants