-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(ssr): add emphasis style in ssr css apache/echarts#18334 #999
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
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
53a44fb
WIP(ssr): add emphasis style in ssr css apache/echarts#18334
Ovilia 2088b3c
Merge branch 'master' into ssr
Ovilia 26abab1
feat(ssr): add style in meta data
Ovilia d7005b8
feat(ssr): improve code
Ovilia fb4c265
feat(ssr): provide registerSSRDataGetter
Ovilia a78b088
fix(ssr): remove a not used method
Ovilia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| let cssClassIdx = 0; | ||
|
|
||
| export function getClassId() { | ||
| return cssClassIdx++; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import Displayable from '../graphic/Displayable'; | ||
| import { liftColor } from '../tool/color'; | ||
| import { BrushScope, SVGVNodeAttrs } from './core'; | ||
| import { getClassId } from './cssClassId'; | ||
|
|
||
| export function createCSSEmphasis( | ||
| el: Displayable, | ||
| attrs: SVGVNodeAttrs, | ||
| scope: BrushScope | ||
| ) { | ||
| if (!el.ignore) { | ||
| if (el.isSilent()) { | ||
| // If el is silent, it can not be hovered nor selected. | ||
| // So set pointer-events to pass through. | ||
| const style = { | ||
| 'pointer-events': 'none' | ||
| }; | ||
| setClassAttribute(style, attrs, scope, true); | ||
| } | ||
| else { | ||
| const emphasisStyle = el.states.emphasis && el.states.emphasis.style | ||
| ? el.states.emphasis.style | ||
| : {}; | ||
| let fill = emphasisStyle.fill; | ||
| if (!fill) { | ||
| // No empahsis fill, lift color | ||
| const normalFill = el.style && el.style.fill; | ||
| const selectFill = el.states.select | ||
| && el.states.select.style | ||
| && el.states.select.style.fill; | ||
| const fromFill = el.currentStates.indexOf('select') >= 0 | ||
| ? (selectFill || normalFill) | ||
| : normalFill; | ||
| if (fromFill) { | ||
| fill = liftColor(fromFill); | ||
| } | ||
| } | ||
| let lineWidth = emphasisStyle.lineWidth; | ||
| if (lineWidth) { | ||
| // Symbols use transform to set size, so lineWidth | ||
| // should be divided by scaleX | ||
| const scaleX = (!emphasisStyle.strokeNoScale && el.transform) | ||
| ? el.transform[0] | ||
| : 1; | ||
| lineWidth = lineWidth / scaleX; | ||
| } | ||
| const style = { | ||
| cursor: 'pointer', // TODO: Should this be customized? | ||
| } as any; | ||
| if (fill) { | ||
| style.fill = fill; | ||
| } | ||
| if (emphasisStyle.stroke) { | ||
| style.stroke = emphasisStyle.stroke; | ||
| } | ||
| if (lineWidth) { | ||
| style['stroke-width'] = lineWidth; | ||
| } | ||
| setClassAttribute(style, attrs, scope, true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function setClassAttribute(style: object, attrs: SVGVNodeAttrs, scope: BrushScope, withHover: boolean) { | ||
| const styleKey = JSON.stringify(style); | ||
| let className = scope.cssStyleCache[styleKey]; | ||
| if (!className) { | ||
| className = scope.zrId + '-cls-' + getClassId(); | ||
| scope.cssStyleCache[styleKey] = className; | ||
| scope.cssNodes['.' + className + (withHover ? ':hover' : '')] = style as any; | ||
| } | ||
| attrs.class = attrs.class ? (attrs.class + ' ' + className) : className; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.