forked from naver/billboard.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(option): refactor useCssRule implementation
- Split related methods to style.ts - Expand applying to legend and Arc elements Ref naver#2736
- Loading branch information
Showing
12 changed files
with
120 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,54 @@ | ||
/** | ||
* Copyright (c) 2017 ~ present NAVER Corp. | ||
* billboard.js project is licensed under the MIT license | ||
*/ | ||
import {$SHAPE} from "../../config/classes"; | ||
import {d3Selection} from "../../../types/types"; | ||
import {IDataRow} from "../data/IData"; | ||
import {addCssRules, isFunction, isString} from "../../module/util"; | ||
|
||
export default { | ||
/** | ||
* Add props color css rule to given selector | ||
* @param {boolean} withShape Set shpes' prefix class | ||
* @param {string} selector CSS selector | ||
* @param {Array} props CSS props list | ||
* @param {Function} propsFn Function to retrieve value or determine for props | ||
* @returns {Function} | ||
* @private | ||
*/ | ||
setCssRule(withShape: boolean, selector: string, props: string[], propsFn: Function): Function { | ||
const $$ = this; | ||
const {config, state: {cssRule, style}} = $$; | ||
|
||
return config.boost_useCssRule ? (selection: d3Selection) => { | ||
selection.each((d: IDataRow) => { | ||
const res = propsFn && propsFn?.call($$, d); | ||
const shapeSelector = `${ | ||
withShape ? `.${$SHAPE.shapes + $$.getTargetSelectorSuffix(d.id)}` : "" | ||
}${selector}`; | ||
|
||
(selector in cssRule) && style.sheet.deleteRule(cssRule[shapeSelector]); | ||
$$.state.cssRule[shapeSelector] = addCssRules( | ||
style, | ||
shapeSelector, | ||
props.filter(Boolean).map(v => ( | ||
isString(res) && v.indexOf(":") === -1 ? `${v}: ${res}` : (v || "") | ||
)) | ||
); | ||
}); | ||
} : () => {}; | ||
}, | ||
|
||
/** | ||
* Get style prop value | ||
* @param {Function|string} v Value | ||
* @returns {string|null} | ||
* @private | ||
*/ | ||
getStylePropValue(v: Function|string): string|null { | ||
const {config: {boost_useCssRule: useCssRule}} = this; | ||
|
||
return useCssRule ? null : isFunction(v) ? v.bind(this) : v; | ||
} | ||
}; |
This file contains 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 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 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 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 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 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.