-
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 3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import LRU from '../core/LRU'; | ||
| import { extend, isGradientObject, isString, map } from '../core/util'; | ||
| import * as colorTool from '../tool/color'; | ||
| import Displayable from '../graphic/Displayable'; | ||
| import { GradientObject } from '../graphic/Gradient'; | ||
| import { BrushScope, SVGVNodeAttrs } from './core'; | ||
|
|
||
| // TODO: Consider deleting the same logic in ECharts and call this method? | ||
| const liftedColorCache = new LRU<string>(100); | ||
Ovilia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| function liftColor(color: GradientObject): GradientObject; | ||
| function liftColor(color: string): string; | ||
| function liftColor(color: string | GradientObject): string | GradientObject { | ||
| if (isString(color)) { | ||
| let liftedColor = liftedColorCache.get(color); | ||
| if (!liftedColor) { | ||
| liftedColor = colorTool.lift(color, -0.1); | ||
| liftedColorCache.put(color, liftedColor); | ||
| } | ||
| return liftedColor; | ||
| } | ||
| else if (isGradientObject(color)) { | ||
| const ret = extend({}, color) as GradientObject; | ||
| ret.colorStops = map(color.colorStops, stop => ({ | ||
| offset: stop.offset, | ||
| color: colorTool.lift(stop.color, -0.1) | ||
| })); | ||
| return ret; | ||
| } | ||
| // Change nothing. | ||
| return color; | ||
| } | ||
|
|
||
| export function createCSSEmphasis( | ||
| el: Displayable, | ||
| attrs: SVGVNodeAttrs, | ||
| scope: BrushScope | ||
| ) { | ||
| if (!el.ignore && el.__metaData) { | ||
| const empahsisStyle = el.states.emphasis | ||
Ovilia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ? el.states.emphasis.style | ||
Ovilia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| : {}; | ||
|
||
| let fill = empahsisStyle.fill; | ||
| if (!fill) { | ||
| // No empahsis fill, lift color | ||
| const normalFill = el.style.fill; | ||
| const selectFill = el.states.select && el.states.select.style.fill; | ||
Ovilia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const fromFill = el.currentStates.indexOf('select') >= 0 | ||
| ? (selectFill || normalFill) | ||
| : normalFill; | ||
| if (fromFill) { | ||
| fill = liftColor(fromFill); | ||
| } | ||
| } | ||
| let lineWidth = empahsisStyle.lineWidth; | ||
| if (lineWidth) { | ||
| // Symbols use transform to set size, so lineWidth | ||
| // should be divided by scaleX | ||
| const scaleX = el.transform ? el.transform[0] : 1; | ||
Ovilia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| lineWidth = lineWidth / scaleX; | ||
| } | ||
| const style = { | ||
| cursor: 'pointer', // TODO: Should be included in el | ||
Ovilia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } as any; | ||
| if (fill) { | ||
| style.fill = fill; | ||
| } | ||
| if (empahsisStyle.stroke) { | ||
| style.stroke = empahsisStyle.stroke; | ||
| } | ||
| if (lineWidth) { | ||
| style['stroke-width'] = lineWidth; | ||
| } | ||
| const styleKey = JSON.stringify(style); | ||
| let className = scope.cssStyleCache[styleKey]; | ||
| if (!className) { | ||
| className = scope.zrId + '-cls-' + scope.cssClassIdx++; | ||
Ovilia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| scope.cssStyleCache[styleKey] = className; | ||
| scope.cssNodes['.' + className + ':hover'] = style; | ||
| } | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <title>Image</title> | ||
| <script src="./lib/config.js"></script> | ||
| <script src="../dist/zrender.js"></script> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| </head> | ||
| <body> | ||
| <div id="main" style="width:1000px;height:800px;"></div> | ||
| <script type="text/javascript"> | ||
| // 初始化zrender | ||
| var zr = zrender.init(document.getElementById('main'), { | ||
| renderer: window.__ZRENDER__DEFAULT__RENDERER__ || 'svg' | ||
| }); | ||
|
|
||
| var rect = new zrender.Rect({ | ||
| shape: { | ||
| x: 10, | ||
| y: 10, | ||
| width: 80, | ||
| height: 80 | ||
| }, | ||
| style: { | ||
| fill: 'red' | ||
| } | ||
| }); | ||
| rect.__metaData = { | ||
| type: 'seriesItem', | ||
| seriesIndex: 0, | ||
| dataIndex: 0, | ||
| styleType: 'itemStyle' | ||
| } | ||
| zr.add(rect); | ||
|
|
||
| setTimeout(() => { | ||
| const metaData = { | ||
| series: [{ | ||
| normal: { | ||
| itemStyle: { | ||
| fill: 'red' | ||
| } | ||
| }, | ||
| emphasis: { | ||
| itemStyle: { | ||
| fill: 'blue' | ||
| } | ||
| } | ||
| }] | ||
| } | ||
|
|
||
| const svg = zr.painter.getViewportRoot().getElementsByTagName('svg')[0]; | ||
| const root = svg.children[0]; | ||
| for (let i = 0; i < root.children.length; i++) { | ||
| const child = root.children[i]; | ||
| const type = child.getAttribute('ecmeta_type'); | ||
| if (type === 'seriesItem') { | ||
| child.addEventListener('mouseover', event => { | ||
| const attrs = event.target.attributes; | ||
| const seriesIndex = attrs.ecmeta_seriesIndex.value; | ||
| const dataIndex = attrs.ecmeta_dataIndex.value; | ||
| const styleType = attrs.ecmeta_styleType.value; | ||
| const emphasis = metaData.series[seriesIndex].emphasis; | ||
| if (emphasis && emphasis[styleType]) { | ||
| const style = emphasis[styleType]; | ||
| for (let key in style) { | ||
| attrs[key].value = style[key]; | ||
| } | ||
| } | ||
| }); | ||
| child.addEventListener('mouseout', event => { | ||
| const attrs = event.target.attributes; | ||
| const seriesIndex = attrs.ecmeta_seriesIndex.value; | ||
| const dataIndex = attrs.ecmeta_dataIndex.value; | ||
| const styleType = attrs.ecmeta_styleType.value; | ||
| const normal = metaData.series[seriesIndex].normal; | ||
| if (normal && normal[styleType]) { | ||
| const style = normal[styleType]; | ||
| for (let key in style) { | ||
| attrs[key].value = style[key]; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| console.log(root) | ||
| }); | ||
| </script> | ||
|
|
||
| </body> | ||
| </html> |
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.