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

feat(axis): allow pixel domain padding for y axes #1145

Merged
merged 17 commits into from
Jun 4, 2021

Conversation

nickofthyme
Copy link
Collaborator

@nickofthyme nickofthyme commented May 5, 2021

Summary

Adds support for pixel domain padding in the vertical/y axis, added to the existing padding options of domain value and domain ratio value.

BREAKING CHANGES:
domain.padding now only takes a number value. If you are using a percent-based padding such as '10%' please set domain.padding to 0.1 and domain.paddingUnit to DomainPaddingUnit.DomainRatio.

Details

This pr adds the ability to set the y domain padding to a fixed pixel value in the spatial or screen space. Currently, the domain is allowed to be set to a domain value or domain percentage value with the misaligned documentation.

Adds paddingUnit as type DomainPaddingUnit to domain options rather than parsing units from a string.

export const DomainPaddingUnit: Readonly<{
    Domain: "domain";
    Pixel: "pixel";
    DomainRatio: "domainRatio";
}>;

Adds domainPixelPadding and constrainDomainPadding as options to continuous scale, but does not apply to time scales.

Note: All domain padding is applied before and domain nicing.

Connected issues

Closes #1144

Checklist

  • Any consumer-facing exports were added to src/index.ts (and stories only import from ../src except for test data & storybook)
  • Proper documentation or storybook story was added for features that require explanation or tutorials
  • Unit tests were updated or added to match the most common scenarios

- Add missing yarn call
- Pass all yarn script args to jest call in vrt.sh
@nickofthyme nickofthyme added enhancement New feature or request :axis Axis related issue breaking change labels May 5, 2021
@nickofthyme nickofthyme requested a review from markov00 May 5, 2021 15:28
Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

I'm a bit confused about when/if the padding is applied to the lower part of the domain.
It looks like it always gets applied to the higher part, and the lower one always gets limited at 0 or at the specified domain min.

scripts/vrt.sh Outdated Show resolved Hide resolved
src/scales/scale_continuous.ts Outdated Show resolved Hide resolved
@nickofthyme
Copy link
Collaborator Author

It looks like it always gets applied to the higher part, and the lower one always gets limited at 0 or at the specified domain min.

This is controlled by the constrainPadding option.

@nickofthyme nickofthyme changed the title feat(axis): allow pixel domain padding for y axes feat(axis): allow pixel domain padding for y axes May 27, 2021
Comment on lines 132 to 158
const { scaleMultiplier } = screenspaceMarkerScaleCompressor(
orderedDomain,
[2 * desiredPixelPadding, 2 * desiredPixelPadding],
chartHeight,
);
let paddedDomainLo = orderedDomain[0] - desiredPixelPadding / scaleMultiplier;
let paddedDomainHigh = orderedDomain[1] + desiredPixelPadding / scaleMultiplier;

