-
Notifications
You must be signed in to change notification settings - Fork 122
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
refactor(cartesian): timeslip preparation #1286
Conversation
af9efea
to
1d5aea6
Compare
d3e3e2b
to
848e188
Compare
jenkins test this |
jenkins test this |
fontStyle: fontStyle ? (fontStyle as FontStyle) : 'normal', | ||
fontWeight: 'normal', | ||
fontStyle: fontStyle ?? 'normal', | ||
fontWeight: 'bold', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could introduce an API option for font weight instead, then this bold
can go back into the theme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great idea
fontSize: 50, | ||
fontFamily: 'custom-font-family', | ||
fontStyle: 'custom-font-style', | ||
fontStyle: 'italic', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's a real need for 'custom-font-style'
we could introduce a fontShorthand
or fontOverride
property, the presence of which would bypass the current CSS shorthand string concatenation logic
*/ | ||
export const getRadians = (angle: number) => (angle * Math.PI) / 180; | ||
/** @internal */ | ||
export const degToRad = (angle: Degrees): Radian => (angle / 180) * Math.PI; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unpublishing it as we don't currently expose pure utility functions in our API, and it wouldn't be a good fit for our library because the related areas take in angles in degrees, so the user needs not convert to radians
210f2d8
to
cc63a3b
Compare
ctx.translate(x, y); | ||
ctx.rotate(getRadians(rotation)); | ||
ctx.translate(-x, -y); | ||
fn(ctx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this function, b/c a single place used it, and it immediately reverted the last (negative) translate here
packages/charts/src/chart_types/xy_chart/renderer/canvas/primitives/rect.ts
Show resolved
Hide resolved
const height = rect.height - borderOffset * 2; | ||
|
||
const borderWidth = !disableBorderOffset && stroke.width >= MIN_STROKE_WIDTH ? stroke.width : 0; | ||
if (stroke.width >= MIN_STROKE_WIDTH) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bunch of 0.001's got replaced with MIN_STROKE_WIDTH
x: 0, | ||
y: 0, | ||
rotate: 0, | ||
x: chartRotation === 90 || chartRotation === 180 ? width : 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice clean up!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O(n)
🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this clean up. Tested locally and changes look great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, the vr tests do not like your changes 🤣 . Idk what that annotation story always triggers a small diff for all.
packages/charts/src/chart_types/xy_chart/renderer/canvas/primitives/rect.ts
Show resolved
Hide resolved
@@ -26,30 +27,28 @@ export function renderText( | |||
origin: Point, | |||
text: string, | |||
font: TextFont, | |||
degree: number = 0, | |||
translation?: Partial<Point>, | |||
angle: Degrees = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
x: 0, | ||
y: 0, | ||
rotate: 0, | ||
x: chartRotation === 90 || chartRotation === 180 ? width : 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O(n)
🎉
@@ -76,7 +76,16 @@ function createPattern( | |||
if (fill) pCtx.fill(path); | |||
} | |||
|
|||
return ctx.createPattern(patternCanvas, 'repeat') ?? undefined; | |||
const pattern = ctx.createPattern(patternCanvas, 'repeat')!; // HTMLCanvasElement always yields a CanvasPattern anyway |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this will never ever throw
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't throw, as the spec says ctx.createPattern
invoked with HTMLCanvasElement
(which patternCanvas
is guaranteed to be) has no null
case.
Details:
It'd throw downstream of this function if pattern
ended up being null
(there are other throw conditions but TS guards against most(*) of those already; example: the "repeat"
literal is OK here).
The spec for createPattern
says:
The only potential for getting a null
is point 2:
- If usability is bad, then return null
It's the preceding point that references usability:
- Let usability be the result of checking the usability of image
The "switch" at the link has no "bad" usability case for HTMLCanvasElement
, so there can't be a null
, so the !
is safe and pattern
will never be null
. Typescript (apparently) is just not granular enough here to recognize that certain argument types can't lead to certain result types.
(*) If my 2nd reading prompted by your question is correct, then a zero dimension canvas would lead to a DOM exception. TS doesn't complain about this possibility, nor does current master
wrap it in throw
/catch
so this aspect is not made worse by this PR. Still, I'll check if we defend against a zero-dimension canvas upstream, eg. by not creating such a canvas, or by applying a minimum 1px by 1px dimension. The best combo is,avoiding a throw
condition so that a throw/catch
wrapper is not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zero dimension canvas would lead to a DOM exception
Good to know!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this and a bunch of other things here into #1303
# Conflicts: # packages/charts/src/chart_types/xy_chart/renderer/canvas/primitives/rect.ts
jenkins test this |
jenkins test this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest changes LGTM.
# [34.0.0](v33.2.4...v34.0.0) (2021-08-16) ### Code Refactoring * **cartesian:** cartesian rendering iteration ([#1286](#1286)) ([b2ae4f7](b2ae4f7)), closes [#1202](#1202) ### BREAKING CHANGES * **cartesian:** - `TextStyle.fontStyle` is no longer a `string`, it's the more specific `FontStyle` - For symmetry, `fontStyle` in word cloud is also switching from `string` to `FontStyle` - Certain text configurations included both `fill` and `textColor` for the text color; `fill` got removed, because `textColor` is part of the public `Font` type, and because `textColor` has clearer meaning than `fill`. Yet, some of the code used the `fill` property and/or made the `fill` property also mandatory. So, userland code needs to remove some `fill` property, and might need to ensure that the correct value is going into `textColor` - `getRadians` got unpublished - No attempt to draw a rect border if there's not enough width/height for at least the specified border width (ie. width/height being at least twice the border width)
🎉 This PR is included in version 34.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
Non-functional code cleanup, code removal and type fixes. Also removes the large pixel dimensions with texture use.
BREAKING CHANGE
TextStyle.fontStyle
is no longer astring
, it's the more specificFontStyle
fontStyle
in word cloud is also switching fromstring
toFontStyle
fill
andtextColor
for the text color;fill
got removed, becausetextColor
is part of the publicFont
type, and becausetextColor
has clearer meaning thanfill
. Yet, some of the code used thefill
property and/or made thefill
property also mandatory. So, userland code needs to remove somefill
property, and might need to ensure that the correct value is going intotextColor
getRadians
got unpublishedDetails
Reviewers,
FontStyle
fill
getRadian
(no apparent change to API MD)Issues
Checklist
packages/charts/src/index.ts
(and stories only import from../src
except for test data & storybook)