Best JavaScript code snippet using storybook-root
g.raphael.js
Source:g.raphael.js
1/*!2 * g.Raphael 0.5 - Charting library, based on Raphaël3 *4 * Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com)5 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.6 */7/*8 * Tooltips on Element prototype9 */10/*\11 * Element.popup12 [ method ]13 **14 * Puts the context Element in a 'popup' tooltip. Can also be used on sets.15 **16 > Parameters17 **18 - dir (string) location of Element relative to the tail: `'down'`, `'left'`, `'up'` [default], or `'right'`.19 - size (number) amount of bevel/padding around the Element, as well as half the width and height of the tail [default: `5`]20 - x (number) x coordinate of the popup's tail [default: Element's `x` or `cx`]21 - y (number) y coordinate of the popup's tail [default: Element's `y` or `cy`]22 **23 = (object) path element of the popup24 > Usage25 | paper.circle(50, 50, 5).attr({26 | stroke: "#fff",27 | fill: "0-#c9de96-#8ab66b:44-#398235"28 | }).popup();29 \*/30Raphael.el.popup = function (dir, size, x, y) {31 var paper = this.paper || this[0].paper,32 bb, xy, center, cw, ch;33 if (!paper) return;34 switch (this.type) {35 case 'text':36 case 'circle':37 case 'ellipse': center = true; break;38 default: center = false;39 }40 dir = dir == null ? 'up' : dir;41 size = size || 5;42 bb = this.getBBox();43 x = typeof x == 'number' ? x : (center ? bb.x + bb.width / 2 : bb.x);44 y = typeof y == 'number' ? y : (center ? bb.y + bb.height / 2 : bb.y);45 cw = Math.max(bb.width / 2 - size, 0);46 ch = Math.max(bb.height / 2 - size, 0);47 this.translate(x - bb.x - (center ? bb.width / 2 : 0), y - bb.y - (center ? bb.height / 2 : 0));48 bb = this.getBBox();49 var paths = {50 up: [51 'M', x, y,52 'l', -size, -size, -cw, 0,53 'a', size, size, 0, 0, 1, -size, -size,54 'l', 0, -bb.height,55 'a', size, size, 0, 0, 1, size, -size,56 'l', size * 2 + cw * 2, 0,57 'a', size, size, 0, 0, 1, size, size,58 'l', 0, bb.height,59 'a', size, size, 0, 0, 1, -size, size,60 'l', -cw, 0,61 'z'62 ].join(','),63 down: [64 'M', x, y,65 'l', size, size, cw, 0,66 'a', size, size, 0, 0, 1, size, size,67 'l', 0, bb.height,68 'a', size, size, 0, 0, 1, -size, size,69 'l', -(size * 2 + cw * 2), 0,70 'a', size, size, 0, 0, 1, -size, -size,71 'l', 0, -bb.height,72 'a', size, size, 0, 0, 1, size, -size,73 'l', cw, 0,74 'z'75 ].join(','),76 left: [77 'M', x, y,78 'l', -size, size, 0, ch,79 'a', size, size, 0, 0, 1, -size, size,80 'l', -bb.width, 0,81 'a', size, size, 0, 0, 1, -size, -size,82 'l', 0, -(size * 2 + ch * 2),83 'a', size, size, 0, 0, 1, size, -size,84 'l', bb.width, 0,85 'a', size, size, 0, 0, 1, size, size,86 'l', 0, ch,87 'z'88 ].join(','),89 right: [90 'M', x, y,91 'l', size, -size, 0, -ch,92 'a', size, size, 0, 0, 1, size, -size,93 'l', bb.width, 0,94 'a', size, size, 0, 0, 1, size, size,95 'l', 0, size * 2 + ch * 2,96 'a', size, size, 0, 0, 1, -size, size,97 'l', -bb.width, 0,98 'a', size, size, 0, 0, 1, -size, -size,99 'l', 0, -ch,100 'z'101 ].join(',')102 };103 xy = {104 up: { x: -!center * (bb.width / 2), y: -size * 2 - (center ? bb.height / 2 : bb.height) },105 down: { x: -!center * (bb.width / 2), y: size * 2 + (center ? bb.height / 2 : bb.height) },106 left: { x: -size * 2 - (center ? bb.width / 2 : bb.width), y: -!center * (bb.height / 2) },107 right: { x: size * 2 + (center ? bb.width / 2 : bb.width), y: -!center * (bb.height / 2) }108 }[dir];109 this.translate(xy.x, xy.y);110 return paper.path(paths[dir]).attr({ fill: "#000", stroke: "none" }).insertBefore(this.node ? this : this[0]);111};112/*\113 * Element.tag114 [ method ]115 **116 * Puts the context Element in a 'tag' tooltip. Can also be used on sets.117 **118 > Parameters119 **120 - angle (number) angle of orientation in degrees [default: `0`]121 - r (number) radius of the loop [default: `5`]122 - x (number) x coordinate of the center of the tag loop [default: Element's `x` or `cx`]123 - y (number) y coordinate of the center of the tag loop [default: Element's `x` or `cx`]124 **125 = (object) path element of the tag126 > Usage127 | paper.circle(50, 50, 15).attr({128 | stroke: "#fff",129 | fill: "0-#c9de96-#8ab66b:44-#398235"130 | }).tag(60);131 \*/132Raphael.el.tag = function (angle, r, x, y) {133 var d = 3,134 paper = this.paper || this[0].paper;135 if (!paper) return;136 var p = paper.path().attr({ fill: '#000', stroke: '#000' }),137 bb = this.getBBox(),138 dx, R, center, tmp;139 switch (this.type) {140 case 'text':141 case 'circle':142 case 'ellipse': center = true; break;143 default: center = false;144 }145 angle = angle || 0;146 x = typeof x == 'number' ? x : (center ? bb.x + bb.width / 2 : bb.x);147 y = typeof y == 'number' ? y : (center ? bb.y + bb.height / 2 : bb.y);148 r = r == null ? 5 : r;149 R = .5522 * r;150 if (bb.height >= r * 2) {151 p.attr({152 path: [153 "M", x, y + r,154 "a", r, r, 0, 1, 1, 0, -r * 2, r, r, 0, 1, 1, 0, r * 2,155 "m", 0, -r * 2 -d,156 "a", r + d, r + d, 0, 1, 0, 0, (r + d) * 2,157 "L", x + r + d, y + bb.height / 2 + d,158 "l", bb.width + 2 * d, 0, 0, -bb.height - 2 * d, -bb.width - 2 * d, 0,159 "L", x, y - r - d160 ].join(",")161 });162 } else {163 dx = Math.sqrt(Math.pow(r + d, 2) - Math.pow(bb.height / 2 + d, 2));164 p.attr({165 path: [166 "M", x, y + r,167 "c", -R, 0, -r, R - r, -r, -r, 0, -R, r - R, -r, r, -r, R, 0, r, r - R, r, r, 0, R, R - r, r, -r, r,168 "M", x + dx, y - bb.height / 2 - d,169 "a", r + d, r + d, 0, 1, 0, 0, bb.height + 2 * d,170 "l", r + d - dx + bb.width + 2 * d, 0, 0, -bb.height - 2 * d,171 "L", x + dx, y - bb.height / 2 - d172 ].join(",")173 });174 }175 angle = 360 - angle;176 p.rotate(angle, x, y);177 if (this.attrs) {178 //elements179 this.attr(this.attrs.x ? 'x' : 'cx', x + r + d + (!center ? this.type == 'text' ? bb.width : 0 : bb.width / 2)).attr('y', center ? y : y - bb.height / 2);180 this.rotate(angle, x, y);181 angle > 90 && angle < 270 && this.attr(this.attrs.x ? 'x' : 'cx', x - r - d - (!center ? bb.width : bb.width / 2)).rotate(180, x, y);182 } else {183 //sets184 if (angle > 90 && angle < 270) {185 this.translate(x - bb.x - bb.width - r - d, y - bb.y - bb.height / 2);186 this.rotate(angle - 180, bb.x + bb.width + r + d, bb.y + bb.height / 2);187 } else {188 this.translate(x - bb.x + r + d, y - bb.y - bb.height / 2);189 this.rotate(angle, bb.x - r - d, bb.y + bb.height / 2); 190 }191 }192 return p.insertBefore(this.node ? this : this[0]);193};194/*\195 * Element.drop196 [ method ]197 **198 * Puts the context Element in a 'drop' tooltip. Can also be used on sets.199 **200 > Parameters201 **202 - angle (number) angle of orientation in degrees [default: `0`]203 - x (number) x coordinate of the drop's point [default: Element's `x` or `cx`]204 - y (number) y coordinate of the drop's point [default: Element's `x` or `cx`]205 **206 = (object) path element of the drop207 > Usage208 | paper.circle(50, 50, 8).attr({209 | stroke: "#fff",210 | fill: "0-#c9de96-#8ab66b:44-#398235"211 | }).drop(60);212 \*/213Raphael.el.drop = function (angle, x, y) {214 var bb = this.getBBox(),215 paper = this.paper || this[0].paper,216 center, size, p, dx, dy;217 if (!paper) return;218 switch (this.type) {219 case 'text':220 case 'circle':221 case 'ellipse': center = true; break;222 default: center = false;223 }224 angle = angle || 0;225 x = typeof x == 'number' ? x : (center ? bb.x + bb.width / 2 : bb.x);226 y = typeof y == 'number' ? y : (center ? bb.y + bb.height / 2 : bb.y);227 size = Math.max(bb.width, bb.height) + Math.min(bb.width, bb.height);228 p = paper.path([229 "M", x, y,230 "l", size, 0,231 "A", size * .4, size * .4, 0, 1, 0, x + size * .7, y - size * .7,232 "z"233 ]).attr({fill: "#000", stroke: "none"}).rotate(22.5 - angle, x, y);234 angle = (angle + 90) * Math.PI / 180;235 dx = (x + size * Math.sin(angle)) - (center ? 0 : bb.width / 2);236 dy = (y + size * Math.cos(angle)) - (center ? 0 : bb.height / 2);237 this.attrs ?238 this.attr(this.attrs.x ? 'x' : 'cx', dx).attr(this.attrs.y ? 'y' : 'cy', dy) :239 this.translate(dx - bb.x, dy - bb.y);240 return p.insertBefore(this.node ? this : this[0]);241};242/*\243 * Element.flag244 [ method ]245 **246 * Puts the context Element in a 'flag' tooltip. Can also be used on sets.247 **248 > Parameters249 **250 - angle (number) angle of orientation in degrees [default: `0`]251 - x (number) x coordinate of the flag's point [default: Element's `x` or `cx`]252 - y (number) y coordinate of the flag's point [default: Element's `x` or `cx`]253 **254 = (object) path element of the flag255 > Usage256 | paper.circle(50, 50, 10).attr({257 | stroke: "#fff",258 | fill: "0-#c9de96-#8ab66b:44-#398235"259 | }).flag(60);260 \*/261Raphael.el.flag = function (angle, x, y) {262 var d = 3,263 paper = this.paper || this[0].paper;264 if (!paper) return;265 var p = paper.path().attr({ fill: '#000', stroke: '#000' }),266 bb = this.getBBox(),267 h = bb.height / 2,268 center;269 switch (this.type) {270 case 'text':271 case 'circle':272 case 'ellipse': center = true; break;273 default: center = false;274 }275 angle = angle || 0;276 x = typeof x == 'number' ? x : (center ? bb.x + bb.width / 2 : bb.x);277 y = typeof y == 'number' ? y : (center ? bb.y + bb.height / 2: bb.y);278 p.attr({279 path: [280 "M", x, y,281 "l", h + d, -h - d, bb.width + 2 * d, 0, 0, bb.height + 2 * d, -bb.width - 2 * d, 0,282 "z"283 ].join(",")284 });285 angle = 360 - angle;286 p.rotate(angle, x, y);287 if (this.attrs) {288 //elements289 this.attr(this.attrs.x ? 'x' : 'cx', x + h + d + (!center ? this.type == 'text' ? bb.width : 0 : bb.width / 2)).attr('y', center ? y : y - bb.height / 2);290 this.rotate(angle, x, y);291 angle > 90 && angle < 270 && this.attr(this.attrs.x ? 'x' : 'cx', x - h - d - (!center ? bb.width : bb.width / 2)).rotate(180, x, y);292 } else {293 //sets294 if (angle > 90 && angle < 270) {295 this.translate(x - bb.x - bb.width - h - d, y - bb.y - bb.height / 2);296 this.rotate(angle - 180, bb.x + bb.width + h + d, bb.y + bb.height / 2);297 } else {298 this.translate(x - bb.x + h + d, y - bb.y - bb.height / 2);299 this.rotate(angle, bb.x - h - d, bb.y + bb.height / 2);300 }301 }302 return p.insertBefore(this.node ? this : this[0]);303};304/*\305 * Element.label306 [ method ]307 **308 * Puts the context Element in a 'label' tooltip. Can also be used on sets.309 **310 = (object) path element of the label.311 > Usage312 | paper.circle(50, 50, 10).attr({313 | stroke: "#fff",314 | fill: "0-#c9de96-#8ab66b:44-#398235"315 | }).label();316 \*/317Raphael.el.label = function () {318 var bb = this.getBBox(),319 paper = this.paper || this[0].paper,320 r = Math.min(20, bb.width + 10, bb.height + 10) / 2;321 if (!paper) return;322 return paper.rect(bb.x - r / 2, bb.y - r / 2, bb.width + r, bb.height + r, r).attr({ stroke: 'none', fill: '#000' }).insertBefore(this.node ? this : this[0]);323};324/*\325 * Element.blob326 [ method ]327 **328 * Puts the context Element in a 'blob' tooltip. Can also be used on sets.329 **330 > Parameters331 **332 - angle (number) angle of orientation in degrees [default: `0`]333 - x (number) x coordinate of the blob's tail [default: Element's `x` or `cx`]334 - y (number) y coordinate of the blob's tail [default: Element's `x` or `cx`]335 **336 = (object) path element of the blob337 > Usage338 | paper.circle(50, 50, 8).attr({339 | stroke: "#fff",340 | fill: "0-#c9de96-#8ab66b:44-#398235"341 | }).blob(60);342 \*/343Raphael.el.blob = function (angle, x, y) {344 var bb = this.getBBox(),345 rad = Math.PI / 180,346 paper = this.paper || this[0].paper,347 p, center, size;348 if (!paper) return;349 switch (this.type) {350 case 'text':351 case 'circle':352 case 'ellipse': center = true; break;353 default: center = false;354 }355 p = paper.path().attr({ fill: "#000", stroke: "none" });356 angle = (+angle + 1 ? angle : 45) + 90;357 size = Math.min(bb.height, bb.width);358 x = typeof x == 'number' ? x : (center ? bb.x + bb.width / 2 : bb.x);359 y = typeof y == 'number' ? y : (center ? bb.y + bb.height / 2 : bb.y);360 var w = Math.max(bb.width + size, size * 25 / 12),361 h = Math.max(bb.height + size, size * 25 / 12),362 x2 = x + size * Math.sin((angle - 22.5) * rad),363 y2 = y + size * Math.cos((angle - 22.5) * rad),364 x1 = x + size * Math.sin((angle + 22.5) * rad),365 y1 = y + size * Math.cos((angle + 22.5) * rad),366 dx = (x1 - x2) / 2,367 dy = (y1 - y2) / 2,368 rx = w / 2,369 ry = h / 2,370 k = -Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * dy * dy - ry * ry * dx * dx) / (rx * rx * dy * dy + ry * ry * dx * dx)),371 cx = k * rx * dy / ry + (x1 + x2) / 2,372 cy = k * -ry * dx / rx + (y1 + y2) / 2;373 p.attr({374 x: cx,375 y: cy,376 path: [377 "M", x, y,378 "L", x1, y1,379 "A", rx, ry, 0, 1, 1, x2, y2,380 "z"381 ].join(",")382 });383 this.translate(cx - bb.x - bb.width / 2, cy - bb.y - bb.height / 2);384 return p.insertBefore(this.node ? this : this[0]);385};386/*387 * Tooltips on Paper prototype388 */389/*\390 * Paper.label391 [ method ]392 **393 * Puts the given `text` into a 'label' tooltip. The text is given a default style according to @g.txtattr. See @Element.label394 **395 > Parameters396 **397 - x (number) x coordinate of the center of the label398 - y (number) y coordinate of the center of the label399 - text (string) text to place inside the label400 **401 = (object) set containing the label path and the text element402 > Usage403 | paper.label(50, 50, "$9.99");404 \*/405Raphael.fn.label = function (x, y, text) {406 var set = this.set();407 text = this.text(x, y, text).attr(Raphael.g.txtattr);408 return set.push(text.label(), text);409};410/*\411 * Paper.popup412 [ method ]413 **414 * Puts the given `text` into a 'popup' tooltip. The text is given a default style according to @g.txtattr. See @Element.popup415 *416 * Note: The `dir` parameter has changed from g.Raphael 0.4.1 to 0.5. The options `0`, `1`, `2`, and `3` has been changed to `'down'`, `'left'`, `'up'`, and `'right'` respectively.417 **418 > Parameters419 **420 - x (number) x coordinate of the popup's tail421 - y (number) y coordinate of the popup's tail422 - text (string) text to place inside the popup423 - dir (string) location of the text relative to the tail: `'down'`, `'left'`, `'up'` [default], or `'right'`.424 - size (number) amount of padding around the Element [default: `5`]425 **426 = (object) set containing the popup path and the text element427 > Usage428 | paper.popup(50, 50, "$9.99", 'down');429 \*/430Raphael.fn.popup = function (x, y, text, dir, size) {431 var set = this.set();432 text = this.text(x, y, text).attr(Raphael.g.txtattr);433 return set.push(text.popup(dir, size), text);434};435/*\436 * Paper.tag437 [ method ]438 **439 * Puts the given text into a 'tag' tooltip. The text is given a default style according to @g.txtattr. See @Element.tag440 **441 > Parameters442 **443 - x (number) x coordinate of the center of the tag loop444 - y (number) y coordinate of the center of the tag loop445 - text (string) text to place inside the tag446 - angle (number) angle of orientation in degrees [default: `0`]447 - r (number) radius of the loop [default: `5`]448 **449 = (object) set containing the tag path and the text element450 > Usage451 | paper.tag(50, 50, "$9.99", 60);452 \*/453Raphael.fn.tag = function (x, y, text, angle, r) {454 var set = this.set();455 text = this.text(x, y, text).attr(Raphael.g.txtattr);456 return set.push(text.tag(angle, r), text);457};458/*\459 * Paper.flag460 [ method ]461 **462 * Puts the given `text` into a 'flag' tooltip. The text is given a default style according to @g.txtattr. See @Element.flag463 **464 > Parameters465 **466 - x (number) x coordinate of the flag's point467 - y (number) y coordinate of the flag's point468 - text (string) text to place inside the flag469 - angle (number) angle of orientation in degrees [default: `0`]470 **471 = (object) set containing the flag path and the text element472 > Usage473 | paper.flag(50, 50, "$9.99", 60);474 \*/475Raphael.fn.flag = function (x, y, text, angle) {476 var set = this.set();477 text = this.text(x, y, text).attr(Raphael.g.txtattr);478 return set.push(text.flag(angle), text);479};480/*\481 * Paper.drop482 [ method ]483 **484 * Puts the given text into a 'drop' tooltip. The text is given a default style according to @g.txtattr. See @Element.drop485 **486 > Parameters487 **488 - x (number) x coordinate of the drop's point489 - y (number) y coordinate of the drop's point490 - text (string) text to place inside the drop491 - angle (number) angle of orientation in degrees [default: `0`]492 **493 = (object) set containing the drop path and the text element494 > Usage495 | paper.drop(50, 50, "$9.99", 60);496 \*/497Raphael.fn.drop = function (x, y, text, angle) {498 var set = this.set();499 text = this.text(x, y, text).attr(Raphael.g.txtattr);500 return set.push(text.drop(angle), text);501};502/*\503 * Paper.blob504 [ method ]505 **506 * Puts the given text into a 'blob' tooltip. The text is given a default style according to @g.txtattr. See @Element.blob507 **508 > Parameters509 **510 - x (number) x coordinate of the blob's tail511 - y (number) y coordinate of the blob's tail512 - text (string) text to place inside the blob513 - angle (number) angle of orientation in degrees [default: `0`]514 **515 = (object) set containing the blob path and the text element516 > Usage517 | paper.blob(50, 50, "$9.99", 60);518 \*/519Raphael.fn.blob = function (x, y, text, angle) {520 var set = this.set();521 text = this.text(x, y, text).attr(Raphael.g.txtattr);522 return set.push(text.blob(angle), text);523};524/**525 * zhanghuihua526 */527Raphael.fn.axis=function (x, y, length, from, to, steps, orientation, labels, type, dashsize) {528 return Raphael.g.axis(x, y, length, from, to, steps, orientation, labels, type, dashsize, this) ;529};530/**531 * Brightness functions on the Element prototype532 */533/*\534 * Element.lighter535 [ method ]536 **537 * Makes the context element lighter by increasing the brightness and reducing the saturation by a given factor. Can be called on Sets.538 **539 > Parameters540 **541 - times (number) adjustment factor [default: `2`]542 **543 = (object) Element544 > Usage545 | paper.circle(50, 50, 20).attr({546 | fill: "#ff0000",547 | stroke: "#fff",548 | "stroke-width": 2549 | }).lighter(6);550 \*/551Raphael.el.lighter = function (times) {552 times = times || 2;553 var fs = [this.attrs.fill, this.attrs.stroke];554 this.fs = this.fs || [fs[0], fs[1]];555 fs[0] = Raphael.rgb2hsb(Raphael.getRGB(fs[0]).hex);556 fs[1] = Raphael.rgb2hsb(Raphael.getRGB(fs[1]).hex);557 fs[0].b = Math.min(fs[0].b * times, 1);558 fs[0].s = fs[0].s / times;559 fs[1].b = Math.min(fs[1].b * times, 1);560 fs[1].s = fs[1].s / times;561 this.attr({fill: "hsb(" + [fs[0].h, fs[0].s, fs[0].b] + ")", stroke: "hsb(" + [fs[1].h, fs[1].s, fs[1].b] + ")"});562 return this;563};564/*\565 * Element.darker566 [ method ]567 **568 * Makes the context element darker by decreasing the brightness and increasing the saturation by a given factor. Can be called on Sets.569 **570 > Parameters571 **572 - times (number) adjustment factor [default: `2`]573 **574 = (object) Element575 > Usage576 | paper.circle(50, 50, 20).attr({577 | fill: "#ff0000",578 | stroke: "#fff",579 | "stroke-width": 2580 | }).darker(6);581 \*/582Raphael.el.darker = function (times) {583 times = times || 2;584 var fs = [this.attrs.fill, this.attrs.stroke];585 this.fs = this.fs || [fs[0], fs[1]];586 fs[0] = Raphael.rgb2hsb(Raphael.getRGB(fs[0]).hex);587 fs[1] = Raphael.rgb2hsb(Raphael.getRGB(fs[1]).hex);588 fs[0].s = Math.min(fs[0].s * times, 1);589 fs[0].b = fs[0].b / times;590 fs[1].s = Math.min(fs[1].s * times, 1);591 fs[1].b = fs[1].b / times;592 this.attr({fill: "hsb(" + [fs[0].h, fs[0].s, fs[0].b] + ")", stroke: "hsb(" + [fs[1].h, fs[1].s, fs[1].b] + ")"});593 return this;594};595/*\596 * Element.resetBrightness597 [ method ]598 **599 * Resets brightness and saturation levels to their original values. See @Element.lighter and @Element.darker. Can be called on Sets.600 **601 = (object) Element602 > Usage603 | paper.circle(50, 50, 20).attr({604 | fill: "#ff0000",605 | stroke: "#fff",606 | "stroke-width": 2607 | }).lighter(6).resetBrightness();608 \*/609Raphael.el.resetBrightness = function () {610 if (this.fs) {611 this.attr({ fill: this.fs[0], stroke: this.fs[1] });612 delete this.fs;613 }614 return this;615};616//alias to set prototype617(function () {618 var brightness = ['lighter', 'darker', 'resetBrightness'],619 tooltips = ['popup', 'tag', 'flag', 'label', 'drop', 'blob'];620 for (var f in tooltips) (function (name) {621 Raphael.st[name] = function () {622 return Raphael.el[name].apply(this, arguments);623 };624 })(tooltips[f]);625 for (var f in brightness) (function (name) {626 Raphael.st[name] = function () {627 for (var i = 0; i < this.length; i++) {628 this[i][name].apply(this[i], arguments);629 }630 return this;631 };632 })(brightness[f]);633})();634//chart prototype for storing common functions635Raphael.g = {636 /*\637 * g.shim638 [ object ]639 **640 * An attribute object that charts will set on all generated shims (shims being the invisible objects that mouse events are bound to)641 **642 > Default value643 | { stroke: 'none', fill: '#000', 'fill-opacity': 0 }644 \*/645 shim: { stroke: 'none', fill: '#000', 'fill-opacity': 0 },646 /*\647 * g.txtattr648 [ object ]649 **650 * An attribute object that charts and tooltips will set on any generated text651 **652 > Default value653 | { font: '12px Arial, sans-serif', fill: '#fff' }654 \*/ 655 txtattr: {656 'font-size': '12px',657 'fill': '#fff',658 'font-family': 'Microsoft YaHei,arial,sans-serif'659 },660 /*\661 * g.colors662 [ array ]663 **664 * An array of color values that charts will iterate through when drawing chart data values.665 **666 \*/667 colors: (function () {668 var hues = [.6, .2, .05, .1333, .75, 0],669 colors = [];670 for (var i = 0; i < 10; i++) {671 if (i < hues.length) {672 colors.push('hsb(' + hues[i] + ',.75, .75)');673 } else {674 colors.push('hsb(' + hues[i - hues.length] + ', 1, .5)');675 }676 }677 return colors;678 })(),679 680 snapEnds: function(from, to, steps) {681 var f = from,682 t = to;683 if (f == t) {684 return {from: f, to: t, power: 0};685 }686 function round(a) {687 return Math.abs(a - .5) < .25 ? ~~(a) + .5 : Math.ceil(a);688 }689 var d = (t - f) / steps,690 r = ~~(d),691 R = r,692 i = 0;693 if (r) {694 while (R) {695 i--;696 R = ~~(d * Math.pow(10, i)) / Math.pow(10, i);697 }698 i ++;699 } else {700 while (!r) {701 i = i || 1;702 r = ~~(d * Math.pow(10, i)) / Math.pow(10, i);703 i++;704 }705 i && i--;706 }707 t = round(to * Math.pow(10, i)) / Math.pow(10, i);708 if (t < to) {709 t = round((to + .5) * Math.pow(10, i)) / Math.pow(10, i);710 }711 f = round((from - (i > 0 ? 0 : .5)) * Math.pow(10, i)) / Math.pow(10, i);712 return { from: f, to: t, power: i };713 },714 axis: function (x, y, length, from, to, steps, orientation, labels, type, dashsize, paper) {715 dashsize = dashsize == null ? 2 : dashsize;716 type = type || "t";717 steps = steps || 10;718 paper = arguments[arguments.length-1] //paper is always last argument719 var path = type == "|" || type == " " ? ["M", x + .5, y, "l", 0, .001] : orientation == 1 || orientation == 3 ? ["M", x + .5, y, "l", 0, -length] : ["M", x, y + .5, "l", length, 0],720 ends = this.snapEnds(from, to, steps),721 f = ends.from,722 t = ends.to,723 i = ends.power,724 j = 0,725 txtattr = { font: "11px 'Fontin Sans', Fontin-Sans, sans-serif" },726 text = paper.set(),727 d;728 d = (t - f) / steps;729 var label = f,730 rnd = i > 0 ? i : 0;731 dx = length / steps;732 if (+orientation == 1 || +orientation == 3) {733 var Y = y,734 addon = (orientation - 1 ? 1 : -1) * (dashsize + 3 + !!(orientation - 1));735 while (Y >= y - length) {736 type != "-" && type != " " && (path = path.concat(["M", x - (type == "+" || type == "|" ? dashsize : !(orientation - 1) * dashsize * 2), Y + .5, "l", dashsize * 2 + 1, 0]));737 text.push(paper.text(x + addon, Y, (labels && labels[j++]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(txtattr).attr({ "text-anchor": orientation - 1 ? "start" : "end" }));738 label += d;739 Y -= dx;740 }741 if (Math.round(Y + dx - (y - length))) {742 type != "-" && type != " " && (path = path.concat(["M", x - (type == "+" || type == "|" ? dashsize : !(orientation - 1) * dashsize * 2), y - length + .5, "l", dashsize * 2 + 1, 0]));743 text.push(paper.text(x + addon, y - length, (labels && labels[j]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(txtattr).attr({ "text-anchor": orientation - 1 ? "start" : "end" }));744 }745 } else {746 label = f;747 rnd = (i > 0) * i;748 addon = (orientation ? -1 : 1) * (dashsize + 9 + !orientation);749 var X = x,750 dx = length / steps,751 txt = 0,752 prev = 0;753 while (X <= x + length) {754 type != "-" && type != " " && (path = path.concat(["M", X + .5, y - (type == "+" ? dashsize : !!orientation * dashsize * 2), "l", 0, dashsize * 2 + 1]));755 text.push(txt = paper.text(X, y + addon, (labels && labels[j++]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(txtattr));756 var bb = txt.getBBox();757 if (prev >= bb.x - 5) {758 text.pop(text.length - 1).remove();759 } else {760 prev = bb.x + bb.width;761 }762 label += d;763 X += dx;764 }765 if (Math.round(X - dx - x - length)) {766 type != "-" && type != " " && (path = path.concat(["M", x + length + .5, y - (type == "+" ? dashsize : !!orientation * dashsize * 2), "l", 0, dashsize * 2 + 1]));767 text.push(paper.text(x + length, y + addon, (labels && labels[j]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(txtattr));768 }769 }770 var res = paper.path(path);771 res.text = text;772 res.all = paper.set([res, text]);773 res.remove = function () {774 this.text.remove();775 this.constructor.prototype.remove.call(this);776 };777 return res;778 },779 780 labelise: function(label, val, total) {781 if (label) {782 return (label + "").replace(/(##+(?:\.#+)?)|(%%+(?:\.%+)?)/g, function (all, value, percent) {783 if (value) {784 return (+val).toFixed(value.replace(/^#+\.?/g, "").length);785 }786 if (percent) {787 return (val * 100 / total).toFixed(percent.replace(/^%+\.?/g, "").length) + "%";788 }789 });790 } else {791 return (+val).toFixed(0);792 }793 }...
layout.js
Source:layout.js
1/*2 Copyright (c) 2012-2017 Open Lab3 Permission is hereby granted, free of charge, to any person obtaining4 a copy of this software and associated documentation files (the5 "Software"), to deal in the Software without restriction, including6 without limitation the rights to use, copy, modify, merge, publish,7 distribute, sublicense, and/or sell copies of the Software, and to8 permit persons to whom the Software is furnished to do so, subject to9 the following conditions:10 The above copyright notice and this permission notice shall be11 included in all copies or substantial portions of the Software.12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,13 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF14 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND15 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE16 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION17 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION18 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.19 */20//----------------------------------positioning-----------------------------------------------21jQuery.fn.centerOnScreen = function () {22 return this.each(function () {23 var container = $(this);24 //console.debug($(window).height(), container.outerHeight(),(($(window).height() - container.outerHeight()) / 2))25 container.css("position", "fixed");26 container.css("top", (($(window).height() - container.outerHeight()) / 2) + 'px');27 container.css("left", (($(window).width() - container.outerWidth()) / 2) + 'px');28 });29};30function nearBestPosition(whereId, theObjId, centerOnEl) {31 var el = whereId;32 var target = theObjId;33 if (typeof whereId != "object") {34 el = $("#" + whereId);35 }36 if (typeof theObjId != "object") {37 target = $("#" + theObjId);38 }39 if (el) {40 target.css("visibility", "hidden");41 var hasContainment = false;42 target.parents().each(function () {43 if ($(this).css("position") == "static")44 return;45 hasContainment = true;46 });47 var trueX = hasContainment ? el.position().left : el.offset().left;48 var trueY = hasContainment ? el.position().top : el.offset().top;49 var h = el.outerHeight();50 var elHeight = parseFloat(h);51 if (centerOnEl) {52 var elWidth = parseFloat(el.outerWidth());53 var targetWidth = parseFloat(target.outerWidth());54 trueX += (elWidth - targetWidth) / 2;55 }56 trueY += parseFloat(elHeight);57 var left = trueX;58 var top = trueY;59 var barHeight = 45 ;60 var barWidth = 20 ;61 if (trueX && trueY) {62 target.css("left", left);63 target.css("top", top);64 }65 if (target.offset().left >= ( ($(window).width() + $(window).scrollLeft()) - target.outerWidth())) {66 left = ( ($(window).width() + $(window).scrollLeft()) - target.outerWidth() - 10 );67 target.css({left:left, marginTop: 0});68 }69 if (target.offset().left < 0) {70 left = 10;71 target.css("left", left);72 }73 if ((target.offset().top + target.outerHeight() >= ( ($(window).height() + $(window).scrollTop()) - barHeight)) && (target.outerHeight() < $(window).height())) {74 var marginTop = -(target.outerHeight() + el.outerHeight());75 target.css("margin-top", marginTop);76 }77 if (target.offset().top < 0) {78 top = 0;79 target.css("top", top);80 }81 target.css("visibility", "visible");82 }83}84$.fn.keepItVisible = function (ref) {85 var thisTop = $(this).offset().top;86 var thisLeft = $(this).offset().left;87 var fromTop =0;88 var fromLeft =0;89 var windowH = $(window).height() + $(window).scrollTop();90 var windowW = $(window).width() + $(window).scrollLeft();91 if (ref){92 fromTop = windowH - (ref.offset().top);93 fromLeft = windowW - (ref.offset().left + ref.outerWidth());94 }95 if (thisTop + $(this).outerHeight() > windowH){96 var mt = (thisTop + $(this).outerHeight()) - windowH;97// $(this).css("margin-top", -$(this).outerHeight() - fromTop);98 $(this).css("margin-top", -mt - fromTop);99 }100 if (thisLeft + $(this).outerWidth() > windowW){101 var mL = (thisLeft + $(this).outerWidth()) - windowW;102// $(this).css("margin-left", -$(this).outerWidth() - fromLeft);103 $(this).css("margin-left", -mL - fromLeft);104 }105 $(this).css("visibility", "visible");106};107//END positioning108/* Caret Functions109 Use setSelection with start = end to set caret110 */111function setSelection(input, start, end) {112 input.setSelectionRange(start, end);113}114$.fn.setCursorPosition = function(pos) {115 this.each(function(index, elem) {116 if (elem.setSelectionRange) {117 elem.setSelectionRange(pos, pos);118 } else if (elem.createTextRange) {119 var range = elem.createTextRange();120 range.collapse(true);121 range.moveEnd('character', pos);122 range.moveStart('character', pos);123 range.select();124 }125 });126 return this;127};128//-- Caret Functions END ---------------------------------------------------------------------------- --129/*----------------------------------------------------------------- manage bbButtons*/130$.buttonBar = {131 defaults: {},132 init: function(){133 setTimeout(function(){134 $.buttonBar.manageButtonBar();135 },100);136 $(window).on("scroll.ButtonBar",function(){137 $.buttonBar.manageButtonBar();138 });139 $(window).on("resize.ButtonBar",function(){140 $.buttonBar.manageButtonBar();141 });142 },143 manageButtonBar: function(anim) {144 $(".buttonArea").not(".bbCloned").not(".notFix").each(function(){145 var bb = this;146 //se usiamo questi si rompe la button bar flottante del save sulla issue list147 //bb.originalHeigh=bb.originalHeigh || $(bb).height();148 //bb.originalOffsetTop=bb.originalOffsetTop||$(bb).offset().top;149 bb.originalHeigh= $(bb).height();150 bb.originalOffsetTop=$(bb).offset().top;151 bb.isOut = $(window).scrollTop() + $(window).height() - bb.originalHeigh < bb.originalOffsetTop;152 if (bb.bbHolder)153 bb.bbHolder.css({width: $(bb).outerWidth(),left:$(bb).offset().left});154 if (bb.isOut && !bb.isCloned){155 if (bb.bbHolder)156 bb.bbHolder.remove();157 bb.isCloned = true;158 bb.bbHolder = $(bb).clone().addClass("bbCloned clone bottom").css({width: $(bb).outerWidth(), marginTop:0,left:$(bb).offset().left});159 bb.bbHolder.hide();160 bb.bbHolder.css({position:"fixed", bottom:0, left:$(bb).offset().left});161 $(bb).after(bb.bbHolder);162 bb.bbHolder.show();163 $(bb).css("visibility","hidden");164 } else if (!bb.isOut && bb.isCloned) {165 //} else {166 bb.isCloned = false;167 bb.bbHolder.remove();168 $(bb).css("visibility","visible");169 }170 });171 },172 refreshButtonBar: function() {173 $(".bbCloned").remove();174 $(".buttonArea").not(".bbCloned").each(function(){175 var bb = this;176 bb.isCloned = false;177 });178 $.buttonBar.manageButtonBar(false);179 }...
common.js
Source:common.js
1var showNotice, adminMenu, columns;2(function($){3// sidebar admin menu4adminMenu = {5 init : function() {6 $('ul#bbAdminMenu li.bb-menu div.bb-menu-toggle').each( function() {7 if ( $(this).siblings('div.bb-menu-sub-wrap').length )8 $(this).click(function(){ adminMenu.toggle( $(this).siblings('div.bb-menu-sub-wrap') ); });9 else10 $(this).hide();11 });12 $('#bbAdminMenu li.bb-menu.bb-menu-separator a').click(function(){13 if ( $('body').hasClass('bb-menu-folded') ) {14 adminMenu.fold(1);15 deleteUserSetting( 'fm' );16 } else {17 adminMenu.fold();18 setUserSetting( 'fm', 'f' );19 }20 return false;21 });22 if ( $('body').hasClass('bb-menu-folded') ) {23 this.fold();24 }25 this.restoreMenuState();26 },27 restoreMenuState : function() {28 $('ul#bbAdminMenu li.bb-menu.bb-menu-has-submenu').each(function(i, e) {29 var v = getUserSetting( 'm'+i );30 if ( $(e).hasClass('bb-menu-current') ) return true; // leave the current parent open31 if ( 'o' == v ) $(e).addClass('bb-menu-open');32 else if ( 'c' == v ) $(e).removeClass('bb-menu-open');33 });34 },35 toggle : function(el) {36 el['slideToggle'](150, function(){el.css('display','');}).parent().toggleClass( 'bb-menu-open' );37 $('ul#bbAdminMenu li.bb-menu.bb-menu-has-submenu').each(function(i, e) {38 var v = $(e).hasClass('bb-menu-open') ? 'o' : 'c';39 setUserSetting( 'm'+i, v );40 });41 return false;42 },43 fold : function(off) {44 if (off) {45 $('body').removeClass('bb-menu-folded');46 $('#bbAdminMenu li.bb-menu.bb-menu-has-submenu').unbind();47 } else {48 $('body').addClass('bb-menu-folded');49 $('#bbAdminMenu li.bb-menu.bb-menu-has-submenu').hoverIntent({50 over: function(e){51 var m, b, h, o, f;52 m = $(this).find('div.bb-menu-sub-wrap');53 b = m.parent().offset().top + m.height() + 1; // Bottom offset of the menu54 h = $('#bbWrap').height(); // Height of the entire page55 o = 60 + b - h;56 f = $(window).height() + $('body').scrollTop() - 15; // The fold57 if (f < (b - o)) {58 o = b - f;59 }60 if (o > 1) {61 m.css({'marginTop':'-'+o+'px'});62 } else if ( m.css('marginTop') ) {63 m.css({'marginTop':''});64 }65 m.addClass('bb-menu-sub-open');66 },67 out: function(){ $(this).find('div.bb-menu-sub-wrap').removeClass('bb-menu-sub-open').css({'marginTop':''}); },68 timeout: 220,69 sensitivity: 8,70 interval: 10071 });72 }73 }74};75$(document).ready(function(){76 adminMenu.init();77 $('thead .check-column :checkbox, tfoot .check-column :checkbox').click( function() {78 $(this).parents( 'table' ).find( '.check-column :checkbox' ).attr( 'checked', $(this).is( ':checked' ) ? 'checked' : false );79 } );80});...
Using AI Code Generation
1import { bb } from 'storybook-root';2import { bb } from 'storybook-root';3import { bb } from 'storybook-root';4import { bb } from 'storybook-root';5import { bb } from 'storybook-root';6import { bb } from 'storybook-root';7import { bb } from 'storybook-root';8import { bb } from 'storybook-root';9import { bb } from 'storybook-root';10import { bb } from 'storybook-root';11import { bb } from 'storybook-root';12import { bb } from 'storybook-root';13import { bb } from 'storybook-root';14import { bb } from 'storybook-root';
Using AI Code Generation
1import { bb } from 'storybook-root';2import { bb } from 'storybook-root/bb';3import { bb } from 'storybook-root';4import { bb } from 'storybook-root/bb';5import { bb } from 'storybook-root';6import { bb } from 'storybook-root/bb';7import { bb } from 'storybook-root';8import { bb } from 'storybook-root/bb';9import { bb } from 'storybook-root';10import { bb } from 'storybook-root/bb';11import { bb } from 'storybook-root';12import { bb } from 'storybook-root/bb';13import { bb } from 'storybook-root';14import { bb } from 'storybook-root/bb';15import { bb } from 'storybook-root';16import { bb } from 'storybook-root/bb';17import { bb } from 'storybook-root';18import { bb } from 'storybook-root/bb';19import { bb } from 'storybook-root';20import { bb } from 'storybook-root/bb';21import { bb } from 'storybook-root';22import { bb } from 'storybook-root/bb';23import { bb } from 'storybook-root';24import { bb } from 'storybook-root/bb';25import { bb } from 'storybook-root';26import { bb } from 'storybook-root/bb';27import { bb } from '
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!