MCPcopy
hub / github.com/tdewolff/minify / createOrUpdatePatternFromDecal

Function createOrUpdatePatternFromDecal

_benchmarks/sample_echarts.js:27143–27390  ·  view source on GitHub ↗

* Create or update pattern image from decal options * * @param {InnerDecalObject | 'none'} decalObject decal options, 'none' if no decal * @return {Pattern} pattern with generated image, null if no decal

(decalObject, api)

Source from the content-addressed store, hash-verified

27141 */
27142
27143 function createOrUpdatePatternFromDecal(decalObject, api) {
27144 if (decalObject === 'none') {
27145 return null;
27146 }
27147
27148 var dpr = api.getDevicePixelRatio();
27149 var zr = api.getZr();
27150 var isSVG = zr.painter.type === 'svg';
27151
27152 if (decalObject.dirty) {
27153 decalMap["delete"](decalObject);
27154 }
27155
27156 var oldPattern = decalMap.get(decalObject);
27157
27158 if (oldPattern) {
27159 return oldPattern;
27160 }
27161
27162 var decalOpt = defaults(decalObject, {
27163 symbol: 'rect',
27164 symbolSize: 1,
27165 symbolKeepAspect: true,
27166 color: 'rgba(0, 0, 0, 0.2)',
27167 backgroundColor: null,
27168 dashArrayX: 5,
27169 dashArrayY: 5,
27170 rotation: 0,
27171 maxTileWidth: 512,
27172 maxTileHeight: 512
27173 });
27174
27175 if (decalOpt.backgroundColor === 'none') {
27176 decalOpt.backgroundColor = null;
27177 }
27178
27179 var pattern = {
27180 repeat: 'repeat'
27181 };
27182 setPatternnSource(pattern);
27183 pattern.rotation = decalOpt.rotation;
27184 pattern.scaleX = pattern.scaleY = isSVG ? 1 : 1 / dpr;
27185 decalMap.set(decalObject, pattern);
27186 decalObject.dirty = false;
27187 return pattern;
27188
27189 function setPatternnSource(pattern) {
27190 var keys = [dpr];
27191 var isValidKey = true;
27192
27193 for (var i = 0; i < decalKeys.length; ++i) {
27194 var value = decalOpt[decalKeys[i]];
27195 var valueType = typeof value;
27196
27197 if (value != null && !isArray(value) && valueType !== 'string' && valueType !== 'number' && valueType !== 'boolean') {
27198 isValidKey = false;
27199 break;
27200 }

Callers 4

decalVisualFunction · 0.85
sample_echarts.jsFile · 0.85
updateElNormalFunction · 0.85

Calls 2

setPatternnSourceFunction · 0.85
defaultsFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…