if (constrainDomainPadding) {
if (paddedDomainLo < 0 && orderedDomain[0] >= 0) {
const { scaleMultiplier } = screenspaceMarkerScaleCompressor(
[0, orderedDomain[1]],
[0, 2 * desiredPixelPadding],
chartHeight,
);
paddedDomainLo = 0;
paddedDomainHigh = orderedDomain[1] + desiredPixelPadding / scaleMultiplier;
} else if (paddedDomainHigh > 0 && orderedDomain[1] <= 0) {
const { scaleMultiplier } = screenspaceMarkerScaleCompressor(
[orderedDomain[0], 0],
[2 * desiredPixelPadding, 0],
chartHeight,
);
paddedDomainLo = orderedDomain[0] - desiredPixelPadding / scaleMultiplier;
paddedDomainHigh = 0;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice solution for adding both a top and bottom padding except when the padding would be the thing that extends the domain over/under the zero axis line 🎉

We might have a situation in the future where the reference line is not the zero line, but something else; for such a case, it would be eventually useful to DRY up and extract the reference value, eg. const intercept = 0; so it's later easy to make configurable. It's not needed in this PR, do you think @markov00 it'd be useful at some point?

Copy link
Member

Choose a reason for hiding this comment

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

Yep, is definitely a nice to have!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is this what you had in mind @monfera 0577a2c?

Copy link
Contributor

@monfera monfera left a comment

Choose a reason for hiding this comment

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

Great PR Nick 🚀

Please add VRT pics for the full variety of cases, with top and bottom padding applied:

  • domain values are both positive and negative
  • positive-only and negative-only; both with and without the padding breaching the zero intercept

This also exercises all the code paths where the scale compressor is used

@nickofthyme
Copy link
Collaborator Author

Great PR Nick 🚀

Please add VRT pics for the full variety of cases, with top and bottom padding applied:

  • domain values are both positive and negative
  • positive-only and negative-only; both with and without the padding breaching the zero intercept

This also exercises all the code paths where the scale compressor is used

❤️ Good idea, see 7511666

@nickofthyme nickofthyme requested a review from monfera June 3, 2021 18:20
Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Nick for all the changes

@nickofthyme nickofthyme enabled auto-merge (squash) June 4, 2021 13:08
@markov00
Copy link
Member

markov00 commented Jun 4, 2021

jenkins test this please

1 similar comment
@nickofthyme
Copy link
Collaborator Author

jenkins test this please

@nickofthyme nickofthyme merged commit 7c1fa8e into elastic:master Jun 4, 2021
@nickofthyme nickofthyme deleted the padding-px-value branch June 4, 2021 15:52
nickofthyme pushed a commit that referenced this pull request Jun 4, 2021
# [30.0.0](v29.2.0...v30.0.0) (2021-06-04)

### Bug Fixes

* **domain:** custom domain should not filter data ([#1181](#1181)) ([76e8dca](76e8dca)), closes [#1129](#1129)
* **value_labels:** zero as a valid value for textBorder and borderWidth ([#1182](#1182)) ([a64f333](a64f333))
* annotation tooltip display when remounting specs ([#1167](#1167)) ([8408600](8408600))
* render nodeLabel formatted text into the nodes ([#1173](#1173)) ([b44bdff](b44bdff))

### Features

* **axis:** allow pixel domain padding for y axes  ([#1145](#1145)) ([7c1fa8e](7c1fa8e))
* apply value formatter to the default legend item label ([#1190](#1190)) ([71474a5](71474a5))
* **tooltip:** stickTo vertical middle of the cursor ([#1163](#1163)) ([380363b](380363b)), closes [#1108](#1108)
* **wordcloud:** click and over events on text ([#1180](#1180)) ([196fb6a](196fb6a)), closes [#1156](#1156)

### BREAKING CHANGES

* **value_labels:** the `textBorder` of `ValueFillDefinition` is now optional or a number only
@nickofthyme
Copy link
Collaborator Author

🎉 This PR is included in version 30.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nickofthyme nickofthyme added the released Issue released publicly label Jun 4, 2021
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
# [30.0.0](elastic/elastic-charts@v29.2.0...v30.0.0) (2021-06-04)

### Bug Fixes

* **domain:** custom domain should not filter data ([opensearch-project#1181](elastic/elastic-charts#1181)) ([92ba84c](elastic/elastic-charts@92ba84c)), closes [opensearch-project#1129](elastic/elastic-charts#1129)
* **value_labels:** zero as a valid value for textBorder and borderWidth ([#1182](elastic/elastic-charts#1182)) ([880fbf1](elastic/elastic-charts@880fbf1))
* annotation tooltip display when remounting specs ([opensearch-project#1167](elastic/elastic-charts#1167)) ([7163951](elastic/elastic-charts@7163951))
* render nodeLabel formatted text into the nodes ([opensearch-project#1173](elastic/elastic-charts#1173)) ([0de9688](elastic/elastic-charts@0de9688))

### Features

* **axis:** allow pixel domain padding for y axes  ([#1145](elastic/elastic-charts#1145)) ([6787728](elastic/elastic-charts@6787728))
* apply value formatter to the default legend item label ([opensearch-project#1190](elastic/elastic-charts#1190)) ([20108bb](elastic/elastic-charts@20108bb))
* **tooltip:** stickTo vertical middle of the cursor ([#1163](elastic/elastic-charts#1163)) ([b858fb3](elastic/elastic-charts@b858fb3)), closes [opensearch-project#1108](elastic/elastic-charts#1108)
* **wordcloud:** click and over events on text ([opensearch-project#1180](elastic/elastic-charts#1180)) ([adbf341](elastic/elastic-charts@adbf341)), closes [opensearch-project#1156](elastic/elastic-charts#1156)

### BREAKING CHANGES

* **value_labels:** the `textBorder` of `ValueFillDefinition` is now optional or a number only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:axis Axis related issue breaking change enhancement New feature or request released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow specifying axis domain padding as pixel
3 participants