How to use stop method in testcontainers-python

Best Python code snippet using testcontainers-python_python

graphics-gradients-tests.js

Source:graphics-gradients-tests.js Github

copy

Full Screen

1YUI.add('graphics-gradients-tests', function(Y) {2 var suite = new Y.Test.Suite('graphics-gradients-tests example test suite'),3 _getClassName = Y.ClassNameManager.getClassName,4 SHAPE,5 RECT,6 CIRCLE,7 ENGINE = "vml",8 DOCUMENT = Y.config.doc,9 canvas = DOCUMENT && DOCUMENT.createElement("canvas"),10 graphicTests,11 svgTests,12 canvasTests,13 vmlTests,14 PATHNODE = "shape",15 TORGB = Y.Color.toRGB,16 TOHEX = Y.Color.toHex,17 toRGBA = function(val, alpha) {18 alpha = Y.Lang.isNumber(alpha) ? alpha : 1;19 if (!Y.Color.re_RGB.test(val)) {20 val = TOHEX(val);21 }22 if(Y.Color.re_hex.exec(val)) {23 val = 'rgba(' + [24 parseInt(RegExp.$1, 16),25 parseInt(RegExp.$2, 16),26 parseInt(RegExp.$3, 16)27 ].join(',') + ',' + alpha + ')';28 }29 return val;30 },31 IMPLEMENTATION;32 if(DOCUMENT && DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"))33 {34 ENGINE = "svg";35 }36 else if(canvas && canvas.getContext && canvas.getContext("2d"))37 {38 ENGINE = "canvas";39 }40 SHAPE = "." + _getClassName(ENGINE + "Shape");41 RECT = "." + _getClassName(ENGINE + "Rect");42 CIRCLE = "." + _getClassName(ENGINE + "Circle");43 IMPLEMENTATION = {44 svg: {45 getStroke: function()46 {47 var node = this._node,48 color = node.getAttribute("stroke"),49 weight = node.getAttribute("stroke-width"),50 opacity = node.getAttribute("stroke-opacity");51 color = toRGBA(TOHEX(color), opacity);52 return {53 color: color,54 weight: weight55 }56 },57 58 getFill: function()59 {60 var node = this._node,61 fillNode,62 stopNodes,63 len,64 i = 0,65 stops,66 stop,67 stopNode,68 offset,69 gradientIndex,70 tagName,71 type,72 color = node.getAttribute("fill"),73 opacity = node.getAttribute("fill-opacity"),74 fill = {};75 if(color.indexOf("url") > -1)76 {77 color = color.slice(color.indexOf("#"), color.lastIndexOf(")"));78 fillNode = Y.one(color);79 if(fillNode)80 {81 tagName = fillNode.get("tagName");82 if(tagName)83 {84 gradientIndex = tagName.indexOf("Gradient");85 if(gradientIndex > -1)86 {87 type = tagName.slice(tagName.indexOf(":") + 1, gradientIndex);88 if(type == "linear")89 {90 //add rotation logic91 }92 else if(type == "radial")93 {94 //add cx,cy,fx,fy,r logic95 }96 }97 fill.type = type;98 }99 stopNodes = fillNode.get("children");100 stopNodes = stopNodes ? stopNodes.filter("stop") : null;101 if(stopNodes)102 { 103 len = stopNodes.size();104 stops = [];105 for(; i < len; i = i + 1)106 {107 stopNode = stopNodes.item(i);108 stop = {};109 if(stopNode.hasAttribute("stop-color"))110 {111 stop.color = TOHEX(stopNode.getAttribute("stop-color")).toLowerCase();112 }113 if(stopNode.hasAttribute("offset"))114 {115 offset = stopNode.getAttribute("offset");116 if(offset.indexOf("%") > -1)117 {118 offset = parseFloat(offset)/100;119 }120 else121 {122 offset = 1;123 }124 stop.offset = offset;125 }126 if(stopNode.hasAttribute("stop-opacity"))127 {128 stop.opacity = stopNode.getAttribute("stop-opacity");129 }130 stops.push(stop);131 }132 fill.stops = stops;133 }134 }135 }136 else137 {138 color = toRGBA(TOHEX(color), opacity);139 fill.color = color;140 fill.type = "solid";141 }142 return fill;143 },144 getDimensions: function(shape)145 {146 var w,147 h,148 node = this._node;149 switch(shape)150 {151 case "circle" :152 w = node.getAttribute("r") * 2;153 h = w;154 break;155 case "ellipse" :156 w = parseFloat(node.getAttribute("rx")) * 2;157 h = parseFloat(node.getAttribute("ry")) * 2;158 break;159 default :160 w = node.getAttribute("width");161 h = node.getAttribute("height");162 break;163 }164 return {165 width: w,166 height: h167 }168 }169 },170 vml: {171 getStroke: function()172 {173 var node = Y.one(this._node),174 nodelist = node.get("children"),175 strokeNode,176 color,177 weight,178 opacity;179 if(nodelist)180 {181 strokeNode = nodelist.filter('stroke');182 if(strokeNode.size() > 0)183 {184 strokeNode = strokeNode.shift().getDOMNode();185 }186 }187 color = node.get("strokecolor");188 weight = node.get("strokeweight");189 opacity = strokeNode ? strokeNode.opacity : 1;190 if(!Y.Lang.isNumber(opacity))191 {192 opacity = 1;193 }194 if(color.value)195 {196 color = color.value;197 }198 color = toRGBA(TOHEX(color), parseFloat(opacity));199 weight = Math.round(weight * (96/72));200 return {201 color: color,202 weight: weight203 }204 },205 206 getFill: function()207 {208 var node = this._node,209 nodelist = Y.one(node).get("children"),210 type,211 fillNode,212 color,213 offset,214 stops,215 stopAttrs,216 stopStrings,217 opacity,218 i = 0,219 len,220 fill = {};221 if(nodelist)222 {223 fillNode = nodelist.filter("fill");224 if(fillNode.size() > 0)225 {226 fillNode = fillNode.shift().getDOMNode();227 }228 type = fillNode.type || "solid";229 if(type == "gradient")230 {231 type = "linear";232 }233 else if(type == "gradientRadial")234 {235 type = "radial";236 }237 }238 else239 {240 type = "solid";241 }242 switch(type)243 {244 case "solid" :245 color = node.get("fillcolor");246 opacity = fillNode ? fillNode.opacity : 1;247 if(color.value)248 {249 color = color.value;250 }251 color = toRGBA(TOHEX(color), parseFloat(opacity)); 252 fill.color = color;253 break;254 case "linear" :255 stopStrings = fillNode.colors;256 if(stopStrings)257 {258 stops = [];259 if(stopStrings.value)260 {261 stopStrings = stopStrings.value;262 }263 stopStrings = stopStrings.split(";");264 len = stops.length;265 for(; i < len; i = i + 1)266 {267 stopAttrs = stopStrings[i].split(" ");268 offset = stopAttrs[0];269 if(offset.indexOf("f") > -1)270 {271 offset = 100 * parseFloat(offset)/65535272 offset = Math.round(offset)/100;273 }274 stops.push( {color: TOHEX(stopAttrs[1]).toLowerCase(), offset: offset} );275 }276 fill.stops = stops;277 }278 break;279 case "radial" :280 stopStrings = fillNode.colors;281 if(stopStrings)282 {283 stops = [];284 if(stopStrings.value)285 {286 stopStrings = stopStrings.value;287 }288 stopStrings = stopStrings.split(";");289 len = stops.length;290 for(; i < len; i = i + 1)291 {292 stopAttrs = stopStrings[i].split(" ");293 offset = stopAttrs[0];294 if(offset.indexOf("f") > -1)295 {296 offset = 100 * parseFloat(offset)/65535297 offset = Math.round(offset)/100;298 }299 stops.push( {color: TOHEX(stopAttrs[1]).toLowerCase(), offset: offset} );300 }301 fill.stops = stops;302 }303 break;304 }305 fill.type = type;306 return fill;307 },308 getDimensions: function(shape)309 {310 var node = this._node,311 w = parseFloat(node.getComputedStyle("width")),312 h = parseFloat(node.getComputedStyle("height"));313 return {314 width: w,315 height: h316 };317 }318 },319 canvas: {320 getStroke: function()321 {322 var context = this._node.getDOMNode().getContext("2d"),323 color = context.strokeStyle,324 weight = context.lineWidth;325 if(color.indexOf("RGBA") > -1 || color.indexOf("rgba") > -1)326 {327 color = color.toLowerCase();328 color = color.replace(/, /g, ",");329 }330 else331 {332 color = toRGBA(TOHEX(color));333 }334 return {335 color: color,336 weight: weight337 }338 },339 getFill: function()340 {341 var context = this._node.getDOMNode().getContext("2d"),342 color = context.fillStyle;343 if(color.indexOf("RGBA") > -1 || color.indexOf("rgba") > -1)344 {345 color = color.toLowerCase();346 color = color.replace(/, /g, ",");347 }348 else349 {350 color = toRGBA(TOHEX(color));351 }352 return {353 color: color354 }355 },356 getDimensions: function(shape)357 {358 var node = this._node,359 w = parseFloat(node.get("width")),360 h = parseFloat(node.get("height")),361 wt = this.getStroke().weight || 0;362 if(wt) {363 wt = wt * 2;364 w = w - wt;365 h = h - wt;366 }367 return {368 width: w,369 height: h370 };371 }372 }373 };374 function ShapeNode(){}375 ShapeNode.prototype = IMPLEMENTATION[ENGINE];376 ShapeNode.one = function(node)377 {378 var instance = ShapeNode._instance;379 if(!instance)380 {381 instance = new Y.ShapeNode();382 ShapeNode._instance = instance;383 }384 instance._node = node;385 return instance;386 };387 Y.ShapeNode = ShapeNode;388 suite.add(new Y.Test.Case({389 name: "Graphics Gradient Tests",390 testGraphicsLoaded : function()391 {392 var shapes = Y.all(SHAPE);393 Y.Assert.areEqual(2, shapes.size(), "There should be 2 shapes.");394 },395 testRect: function()396 {397 var rect = Y.all(RECT).shift(),398 rectWidth = 685,399 rectHeight = 400,400 rectDimensions = Y.ShapeNode.one(rect).getDimensions("rect"),401 defaultStops = [402 {color: "#ff6666", opacity: 1, offset: 0},403 {color: "#00ffff", opacity: 1, offset: 0.5},404 {color: "#000000", opacity: 1, offset: 1}405 ],406 defaultStop,407 i = 0,408 len = defaultStops.length,409 fill,410 stops,411 key,412 stop;413 Y.Assert.areEqual(rectWidth, rectDimensions.width, "The width of the rectangle should be " + rectWidth + ".");414 Y.Assert.areEqual(rectHeight, rectDimensions.height, "The height of the rectangle should be " + rectHeight + ".");415 if(ENGINE != "canvas")416 {417 fill = Y.ShapeNode.one(rect).getFill();418 stops = fill.stops;419 for(; i < len; i = i + 1)420 {421 stop = stops[i];422 defaultStop = defaultStops[i];423 for(key in stop)424 {425 if(stop.hasOwnProperty(key))426 {427 Y.Assert.areEqual(defaultStop[key], stop[key], "The " + key + " value should be " + defaultStop[key] + ".");428 }429 }430 }431 }432 },433 testCircle: function()434 {435 var circle = Y.all(CIRCLE).shift(),436 circleWidth = 100,437 circleHeight = 100,438 circleDimensions = Y.ShapeNode.one(circle).getDimensions("circle"),439 defaultStops = [440 {color: "#ff6666", offset: 0, opacity: 1},441 {color: "#00ffff", offset: 0.4, opacity: 1},442 {color: "#000000", offset: 0.7, opacity: 1}443 ],444 defaultStop,445 i = 0,446 len = defaultStops.length,447 fill,448 stops,449 key,450 stop;451 Y.Assert.areEqual(circleWidth, circleDimensions.width, "The width of the circle should be " + circleWidth + ".");452 Y.Assert.areEqual(circleHeight, circleDimensions.height, "The height of the circle should be " + circleHeight + ".");453 if(ENGINE != "canvas")454 {455 fill = Y.ShapeNode.one(circle).getFill();456 stops = fill.stops;457 for(; i < len; i = i + 1)458 {459 stop = stops[i];460 defaultStop = defaultStops[i];461 if(stop && defaultStops)462 {463 for(key in stop)464 {465 if(stop.hasOwnProperty(key))466 {467 Y.Assert.areEqual(defaultStop[key], stop[key], "The " + key + " value should be " + defaultStop[key] + ".");468 }469 }470 }471 }472 }473 }474 }));475 Y.Test.Runner.add(suite);...

Full Screen

Full Screen

graphics-customshape-tests.js

Source:graphics-customshape-tests.js Github

copy

Full Screen

1YUI.add('graphics-customshape-tests', function(Y) {2 var suite = new Y.Test.Suite('graphics-customshape-tests example test suite'),3 _getClassName = Y.ClassNameManager.getClassName,4 SHAPE,5 ENGINE = "vml",6 ROUNDEDRECT,7 DOCUMENT = Y.config.doc,8 canvas = DOCUMENT && DOCUMENT.createElement("canvas"),9 graphicTests,10 svgTests,11 canvasTests,12 vmlTests,13 TORGB = Y.Color.toRGB,14 TOHEX = Y.Color.toHex,15 toRGBA = function(val, alpha) {16 alpha = Y.Lang.isNumber(alpha) ? alpha : 1;17 if (!Y.Color.re_RGB.test(val)) {18 val = TOHEX(val);19 }20 if(Y.Color.re_hex.exec(val)) {21 val = 'rgba(' + [22 parseInt(RegExp.$1, 16),23 parseInt(RegExp.$2, 16),24 parseInt(RegExp.$3, 16)25 ].join(',') + ',' + alpha + ')';26 }27 return val;28 },29 IMPLEMENTATION;30 if(DOCUMENT && DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"))31 {32 ENGINE = "svg";33 }34 else if(canvas && canvas.getContext && canvas.getContext("2d"))35 {36 ENGINE = "canvas";37 }38 SHAPE = "." + _getClassName(ENGINE + "Shape");39 ROUNDEDRECT = "." + _getClassName("roundedRect");40 IMPLEMENTATION = {41 svg: {42 getStroke: function()43 {44 var node = this._node,45 color = node.getAttribute("stroke"),46 weight = node.getAttribute("stroke-width"),47 opacity = node.getAttribute("stroke-opacity");48 color = toRGBA(TOHEX(color), opacity);49 return {50 color: color,51 weight: weight52 }53 },54 55 getFill: function()56 {57 var node = this._node,58 fillNode,59 stopNodes,60 len,61 i = 0,62 stops,63 stop,64 stopNode,65 offset,66 gradientIndex,67 tagName,68 type,69 color = node.getAttribute("fill"),70 opacity = node.getAttribute("fill-opacity"),71 fill = {};72 if(color.indexOf("url") > -1)73 {74 color = color.slice(color.indexOf("#"), color.lastIndexOf(")"));75 fillNode = Y.one(color);76 if(fillNode)77 {78 tagName = fillNode.get("tagName");79 if(tagName)80 {81 gradientIndex = tagName.indexOf("Gradient");82 if(gradientIndex > -1)83 {84 type = tagName.slice(tagName.indexOf(":") + 1, gradientIndex);85 if(type == "linear")86 {87 //add rotation logic88 }89 else if(type == "radial")90 {91 //add cx,cy,fx,fy,r logic92 }93 }94 fill.type = type;95 }96 stopNodes = fillNode.get("children");97 stopNodes = stopNodes ? stopNodes.filter("stop") : null;98 if(stopNodes)99 { 100 len = stopNodes.size();101 stops = [];102 for(; i < len; i = i + 1)103 {104 stopNode = stopNodes.item(i);105 stop = {};106 if(stopNode.hasAttribute("stop-color"))107 {108 stop.color = TOHEX(stopNode.getAttribute("stop-color")).toLowerCase();109 }110 if(stopNode.hasAttribute("offset"))111 {112 offset = stopNode.getAttribute("offset");113 if(offset.indexOf("%") > -1)114 {115 offset = parseFloat(offset)/100;116 }117 else118 {119 offset = 1;120 }121 stop.offset = offset;122 }123 if(stopNode.hasAttribute("stop-opacity"))124 {125 stop.opacity = stopNode.getAttribute("stop-opacity");126 }127 stops.push(stop);128 }129 fill.stops = stops;130 }131 }132 }133 else134 {135 color = toRGBA(TOHEX(color), opacity);136 fill.color = color;137 fill.type = "solid";138 }139 return fill;140 },141 getDimensions: function(shape)142 {143 var w,144 h,145 node = this._node;146 switch(shape)147 {148 case "circle" :149 w = node.getAttribute("r") * 2;150 h = w;151 break;152 case "ellipse" :153 w = parseFloat(node.getAttribute("rx")) * 2;154 h = parseFloat(node.getAttribute("ry")) * 2;155 break;156 default :157 w = node.get("width");158 h = node.get("height");159 break;160 }161 return {162 width: w,163 height: h164 }165 }166 },167 vml: {168 getStroke: function()169 {170 var node = Y.one(this._node),171 nodelist = node.get("children"),172 strokeNode,173 color,174 weight,175 opacity;176 if(nodelist)177 {178 strokeNode = nodelist.filter('stroke');179 if(strokeNode.size() > 0)180 {181 strokeNode = strokeNode.shift().getDOMNode();182 }183 }184 color = node.get("strokecolor");185 weight = node.get("strokeweight");186 opacity = strokeNode ? strokeNode.opacity : 1;187 if(!Y.Lang.isNumber(opacity))188 {189 opacity = 1;190 }191 if(color.value)192 {193 color = color.value;194 }195 color = toRGBA(TOHEX(color), parseFloat(opacity));196 weight = Math.round(weight * (96/72));197 return {198 color: color,199 weight: weight200 }201 },202 getFill: function()203 {204 var node = this._node,205 nodelist = Y.one(node).get("children"),206 type,207 fillNode,208 color,209 offset,210 stops,211 stopAttrs,212 stopStrings,213 opacity,214 i = 0,215 len,216 fill = {};217 if(nodelist)218 {219 fillNode = nodelist.filter("fill");220 if(fillNode.size() > 0)221 {222 fillNode = fillNode.shift().getDOMNode();223 }224 type = fillNode.type || "solid";225 if(type == "gradient")226 {227 type = "linear";228 }229 else if(type == "gradientRadial")230 {231 type = "radial";232 }233 }234 else235 {236 type = "solid";237 }238 switch(type)239 {240 case "solid" :241 color = node.get("fillcolor");242 opacity = fillNode ? fillNode.opacity : 1;243 if(color.value)244 {245 color = color.value;246 }247 color = toRGBA(TOHEX(color), parseFloat(opacity)); 248 fill.color = color;249 break;250 case "linear" :251 stopStrings = fillNode.colors;252 if(stopStrings)253 {254 stops = [];255 if(stopStrings.value)256 {257 stopStrings = stopStrings.value;258 }259 stopStrings = stopStrings.split(";");260 len = stops.length;261 for(; i < len; i = i + 1)262 {263 stopAttrs = stopStrings[i].split(" ");264 offset = stopAttrs[0];265 if(offset.indexOf("f") > -1)266 {267 offset = 100 * parseFloat(offset)/65535268 offset = Math.round(offset)/100;269 }270 stops.push( {color: TOHEX(stopAttrs[1]).toLowerCase(), offset: offset} );271 }272 fill.stops = stops;273 }274 break;275 case "radial" :276 stopStrings = fillNode.colors;277 if(stopStrings)278 {279 stops = [];280 if(stopStrings.value)281 {282 stopStrings = stopStrings.value;283 }284 stopStrings = stopStrings.split(";");285 len = stops.length;286 for(; i < len; i = i + 1)287 {288 stopAttrs = stopStrings[i].split(" ");289 offset = stopAttrs[0];290 if(offset.indexOf("f") > -1)291 {292 offset = 100 * parseFloat(offset)/65535293 offset = Math.round(offset)/100;294 }295 stops.push( {color: TOHEX(stopAttrs[1]).toLowerCase(), offset: offset} );296 }297 fill.stops = stops;298 }299 break;300 }301 fill.type = type;302 return fill;303 },304 getDimensions: function(shape)305 {306 var node = this._node,307 w = parseFloat(node.getComputedStyle("width")),308 h = parseFloat(node.getComputedStyle("height"));309 return {310 width: w,311 height: h312 };313 }314 },315 canvas: {316 getStroke: function()317 {318 var context = this._node.getDOMNode().getContext("2d"),319 color = context.strokeStyle,320 weight = context.lineWidth;321 if(color.indexOf("RGBA") > -1 || color.indexOf("rgba") > -1)322 {323 color = color.toLowerCase();324 color = color.replace(/, /g, ",");325 }326 else327 {328 color = toRGBA(TOHEX(color));329 }330 return {331 color: color,332 weight: weight333 }334 },335 getFill: function()336 {337 var context = this._node.getDOMNode().getContext("2d"),338 color = context.fillStyle;339 if(color.indexOf("RGBA") > -1 || color.indexOf("rgba") > -1)340 {341 color = color.toLowerCase();342 color = color.replace(/, /g, ",");343 }344 else345 {346 color = toRGBA(TOHEX(color));347 }348 return {349 color: color350 }351 },352 getDimensions: function(shape)353 {354 var node = this._node,355 w = parseFloat(node.get("width")),356 h = parseFloat(node.get("height")),357 wt = this.getStroke().weight || 0;358 if(wt) {359 wt = wt * 2;360 w = w - wt;361 h = h - wt;362 }363 return {364 width: w,365 height: h366 };367 }368 }369 };370 function ShapeNode(){}371 ShapeNode.prototype = IMPLEMENTATION[ENGINE];372 ShapeNode.one = function(node)373 {374 var instance = ShapeNode._instance;375 if(!instance)376 {377 instance = new Y.ShapeNode();378 ShapeNode._instance = instance;379 }380 instance._node = node;381 return instance;382 };383 Y.ShapeNode = ShapeNode;384 suite.add(new Y.Test.Case({385 name: "Graphics Path Tests",386 testGraphicsLoaded : function()387 {388 var shapes = Y.all(SHAPE),389 paths = Y.all(ROUNDEDRECT);390 Y.Assert.areEqual(1, shapes.size(), "There should be 1 shape.");391 Y.Assert.areEqual(1, paths.size(), "There should be 1 roundedRect instance.");392 },393 testCustomShape: function()394 {395 var roundRect = Y.all(ROUNDEDRECT).shift(),396 roundRectWidth = 300,397 roundRectHeight = 200,398 roundRectDimensions = Y.ShapeNode.one(roundRect).getDimensions("path"),399 defaultStops = [400 {color: "#9aa9bb", offset: 0, opacity: 1},401 {color: "#eeefff", offset: 0.4, opacity: 1},402 {color: "#00000f", offset: 0.8, opacity: 1},403 {color: "#9aa9bb", offset: 1, opacity: 1}404 ],405 defaultStop,406 i = 0,407 len = defaultStops.length,408 fill,409 stops, 410 key,411 stop;412 //Need to add logic for parsing size of path element in svg413 if(ENGINE != "svg")414 {415 Y.Assert.areEqual(roundRectWidth, roundRectDimensions.width, "The width of the roundRect should be " + roundRectWidth + ".");416 Y.Assert.areEqual(roundRectHeight, roundRectDimensions.height, "The height of the roundRect should be " + roundRectHeight + ".");417 }418 if(ENGINE != "canvas")419 {420 fill = Y.ShapeNode.one(roundRect).getFill();421 stops = fill.stops;422 for(; i < len; i = i + 1)423 {424 stop = stops[i];425 defaultStop = defaultStops[i];426 if(stop && defaultStops)427 {428 for(key in stop)429 {430 if(stop.hasOwnProperty(key))431 {432 Y.Assert.areEqual(defaultStop[key], stop[key], "The " + key + " value should be " + defaultStop[key] + ".");433 }434 }435 }436 }437 }438 }439 }));440 Y.Test.Runner.add(suite);...

Full Screen

Full Screen

graphics-violin-tests.js

Source:graphics-violin-tests.js Github

copy

Full Screen

1YUI.add('graphics-violin-tests', function(Y) {2 var suite = new Y.Test.Suite('graphics-violin-tests example test suite'),3 _getClassName = Y.ClassNameManager.getClassName,4 SHAPE,5 ENGINE = "vml",6 ELLIPSE,7 RECT,8 PATH,9 DOCUMENT = Y.config.doc,10 canvas = DOCUMENT && DOCUMENT.createElement("canvas"),11 graphicTests,12 svgTests,13 canvasTests,14 vmlTests,15 TORGB = Y.Color.toRGB,16 TOHEX = Y.Color.toHex,17 toRGBA = function(val, alpha) {18 alpha = Y.Lang.isNumber(alpha) ? alpha : 1;19 if (!Y.Color.re_RGB.test(val)) {20 val = TOHEX(val);21 }22 if(Y.Color.re_hex.exec(val)) {23 val = 'rgba(' + [24 parseInt(RegExp.$1, 16),25 parseInt(RegExp.$2, 16),26 parseInt(RegExp.$3, 16)27 ].join(',') + ',' + alpha + ')';28 }29 return val;30 },31 IMPLEMENTATION;32 if(DOCUMENT && DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"))33 {34 ENGINE = "svg";35 }36 else if(canvas && canvas.getContext && canvas.getContext("2d"))37 {38 ENGINE = "canvas";39 }40 SHAPE = "." + _getClassName(ENGINE + "Shape");41 ELLIPSE = "." + _getClassName(ENGINE + "Ellipse");42 RECT = "." + _getClassName(ENGINE + "Rect");43 PATH = "." + _getClassName(ENGINE + "Path");44 IMPLEMENTATION = {45 svg: {46 getStroke: function()47 {48 var node = this._node,49 color = node.getAttribute("stroke"),50 weight = node.getAttribute("stroke-width"),51 opacity = node.getAttribute("stroke-opacity");52 color = toRGBA(TOHEX(color), opacity);53 return {54 color: color,55 weight: weight56 }57 },58 getFill: function()59 {60 var node = this._node,61 fillNode,62 stopNodes,63 len,64 i = 0,65 stops,66 stop,67 stopNode,68 offset,69 gradientIndex,70 tagName,71 type,72 color = node.getAttribute("fill"),73 opacity = node.getAttribute("fill-opacity"),74 fill = {};75 if(color.indexOf("url") > -1)76 {77 color = color.slice(color.indexOf("#"), color.lastIndexOf(")"));78 fillNode = Y.one(color);79 if(fillNode)80 {81 tagName = fillNode.get("tagName");82 if(tagName)83 {84 gradientIndex = tagName.indexOf("Gradient");85 if(gradientIndex > -1)86 {87 type = tagName.slice(tagName.indexOf(":") + 1, gradientIndex);88 if(type == "linear")89 {90 //add rotation logic91 }92 else if(type == "radial")93 {94 //add cx,cy,fx,fy,r logic95 }96 }97 fill.type = type;98 }99 stopNodes = fillNode.get("children");100 stopNodes = stopNodes ? stopNodes.filter("stop") : null;101 if(stopNodes)102 { 103 len = stopNodes.size();104 stops = [];105 for(; i < len; i = i + 1)106 {107 stopNode = stopNodes.item(i);108 stop = {};109 if(stopNode.hasAttribute("stop-color"))110 {111 stop.color = TOHEX(stopNode.getAttribute("stop-color")).toLowerCase();112 }113 if(stopNode.hasAttribute("offset"))114 {115 offset = stopNode.getAttribute("offset");116 if(offset.indexOf("%") > -1)117 {118 offset = parseFloat(offset)/100;119 }120 else121 {122 offset = 1;123 }124 stop.offset = offset;125 }126 if(stopNode.hasAttribute("stop-opacity"))127 {128 stop.opacity = stopNode.getAttribute("stop-opacity");129 }130 stops.push(stop);131 }132 fill.stops = stops;133 }134 }135 }136 else137 {138 color = toRGBA(TOHEX(color), opacity);139 fill.color = color;140 fill.type = "solid";141 }142 return fill;143 },144 getDimensions: function(shape)145 {146 var w,147 h,148 node = this._node;149 switch(shape)150 {151 case "circle" :152 w = node.getAttribute("r") * 2;153 h = w;154 break;155 case "ellipse" :156 w = parseFloat(node.getAttribute("rx")) * 2;157 h = parseFloat(node.getAttribute("ry")) * 2;158 break;159 default :160 w = node.get("width");161 h = node.get("height");162 break;163 }164 return {165 width: w,166 height: h167 }168 }169 },170 vml: {171 getStroke: function()172 {173 var node = Y.one(this._node),174 nodelist = node.get("children"),175 strokeNode,176 color,177 weight,178 opacity;179 if(nodelist)180 {181 strokeNode = nodelist.filter('stroke');182 if(strokeNode.size() > 0)183 {184 strokeNode = strokeNode.shift().getDOMNode();185 }186 }187 color = node.get("strokecolor");188 weight = node.get("strokeweight");189 opacity = strokeNode ? strokeNode.opacity : 1;190 if(!Y.Lang.isNumber(opacity))191 {192 opacity = 1;193 }194 if(color.value)195 {196 color = color.value;197 }198 color = toRGBA(TOHEX(color), parseFloat(opacity));199 weight = Math.round(weight * (96/72));200 return {201 color: color,202 weight: weight203 }204 },205 getFill: function()206 {207 var node = this._node,208 nodelist = Y.one(node).get("children"),209 type,210 fillNode,211 color,212 offset,213 stops,214 stopAttrs,215 stopStrings,216 opacity,217 i = 0,218 len,219 fill = {};220 if(nodelist)221 {222 fillNode = nodelist.filter("fill");223 if(fillNode.size() > 0)224 {225 fillNode = fillNode.shift().getDOMNode();226 }227 type = fillNode.type || "solid";228 if(type == "gradient")229 {230 type = "linear";231 }232 else if(type == "gradientRadial")233 {234 type = "radial";235 }236 }237 else238 {239 type = "solid";240 }241 switch(type)242 {243 case "solid" :244 color = node.get("fillcolor");245 opacity = fillNode ? fillNode.opacity : 1;246 if(color.value)247 {248 color = color.value;249 }250 color = toRGBA(TOHEX(color), parseFloat(opacity)); 251 fill.color = color;252 break;253 case "linear" :254 stopStrings = fillNode.colors;255 if(stopStrings)256 {257 stops = [];258 if(stopStrings.value)259 {260 stopStrings = stopStrings.value;261 }262 stopStrings = stopStrings.split(";");263 len = stops.length;264 for(; i < len; i = i + 1)265 {266 stopAttrs = stopStrings[i].split(" ");267 offset = stopAttrs[0];268 if(offset.indexOf("f") > -1)269 {270 offset = 100 * parseFloat(offset)/65535271 offset = Math.round(offset)/100;272 }273 stops.push( {color: TOHEX(stopAttrs[1]).toLowerCase(), offset: offset} );274 }275 fill.stops = stops;276 }277 break;278 case "radial" :279 stopStrings = fillNode.colors;280 if(stopStrings)281 {282 stops = [];283 if(stopStrings.value)284 {285 stopStrings = stopStrings.value;286 }287 stopStrings = stopStrings.split(";");288 len = stops.length;289 for(; i < len; i = i + 1)290 {291 stopAttrs = stopStrings[i].split(" ");292 offset = stopAttrs[0];293 if(offset.indexOf("f") > -1)294 {295 offset = 100 * parseFloat(offset)/65535296 offset = Math.round(offset)/100;297 }298 stops.push( {color: TOHEX(stopAttrs[1]).toLowerCase(), offset: offset} );299 }300 fill.stops = stops;301 }302 break;303 }304 fill.type = type;305 return fill;306 },307 getDimensions: function(shape)308 {309 var node = this._node,310 w = parseFloat(node.getComputedStyle("width")),311 h = parseFloat(node.getComputedStyle("height"));312 return {313 width: w,314 height: h315 };316 }317 },318 canvas: {319 getStroke: function()320 {321 var context = this._node.getDOMNode().getContext("2d"),322 color = context.strokeStyle,323 weight = context.lineWidth;324 if(color.indexOf("RGBA") > -1 || color.indexOf("rgba") > -1)325 {326 color = color.toLowerCase();327 color = color.replace(/, /g, ",");328 }329 else330 {331 color = toRGBA(TOHEX(color));332 }333 return {334 color: color,335 weight: weight336 }337 },338 getFill: function()339 {340 var context = this._node.getDOMNode().getContext("2d"),341 color = context.fillStyle;342 if(color.indexOf("RGBA") > -1 || color.indexOf("rgba") > -1)343 {344 color = color.toLowerCase();345 color = color.replace(/, /g, ",");346 }347 else348 {349 color = toRGBA(TOHEX(color));350 }351 return {352 color: color353 }354 },355 getDimensions: function(shape)356 {357 var node = this._node,358 w = parseFloat(node.get("width")),359 h = parseFloat(node.get("height")),360 wt = this.getStroke().weight || 0;361 if(wt) {362 wt = wt * 2;363 w = w - wt;364 h = h - wt;365 }366 return {367 width: w,368 height: h369 };370 }371 }372 };373 function ShapeNode(){}374 ShapeNode.prototype = IMPLEMENTATION[ENGINE];375 ShapeNode.one = function(node)376 {377 var instance = ShapeNode._instance;378 if(!instance)379 {380 instance = new Y.ShapeNode();381 ShapeNode._instance = instance;382 }383 instance._node = node;384 return instance;385 };386 Y.ShapeNode = ShapeNode;387 suite.add(new Y.Test.Case({388 name: "Graphics Violin Tests",389 testGraphicsLoaded : function()390 {391 var shapes = Y.all(SHAPE),392 ellipses = Y.all(ELLIPSE),393 rects = Y.all(RECT),394 paths = Y.all(PATH),395 ie = Y.UA.ie,396 numberofpaths = ie && ie < 9 ? 19 : 20,397 totalshapes = numberofpaths + 8;398 Y.Assert.areEqual(totalshapes, shapes.size(), "There should be " + totalshapes + " shape.");399 Y.Assert.areEqual(7, ellipses.size(), "There should be 7 Ellipse instance.");400 Y.Assert.areEqual(1, rects.size(), "There should be 3 Rect instances.");401 Y.Assert.areEqual(numberofpaths, paths.size(), "There should be " + numberofpaths + " Path instances.");402 }403 }));404 Y.Test.Runner.add(suite);...

Full Screen

Full Screen

graphics-muddyglass-tests.js

Source:graphics-muddyglass-tests.js Github

copy

Full Screen

1YUI.add('graphics-muddyglass-tests', function(Y) {2 var suite = new Y.Test.Suite('graphics-muddyglass-tests example test suite'),3 _getClassName = Y.ClassNameManager.getClassName,4 SHAPE,5 ENGINE = "vml",6 ELLIPSE,7 RECT,8 DOCUMENT = Y.config.doc,9 canvas = DOCUMENT && DOCUMENT.createElement("canvas"),10 graphicTests,11 svgTests,12 canvasTests,13 vmlTests,14 TORGB = Y.Color.toRGB,15 TOHEX = Y.Color.toHex,16 toRGBA = function(val, alpha) {17 alpha = Y.Lang.isNumber(alpha) ? alpha : 1;18 if (!Y.Color.re_RGB.test(val)) {19 val = TOHEX(val);20 }21 if(Y.Color.re_hex.exec(val)) {22 val = 'rgba(' + [23 parseInt(RegExp.$1, 16),24 parseInt(RegExp.$2, 16),25 parseInt(RegExp.$3, 16)26 ].join(',') + ',' + alpha + ')';27 }28 return val;29 },30 IMPLEMENTATION;31 if(DOCUMENT && DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"))32 {33 ENGINE = "svg";34 }35 else if(canvas && canvas.getContext && canvas.getContext("2d"))36 {37 ENGINE = "canvas";38 }39 SHAPE = "." + _getClassName(ENGINE + "Shape");40 ELLIPSE = "." + _getClassName(ENGINE + "Ellipse");41 RECT = "." + _getClassName(ENGINE + "Rect");42 IMPLEMENTATION = {43 svg: {44 getStroke: function()45 {46 var node = this._node,47 color = node.getAttribute("stroke"),48 weight = node.getAttribute("stroke-width"),49 opacity = node.getAttribute("stroke-opacity");50 color = toRGBA(TOHEX(color), opacity);51 return {52 color: color,53 weight: weight54 }55 },56 getFill: function()57 {58 var node = this._node,59 fillNode,60 stopNodes,61 len,62 i = 0,63 stops,64 stop,65 stopNode,66 offset,67 gradientIndex,68 tagName,69 type,70 color = node.getAttribute("fill"),71 opacity = node.getAttribute("fill-opacity"),72 fill = {};73 if(color.indexOf("url") > -1)74 {75 color = color.slice(color.indexOf("#"), color.lastIndexOf(")"));76 fillNode = Y.one(color);77 if(fillNode)78 {79 tagName = fillNode.get("tagName");80 if(tagName)81 {82 gradientIndex = tagName.indexOf("Gradient");83 if(gradientIndex > -1)84 {85 type = tagName.slice(tagName.indexOf(":") + 1, gradientIndex);86 if(type == "linear")87 {88 //add rotation logic89 }90 else if(type == "radial")91 {92 //add cx,cy,fx,fy,r logic93 }94 }95 fill.type = type;96 }97 stopNodes = fillNode.get("children");98 stopNodes = stopNodes ? stopNodes.filter("stop") : null;99 if(stopNodes)100 { 101 len = stopNodes.size();102 stops = [];103 for(; i < len; i = i + 1)104 {105 stopNode = stopNodes.item(i);106 stop = {};107 if(stopNode.hasAttribute("stop-color"))108 {109 stop.color = TOHEX(stopNode.getAttribute("stop-color")).toLowerCase();110 }111 if(stopNode.hasAttribute("offset"))112 {113 offset = stopNode.getAttribute("offset");114 if(offset.indexOf("%") > -1)115 {116 offset = parseFloat(offset)/100;117 }118 else119 {120 offset = 1;121 }122 stop.offset = offset;123 }124 if(stopNode.hasAttribute("stop-opacity"))125 {126 stop.opacity = stopNode.getAttribute("stop-opacity");127 }128 stops.push(stop);129 }130 fill.stops = stops;131 }132 }133 }134 else135 {136 color = toRGBA(TOHEX(color), opacity);137 fill.color = color;138 fill.type = "solid";139 }140 return fill;141 },142 getDimensions: function(shape)143 {144 var w,145 h,146 node = this._node;147 switch(shape)148 {149 case "circle" :150 w = node.getAttribute("r") * 2;151 h = w;152 break;153 case "ellipse" :154 w = parseFloat(node.getAttribute("rx")) * 2;155 h = parseFloat(node.getAttribute("ry")) * 2;156 break;157 default :158 w = node.get("width");159 h = node.get("height");160 break;161 }162 return {163 width: w,164 height: h165 }166 }167 },168 vml: {169 getStroke: function()170 {171 var node = Y.one(this._node),172 nodelist = node.get("children"),173 strokeNode,174 color,175 weight,176 opacity;177 if(nodelist)178 {179 strokeNode = nodelist.filter('stroke');180 if(strokeNode.size() > 0)181 {182 strokeNode = strokeNode.shift().getDOMNode();183 }184 }185 color = node.get("strokecolor");186 weight = node.get("strokeweight");187 opacity = strokeNode ? strokeNode.opacity : 1;188 if(!Y.Lang.isNumber(opacity))189 {190 opacity = 1;191 }192 if(color.value)193 {194 color = color.value;195 }196 color = toRGBA(TOHEX(color), parseFloat(opacity));197 weight = Math.round(weight * (96/72));198 return {199 color: color,200 weight: weight201 }202 },203 getFill: function()204 {205 var node = this._node,206 nodelist = Y.one(node).get("children"),207 type,208 fillNode,209 color,210 offset,211 stops,212 stopAttrs,213 stopStrings,214 opacity,215 i = 0,216 len,217 fill = {};218 if(nodelist)219 {220 fillNode = nodelist.filter("fill");221 if(fillNode.size() > 0)222 {223 fillNode = fillNode.shift().getDOMNode();224 }225 type = fillNode.type || "solid";226 if(type == "gradient")227 {228 type = "linear";229 }230 else if(type == "gradientRadial")231 {232 type = "radial";233 }234 }235 else236 {237 type = "solid";238 }239 switch(type)240 {241 case "solid" :242 color = node.get("fillcolor");243 opacity = fillNode ? fillNode.opacity : 1;244 if(color.value)245 {246 color = color.value;247 }248 color = toRGBA(TOHEX(color), parseFloat(opacity)); 249 fill.color = color;250 break;251 case "linear" :252 stopStrings = fillNode.colors;253 if(stopStrings)254 {255 stops = [];256 if(stopStrings.value)257 {258 stopStrings = stopStrings.value;259 }260 stopStrings = stopStrings.split(";");261 len = stops.length;262 for(; i < len; i = i + 1)263 {264 stopAttrs = stopStrings[i].split(" ");265 offset = stopAttrs[0];266 if(offset.indexOf("f") > -1)267 {268 offset = 100 * parseFloat(offset)/65535269 offset = Math.round(offset)/100;270 }271 stops.push( {color: TOHEX(stopAttrs[1]).toLowerCase(), offset: offset} );272 }273 fill.stops = stops;274 }275 break;276 case "radial" :277 stopStrings = fillNode.colors;278 if(stopStrings)279 {280 stops = [];281 if(stopStrings.value)282 {283 stopStrings = stopStrings.value;284 }285 stopStrings = stopStrings.split(";");286 len = stops.length;287 for(; i < len; i = i + 1)288 {289 stopAttrs = stopStrings[i].split(" ");290 offset = stopAttrs[0];291 if(offset.indexOf("f") > -1)292 {293 offset = 100 * parseFloat(offset)/65535294 offset = Math.round(offset)/100;295 }296 stops.push( {color: TOHEX(stopAttrs[1]).toLowerCase(), offset: offset} );297 }298 fill.stops = stops;299 }300 break;301 }302 fill.type = type;303 return fill;304 },305 getDimensions: function(shape)306 {307 var node = this._node,308 w = parseFloat(node.getComputedStyle("width")),309 h = parseFloat(node.getComputedStyle("height"));310 return {311 width: w,312 height: h313 };314 }315 },316 canvas: {317 getStroke: function()318 {319 var context = this._node.getDOMNode().getContext("2d"),320 color = context.strokeStyle,321 weight = context.lineWidth;322 if(color.indexOf("RGBA") > -1 || color.indexOf("rgba") > -1)323 {324 color = color.toLowerCase();325 color = color.replace(/, /g, ",");326 }327 else328 {329 color = toRGBA(TOHEX(color));330 }331 return {332 color: color,333 weight: weight334 }335 },336 getFill: function()337 {338 var context = this._node.getDOMNode().getContext("2d"),339 color = context.fillStyle;340 if(color.indexOf("RGBA") > -1 || color.indexOf("rgba") > -1)341 {342 color = color.toLowerCase();343 color = color.replace(/, /g, ",");344 }345 else346 {347 color = toRGBA(TOHEX(color));348 }349 return {350 color: color351 }352 },353 getDimensions: function(shape)354 {355 var node = this._node,356 w = parseFloat(node.get("width")),357 h = parseFloat(node.get("height")),358 wt = this.getStroke().weight || 0;359 if(wt) {360 wt = wt * 2;361 w = w - wt;362 h = h - wt;363 }364 return {365 width: w,366 height: h367 };368 }369 }370 };371 function ShapeNode(){}372 ShapeNode.prototype = IMPLEMENTATION[ENGINE];373 ShapeNode.one = function(node)374 {375 var instance = ShapeNode._instance;376 if(!instance)377 {378 instance = new Y.ShapeNode();379 ShapeNode._instance = instance;380 }381 instance._node = node;382 return instance;383 };384 Y.ShapeNode = ShapeNode;385 suite.add(new Y.Test.Case({386 name: "Graphics Transparent Glass Tests",387 testGraphicsLoaded : function()388 {389 var shapes = Y.all(SHAPE),390 ellipses = Y.all(ELLIPSE),391 rects = Y.all(RECT);392 Y.Assert.areEqual(4, shapes.size(), "There should be 1 shape.");393 Y.Assert.areEqual(1, ellipses.size(), "There should be 1 Ellipse instance.");394 Y.Assert.areEqual(3, rects.size(), "There should be 3 Rect instances.");395 }396 }));397 Y.Test.Runner.add(suite);...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run testcontainers-python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful