Best JavaScript code snippet using stryker-parent
d3-parsets.js
Source:d3-parsets.js
1// Parallel Sets by Jason Davies, http://www.jasondavies.com/2// Functionality based on http://eagereyes.org/parallel-sets3(function() {4 d3.parsets = function() {5 var event = d3.dispatch("sortDimensions", "sortCategories"),6 dimensions_ = autoDimensions,7 dimensionFormat = String,8 tooltip_ = defaultTooltip,9 categoryTooltip = defaultCategoryTooltip,10 value_,11 spacing = 20,12 width,13 height,14 tension = 1,15 tension0,16 duration = 500;17 function parsets(selection) {18 selection.each(function(data, i) {19 var g = d3.select(this),20 ordinal = d3.scale.ordinal(),21 dragging = false,22 dimensionNames = dimensions_.call(this, data, i),23 dimensions = [],24 tree = {children: {}, count: 0},25 nodes,26 total,27 ribbon;28 d3.select(window).on("mousemove.parsets." + ++parsetsId, unhighlight);29 if (tension0 == null) tension0 = tension;30 g.selectAll(".ribbon, .ribbon-mouse")31 .data(["ribbon", "ribbon-mouse"], String)32 .enter().append("g")33 .attr("class", String);34 updateDimensions();35 if (tension != tension0) {36 var t = d3.transition(g);37 if (t.tween) t.tween("ribbon", tensionTween);38 else tensionTween()(1);39 }40 function tensionTween() {41 var i = d3.interpolateNumber(tension0, tension);42 return function(t) {43 tension0 = i(t);44 ribbon.attr("d", ribbonPath);45 };46 }47 function updateDimensions() {48 // Cache existing bound dimensions to preserve sort order.49 var dimension = g.selectAll("g.dimension"),50 cache = {};51 dimension.each(function(d) { cache[d.name] = d; });52 dimensionNames.forEach(function(d) {53 if (!cache.hasOwnProperty(d)) {54 cache[d] = {name: d, categories: []};55 }56 dimensions.push(cache[d]);57 });58 dimensions.sort(compareY);59 // Populate tree with existing nodes.60 g.select(".ribbon").selectAll("path")61 .each(function(d) {62 var path = d.path.split("\0"),63 node = tree,64 n = path.length - 1;65 for (var i = 0; i < n; i++) {66 var p = path[i];67 node = node.children.hasOwnProperty(p) ? node.children[p]68 : node.children[p] = {children: {}, count: 0};69 }70 node.children[d.name] = d;71 });72 tree = buildTree(tree, data, dimensions.map(dimensionName), value_);73 cache = dimensions.map(function(d) {74 var t = {};75 d.categories.forEach(function(c) {76 t[c.name] = c;77 });78 return t;79 });80 (function categories(d, i) {81 if (!d.children) return;82 var dim = dimensions[i],83 t = cache[i];84 for (var k in d.children) {85 if (!t.hasOwnProperty(k)) {86 dim.categories.push(t[k] = {name: k});87 }88 categories(d.children[k], i + 1);89 }90 })(tree, 0);91 ordinal.domain([]).range(d3.range(dimensions[0].categories.length));92 nodes = layout(tree, dimensions, ordinal);93 total = getTotal(dimensions);94 dimensions.forEach(function(d) {95 d.count = total;96 });97 dimension = dimension.data(dimensions, dimensionName);98 var dEnter = dimension.enter().append("g")99 .attr("class", "dimension")100 .attr("transform", function(d) { return "translate(0," + d.y + ")"; })101 .on("mousedown.parsets", cancelEvent);102 dimension.each(function(d) {103 d.y0 = d.y;104 d.categories.forEach(function(d) { d.x0 = d.x; });105 });106 dEnter.append("rect")107 .attr("width", width)108 .attr("y", -45)109 .attr("height", 45);110 var textEnter = dEnter.append("text")111 .attr("class", "dimension")112 .attr("transform", "translate(0,-25)");113 textEnter.append("tspan")114 .attr("class", "name")115 .text(dimensionFormatName);116 textEnter.append("tspan")117 .attr("class", "sort alpha")118 .attr("dx", "2em")119 .text("alpha »")120 .on("mousedown.parsets", cancelEvent);121 textEnter.append("tspan")122 .attr("class", "sort size")123 .attr("dx", "2em")124 .text("size »")125 .on("mousedown.parsets", cancelEvent);126 dimension127 .call(d3.behavior.drag()128 .origin(identity)129 .on("dragstart", function(d) {130 dragging = true;131 d.y0 = d.y;132 })133 .on("drag", function(d) {134 d.y0 = d.y = d3.event.y;135 for (var i = 1; i < dimensions.length; i++) {136 if (height * dimensions[i].y < height * dimensions[i - 1].y) {137 dimensions.sort(compareY);138 dimensionNames = dimensions.map(dimensionName);139 ordinal.domain([]).range(d3.range(dimensions[0].categories.length));140 nodes = layout(tree = buildTree({children: {}, count: 0}, data, dimensionNames, value_), dimensions, ordinal);141 total = getTotal(dimensions);142 g.selectAll(".ribbon, .ribbon-mouse").selectAll("path").remove();143 updateRibbons();144 updateCategories(dimension);145 dimension.transition().duration(duration)146 .attr("transform", translateY)147 .tween("ribbon", ribbonTweenY);148 event.sortDimensions();149 break;150 }151 }152 d3.select(this)153 .attr("transform", "translate(0," + d.y + ")")154 .transition();155 ribbon.filter(function(r) { return r.source.dimension === d || r.target.dimension === d; })156 .attr("d", ribbonPath);157 })158 .on("dragend", function(d) {159 dragging = false;160 unhighlight();161 var y0 = 45,162 dy = (height - y0 - 2) / (dimensions.length - 1);163 dimensions.forEach(function(d, i) {164 d.y = y0 + i * dy;165 });166 transition(d3.select(this))167 .attr("transform", "translate(0," + d.y + ")")168 .tween("ribbon", ribbonTweenY);169 }));170 dimension.select("text").select("tspan.sort.alpha")171 .on("click.parsets", sortBy("alpha", function(a, b) { return a.name < b.name ? 1 : -1; }, dimension));172 dimension.select("text").select("tspan.sort.size")173 .on("click.parsets", sortBy("size", function(a, b) { return a.count - b.count; }, dimension));174 dimension.transition().duration(duration)175 .attr("transform", function(d) { return "translate(0," + d.y + ")"; })176 .tween("ribbon", ribbonTweenY);177 dimension.exit().remove();178 updateCategories(dimension);179 updateRibbons();180 // start default by size181 dimensions.forEach(function(d){182 d.categories.sort(function(a,b) { return d3.descending(a.count,b.count) });183 })184 nodes = layout(tree, dimensions, ordinal);185 updateCategories(dimension);186 updateRibbons();187 // end default by size188 }189 function sortBy(type, f, dimension) {190 return function(d) {191 var direction = this.__direction = -(this.__direction || 1);192 d3.select(this).text(direction > 0 ? type + " »" : "« " + type);193 d.categories.sort(function() { return direction * f.apply(this, arguments); });194 nodes = layout(tree, dimensions, ordinal);195 updateCategories(dimension);196 updateRibbons();197 event.sortCategories();198 };199 }200 function updateRibbons() {201 ribbon = g.select(".ribbon").selectAll("path")202 .data(nodes, function(d) { return d.path; });203 ribbon.enter().append("path")204 .each(function(d) {205 d.source.x0 = d.source.x;206 d.target.x0 = d.target.x;207 })208 .attr("class", function(d) { return "category-" + d.major; })209 .attr("d", ribbonPath);210 ribbon.sort(function(a, b) { return b.count - a.count; });211 ribbon.exit().remove();212 var mouse = g.select(".ribbon-mouse").selectAll("path")213 .data(nodes, function(d) { return d.path; });214 mouse.enter().append("path")215 .on("mousemove.parsets", function(d) {216 ribbon.classed("active", false);217 if (dragging) return;218 highlight(d = d.node, true);219 showTooltip(tooltip_.call(this, d));220 d3.event.stopPropagation();221 });222 mouse223 .sort(function(a, b) { return b.count - a.count; })224 .attr("d", ribbonPathStatic);225 mouse.exit().remove();226 }227 // Animates the x-coordinates only of the relevant ribbon paths.228 function ribbonTweenX(d) {229 var nodes = [d],230 r = ribbon.filter(function(r) {231 var s, t;232 if (r.source.node === d) nodes.push(s = r.source);233 if (r.target.node === d) nodes.push(t = r.target);234 return s || t;235 }),236 i = nodes.map(function(d) { return d3.interpolateNumber(d.x0, d.x); }),237 n = nodes.length;238 return function(t) {239 for (var j = 0; j < n; j++) nodes[j].x0 = i[j](t);240 r.attr("d", ribbonPath);241 };242 }243 // Animates the y-coordinates only of the relevant ribbon paths.244 function ribbonTweenY(d) {245 var r = ribbon.filter(function(r) { return r.source.dimension.name == d.name || r.target.dimension.name == d.name; }),246 i = d3.interpolateNumber(d.y0, d.y);247 return function(t) {248 d.y0 = i(t);249 r.attr("d", ribbonPath);250 };251 }252 // Highlight a node and its descendants, and optionally its ancestors.253 function highlight(d, ancestors) {254 if (dragging) return;255 var highlight = [];256 (function recurse(d) {257 highlight.push(d);258 for (var k in d.children) recurse(d.children[k]);259 })(d);260 highlight.shift();261 if (ancestors) while (d) highlight.push(d), d = d.parent;262 ribbon.filter(function(d) {263 var active = highlight.indexOf(d.node) >= 0;264 if (active) this.parentNode.appendChild(this);265 return active;266 }).classed("active", true);267 }268 // Unhighlight all nodes.269 function unhighlight() {270 if (dragging) return;271 ribbon.classed("active", false);272 hideTooltip();273 }274 function updateCategories(g) {275 var category = g.selectAll("g.category")276 .data(function(d) { return d.categories; }, function(d) { return d.name; });277 var categoryEnter = category.enter().append("g")278 .attr("class", "category")279 .attr("transform", function(d) { return "translate(" + d.x + ")"; });280 category.exit().remove();281 category282 .on("mousemove.parsets", function(d) {283 ribbon.classed("active", false);284 if (dragging) return;285 d.nodes.forEach(function(d) { highlight(d); });286 showTooltip(categoryTooltip.call(this, d));287 d3.event.stopPropagation();288 })289 .on("mouseout.parsets", unhighlight)290 .on("mousedown.parsets", cancelEvent)291 .call(d3.behavior.drag()292 .origin(identity)293 .on("dragstart", function(d) {294 dragging = true;295 d.x0 = d.x;296 })297 .on("drag", function(d) {298 d.x = d3.event.x;299 var categories = d.dimension.categories;300 for (var i = 0, c = categories[0]; ++i < categories.length;) {301 if (c.x + c.dx / 2 > (c = categories[i]).x + c.dx / 2) {302 categories.sort(function(a, b) { return a.x + a.dx / 2 - b.x - b.dx / 2; });303 nodes = layout(tree, dimensions, ordinal);304 updateRibbons();305 updateCategories(g);306 highlight(d.node);307 event.sortCategories();308 break;309 }310 }311 var x = 0,312 p = spacing / (categories.length - 1);313 categories.forEach(function(e) {314 if (d === e) e.x0 = d3.event.x;315 e.x = x;316 x += e.count / total * (width - spacing) + p;317 });318 d3.select(this)319 .attr("transform", function(d) { return "translate(" + d.x0 + ")"; })320 .transition();321 ribbon.filter(function(r) { return r.source.node === d || r.target.node === d; })322 .attr("d", ribbonPath);323 })324 .on("dragend", function(d) {325 dragging = false;326 unhighlight();327 updateRibbons();328 transition(d3.select(this))329 .attr("transform", "translate(" + d.x + ")")330 .tween("ribbon", ribbonTweenX);331 }));332 category.transition().duration(duration)333 .attr("transform", function(d) { return "translate(" + d.x + ")"; })334 .tween("ribbon", ribbonTweenX);335 categoryEnter.append("rect")336 .attr("width", function(d) { return d.dx; })337 .attr("y", -20)338 .attr("height", 20);339 categoryEnter.append("line")340 .style("stroke-width", 2);341 categoryEnter.append("text")342 .attr("dy", "-.3em");343 category.select("rect")344 .attr("width", function(d) { return d.dx; })345 .attr("class", function(d) {346 return "category-" + (d.dimension === dimensions[0] ? ordinal(d.name) : "background");347 });348 category.select("line")349 .attr("x2", function(d) { return d.dx; });350 category.select("text")351 .text(truncateText(function(d) {return d.name;}, function(d) { return d.dx; }));352 //.text(function(d){return d.name + ' ' + d.count});353 }354 });355 }356 parsets.dimensionFormat = function(_) {357 if (!arguments.length) return dimensionFormat;358 dimensionFormat = _;359 return parsets;360 };361 parsets.dimensions = function(_) {362 if (!arguments.length) return dimensions_;363 dimensions_ = d3.functor(_);364 return parsets;365 };366 parsets.value = function(_) {367 if (!arguments.length) return value_;368 value_ = d3.functor(_);369 return parsets;370 };371 parsets.width = function(_) {372 if (!arguments.length) return width;373 width = +_;374 return parsets;375 };376 parsets.height = function(_) {377 if (!arguments.length) return height;378 height = +_;379 return parsets;380 };381 parsets.spacing = function(_) {382 if (!arguments.length) return spacing;383 spacing = +_;384 return parsets;385 };386 parsets.tension = function(_) {387 if (!arguments.length) return tension;388 tension = +_;389 return parsets;390 };391 parsets.duration = function(_) {392 if (!arguments.length) return duration;393 duration = +_;394 return parsets;395 };396 parsets.tooltip = function(_) {397 if (!arguments.length) return tooltip;398 tooltip_ = _ == null ? defaultTooltip : _;399 return parsets;400 };401 parsets.categoryTooltip = function(_) {402 if (!arguments.length) return categoryTooltip;403 categoryTooltip = _ == null ? defaultCategoryTooltip : _;404 return parsets;405 };406 var body = d3.select("body");407 var tooltip = body.append("div")408 .style("display", "none")409 .attr("class", "parsets tooltipParset");410 return d3.rebind(parsets, event, "on").value(1).width(960).height(600);411 function dimensionFormatName(d, i) {412 return dimensionFormat.call(this, d.name, i);413 }414 function showTooltip(html) {415 var m = d3.mouse(body.node());416 tooltip417 .style("display", null)418 .style("left", m[0] - 100 + "px")419 .style("top", m[1] + 15 + "px")420 .html(html);421 }422 function hideTooltip() {423 tooltip.style("display", "none");424 }425 function transition(g) {426 return duration ? g.transition().duration(duration).ease(parsetsEase) : g;427 }428 function layout(tree, dimensions, ordinal) {429 var nodes = [],430 nd = dimensions.length,431 y0 = 45,432 dy = (height - y0 - 2) / (nd - 1);433 dimensions.forEach(function(d, i) {434 d.categories.forEach(function(c) {435 c.dimension = d;436 c.count = 0;437 c.nodes = [];438 });439 d.y = y0 + i * dy;440 });441 // Compute per-category counts.442 var total = (function rollup(d, i) {443 if (!d.children) return d.count;444 var dim = dimensions[i],445 total = 0;446 dim.categories.forEach(function(c) {447 var child = d.children[c.name];448 if (!child) return;449 c.nodes.push(child);450 var count = rollup(child, i + 1);451 c.count += count;452 total += count;453 });454 return total;455 })(tree, 0);456 // Stack the counts.457 dimensions.forEach(function(d) {458 d.categories = d.categories.filter(function(d) { return d.count; });459 var x = 0,460 p = spacing / (d.categories.length - 1);461 d.categories.forEach(function(c) {462 c.x = x;463 c.dx = c.count / total * (width - spacing);464 c.in = {dx: 0};465 c.out = {dx: 0};466 x += c.dx + p;467 });468 });469 var dim = dimensions[0];470 dim.categories.forEach(function(c) {471 var k = c.name;472 if (tree.children.hasOwnProperty(k)) {473 recurse(c, {node: tree.children[k], path: k}, 1, ordinal(k));474 }475 });476 function recurse(p, d, depth, major) {477 var node = d.node,478 dimension = dimensions[depth];479 dimension.categories.forEach(function(c) {480 var k = c.name;481 if (!node.children.hasOwnProperty(k)) return;482 var child = node.children[k];483 child.path = d.path + "\0" + k;484 var target = child.target || {node: c, dimension: dimension};485 target.x = c.in.dx;486 target.dx = child.count / total * (width - spacing);487 c.in.dx += target.dx;488 var source = child.source || {node: p, dimension: dimensions[depth - 1]};489 source.x = p.out.dx;490 source.dx = target.dx;491 p.out.dx += source.dx;492 child.node = child;493 child.source = source;494 child.target = target;495 child.major = major;496 nodes.push(child);497 if (depth + 1 < dimensions.length) recurse(c, child, depth + 1, major);498 });499 }500 return nodes;501 }502 // Dynamic path string for transitions.503 function ribbonPath(d) {504 var s = d.source,505 t = d.target;506 return ribbonPathString(s.node.x0 + s.x0, s.dimension.y0, s.dx, t.node.x0 + t.x0, t.dimension.y0, t.dx, tension0);507 }508 // Static path string for mouse handlers.509 function ribbonPathStatic(d) {510 var s = d.source,511 t = d.target;512 return ribbonPathString(s.node.x + s.x, s.dimension.y, s.dx, t.node.x + t.x, t.dimension.y, t.dx, tension);513 }514 function ribbonPathString(sx, sy, sdx, tx, ty, tdx, tension) {515 var m0, m1;516 return (tension === 1 ? [517 "M", [sx, sy],518 "L", [tx, ty],519 "h", tdx,520 "L", [sx + sdx, sy],521 "Z"]522 : ["M", [sx, sy],523 "C", [sx, m0 = tension * sy + (1 - tension) * ty], " ",524 [tx, m1 = tension * ty + (1 - tension) * sy], " ", [tx, ty],525 "h", tdx,526 "C", [tx + tdx, m1], " ", [sx + sdx, m0], " ", [sx + sdx, sy],527 "Z"]).join("");528 }529 function compareY(a, b) {530 a = height * a.y, b = height * b.y;531 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : a <= a ? -1 : b <= b ? 1 : NaN;532 }533 };534 d3.parsets.tree = buildTree;535 function autoDimensions(d) {536 return d.length ? d3.keys(d[0]).sort() : [];537 }538 function cancelEvent() {539 d3.event.stopPropagation();540 d3.event.preventDefault();541 }542 function dimensionName(d) { return d.name; }543 function getTotal(dimensions) {544 return dimensions[0].categories.reduce(function(a, d) {545 return a + d.count;546 }, 0);547 }548 // Given a text function and width function, truncates the text if necessary to549 // fit within the given width.550 function truncateText(text, width) {551 return function(d, i) {552 var t = this.textContent = text(d, i),553 w = width(d, i);554 if (this.getComputedTextLength() < w) return t;555 this.textContent = "â¦" + t;556 var lo = 0,557 hi = t.length + 1,558 x;559 while (lo < hi) {560 var mid = lo + hi >> 1;561 if ((x = this.getSubStringLength(0, mid)) < w) lo = mid + 1;562 else hi = mid;563 }564 return lo > 1 ? t.substr(0, lo - 2) + "â¦" : "";565 };566 }567 var percent = d3.format("%"),568 comma = d3.format(",f"),569 parsetsEase = "elastic",570 parsetsId = 0;571 // Construct tree of all category counts for a given ordered list of572 // dimensions. Similar to d3.nest, except we also set the parent.573 function buildTree(root, data, dimensions, value) {574 zeroCounts(root);575 var n = data.length,576 nd = dimensions.length;577 for (var i = 0; i < n; i++) {578 var d = data[i],579 v = +value(d, i),580 node = root;581 for (var j = 0; j < nd; j++) {582 var dimension = dimensions[j],583 category = d[dimension],584 children = node.children;585 node.count += v;586 node = children.hasOwnProperty(category) ? children[category]587 : children[category] = {588 children: j === nd - 1 ? null : {},589 count: 0,590 parent: node,591 dimension: dimension,592 name: category593 };594 }595 node.count += v;596 }597 return root;598 }599 function zeroCounts(d) {600 d.count = 0;601 if (d.children) {602 for (var k in d.children) zeroCounts(d.children[k]);603 }604 }605 function identity(d) { return d; }606 function translateY(d) { return "translate(0," + d.y + ")"; }607 function defaultTooltip(d) {608 var count = d.count,609 path = [];610 while (d.parent) {611 if (d.name) path.unshift(d.name);612 d = d.parent;613 }614 return path.join(" â ") + "<br>" + comma(count) + " (" + percent(count / d.count) + ")";615 }616 function defaultCategoryTooltip(d) {617 return d.name + "<br>" + comma(d.count) + " (" + percent(d.count / d.dimension.count) + ")";618 }...
d3.parsets.js
Source:d3.parsets.js
1// Parallel Sets by Jason Davies, http://www.jasondavies.com/2// Functionality based on http://eagereyes.org/parallel-sets3(function() {4 d3.parsets = function() {5 var event = d3.dispatch("sortDimensions", "sortCategories"),6 dimensions_ = autoDimensions,7 dimensionFormat = String,8 tooltip_ = defaultTooltip,9 categoryTooltip = defaultCategoryTooltip,10 value_,11 spacing = 20,12 width,13 height,14 tension = 1,15 tension0,16 duration = 500;17 function parsets(selection) {18 selection.each(function(data, i) {19 var g = d3.select(this),20 ordinal = d3.scale.ordinal(),21 dragging = false,22 dimensionNames = dimensions_.call(this, data, i),23 dimensions = [],24 tree = {children: {}, count: 0},25 nodes,26 total,27 ribbon;28 d3.select(window).on("mousemove.parsets." + ++parsetsId, unhighlight);29 if (tension0 == null) tension0 = tension;30 g.selectAll(".ribbon, .ribbon-mouse")31 .data(["ribbon", "ribbon-mouse"], String)32 .enter().append("g")33 .attr("class", String);34 updateDimensions();35 if (tension != tension0) {36 var t = d3.transition(g);37 if (t.tween) t.tween("ribbon", tensionTween);38 else tensionTween()(1);39 }40 function tensionTween() {41 var i = d3.interpolateNumber(tension0, tension);42 return function(t) {43 tension0 = i(t);44 ribbon.attr("d", ribbonPath);45 };46 }47 function updateDimensions() {48 // Cache existing bound dimensions to preserve sort order.49 var dimension = g.selectAll("g.dimension"),50 cache = {};51 dimension.each(function(d) { cache[d.name] = d; });52 dimensionNames.forEach(function(d) {53 if (!cache.hasOwnProperty(d)) {54 cache[d] = {name: d, categories: []};55 }56 dimensions.push(cache[d]);57 });58 dimensions.sort(compareY);59 // Populate tree with existing nodes.60 g.select(".ribbon").selectAll("path")61 .each(function(d) {62 var path = d.path.split("\0"),63 node = tree,64 n = path.length - 1;65 for (var i = 0; i < n; i++) {66 var p = path[i];67 node = node.children.hasOwnProperty(p) ? node.children[p]68 : node.children[p] = {children: {}, count: 0};69 }70 node.children[d.name] = d;71 });72 tree = buildTree(tree, data, dimensions.map(dimensionName), value_);73 cache = dimensions.map(function(d) {74 var t = {};75 d.categories.forEach(function(c) {76 t[c.name] = c;77 });78 return t;79 });80 (function categories(d, i) {81 if (!d.children) return;82 var dim = dimensions[i],83 t = cache[i];84 for (var k in d.children) {85 if (!t.hasOwnProperty(k)) {86 dim.categories.push(t[k] = {name: k});87 }88 categories(d.children[k], i + 1);89 }90 })(tree, 0);91 ordinal.domain([]).range(d3.range(dimensions[0].categories.length));92 nodes = layout(tree, dimensions, ordinal);93 total = getTotal(dimensions);94 dimensions.forEach(function(d) {95 d.count = total;96 });97 dimension = dimension.data(dimensions, dimensionName);98 var dEnter = dimension.enter().append("g")99 .attr("class", "dimension")100 .attr("transform", function(d) { return "translate(0," + d.y + ")"; })101 .on("mousedown.parsets", cancelEvent);102 dimension.each(function(d) {103 d.y0 = d.y;104 d.categories.forEach(function(d) { d.x0 = d.x; });105 });106 dEnter.append("rect")107 .attr("width", width)108 .attr("y", -45)109 .attr("height", 45);110 var textEnter = dEnter.append("text")111 .attr("class", "dimension")112 .attr("transform", "translate(0,-25)");113 textEnter.append("tspan")114 .attr("class", "name")115 .text(dimensionFormatName);116 textEnter.append("tspan")117 .attr("class", "sort alpha")118 .attr("dx", "2em")119 .text("alpha »")120 .on("mousedown.parsets", cancelEvent);121 textEnter.append("tspan")122 .attr("class", "sort size")123 .attr("dx", "2em")124 .text("size »")125 .on("mousedown.parsets", cancelEvent);126 dimension127 .call(d3.behavior.drag()128 .origin(identity)129 .on("dragstart", function(d) {130 dragging = true;131 d.y0 = d.y;132 })133 .on("drag", function(d) {134 d.y0 = d.y = d3.event.y;135 for (var i = 1; i < dimensions.length; i++) {136 if (height * dimensions[i].y < height * dimensions[i - 1].y) {137 dimensions.sort(compareY);138 dimensionNames = dimensions.map(dimensionName);139 ordinal.domain([]).range(d3.range(dimensions[0].categories.length));140 nodes = layout(tree = buildTree({children: {}, count: 0}, data, dimensionNames, value_), dimensions, ordinal);141 total = getTotal(dimensions);142 g.selectAll(".ribbon, .ribbon-mouse").selectAll("path").remove();143 updateRibbons();144 updateCategories(dimension);145 dimension.transition().duration(duration)146 .attr("transform", translateY)147 .tween("ribbon", ribbonTweenY);148 event.sortDimensions();149 break;150 }151 }152 d3.select(this)153 .attr("transform", "translate(0," + d.y + ")")154 .transition();155 ribbon.filter(function(r) { return r.source.dimension === d || r.target.dimension === d; })156 .attr("d", ribbonPath);157 })158 .on("dragend", function(d) {159 dragging = false;160 unhighlight();161 var y0 = 45,162 dy = (height - y0 - 2) / (dimensions.length - 1);163 dimensions.forEach(function(d, i) {164 d.y = y0 + i * dy;165 });166 transition(d3.select(this))167 .attr("transform", "translate(0," + d.y + ")")168 .tween("ribbon", ribbonTweenY);169 }));170 dimension.select("text").select("tspan.sort.alpha")171 .on("click.parsets", sortBy("alpha", function(a, b) { return a.name < b.name ? 1 : -1; }, dimension));172 dimension.select("text").select("tspan.sort.size")173 .on("click.parsets", sortBy("size", function(a, b) { return a.count - b.count; }, dimension));174 dimension.transition().duration(duration)175 .attr("transform", function(d) { return "translate(0," + d.y + ")"; })176 .tween("ribbon", ribbonTweenY);177 dimension.exit().remove();178 updateCategories(dimension);179 updateRibbons();180 }181 function sortBy(type, f, dimension) {182 return function(d) {183 var direction = this.__direction = -(this.__direction || 1);184 d3.select(this).text(direction > 0 ? type + " »" : "« " + type);185 d.categories.sort(function() { return direction * f.apply(this, arguments); });186 nodes = layout(tree, dimensions, ordinal);187 updateCategories(dimension);188 updateRibbons();189 event.sortCategories();190 };191 }192 function updateRibbons() {193 ribbon = g.select(".ribbon").selectAll("path")194 .data(nodes, function(d) { return d.path; });195 ribbon.enter().append("path")196 .each(function(d) {197 d.source.x0 = d.source.x;198 d.target.x0 = d.target.x;199 })200 .attr("class", function(d) { return "category-" + d.major; })201 .attr("d", ribbonPath);202 ribbon.sort(function(a, b) { return b.count - a.count; });203 ribbon.exit().remove();204 var mouse = g.select(".ribbon-mouse").selectAll("path")205 .data(nodes, function(d) { return d.path; });206 mouse.enter().append("path")207 .on("mousemove.parsets", function(d) {208 ribbon.classed("active", false);209 if (dragging) return;210 highlight(d = d.node, true);211 showTooltip(tooltip_.call(this, d));212 d3.event.stopPropagation();213 });214 mouse215 .sort(function(a, b) { return b.count - a.count; })216 .attr("d", ribbonPathStatic);217 mouse.exit().remove();218 }219 // Animates the x-coordinates only of the relevant ribbon paths.220 function ribbonTweenX(d) {221 var nodes = [d],222 r = ribbon.filter(function(r) {223 var s, t;224 if (r.source.node === d) nodes.push(s = r.source);225 if (r.target.node === d) nodes.push(t = r.target);226 return s || t;227 }),228 i = nodes.map(function(d) { return d3.interpolateNumber(d.x0, d.x); }),229 n = nodes.length;230 return function(t) {231 for (var j = 0; j < n; j++) nodes[j].x0 = i[j](t);232 r.attr("d", ribbonPath);233 };234 }235 // Animates the y-coordinates only of the relevant ribbon paths.236 function ribbonTweenY(d) {237 var r = ribbon.filter(function(r) { return r.source.dimension.name == d.name || r.target.dimension.name == d.name; }),238 i = d3.interpolateNumber(d.y0, d.y);239 return function(t) {240 d.y0 = i(t);241 r.attr("d", ribbonPath);242 };243 }244 // Highlight a node and its descendants, and optionally its ancestors.245 function highlight(d, ancestors) {246 if (dragging) return;247 var highlight = [];248 (function recurse(d) {249 highlight.push(d);250 for (var k in d.children) recurse(d.children[k]);251 })(d);252 highlight.shift();253 if (ancestors) while (d) highlight.push(d), d = d.parent;254 ribbon.filter(function(d) {255 var active = highlight.indexOf(d.node) >= 0;256 if (active) this.parentNode.appendChild(this);257 return active;258 }).classed("active", true);259 }260 // Unhighlight all nodes.261 function unhighlight() {262 if (dragging) return;263 ribbon.classed("active", false);264 hideTooltip();265 }266 function updateCategories(g) {267 var category = g.selectAll("g.category")268 .data(function(d) { return d.categories; }, function(d) { return d.name; });269 var categoryEnter = category.enter().append("g")270 .attr("class", "category")271 .attr("transform", function(d) { return "translate(" + d.x + ")"; });272 category.exit().remove();273 category274 .on("mousemove.parsets", function(d) {275 ribbon.classed("active", false);276 if (dragging) return;277 d.nodes.forEach(function(d) { highlight(d); });278 showTooltip(categoryTooltip.call(this, d));279 d3.event.stopPropagation();280 })281 .on("mouseout.parsets", unhighlight)282 .on("mousedown.parsets", cancelEvent)283 .call(d3.behavior.drag()284 .origin(identity)285 .on("dragstart", function(d) {286 dragging = true;287 d.x0 = d.x;288 })289 .on("drag", function(d) {290 d.x = d3.event.x;291 var categories = d.dimension.categories;292 for (var i = 0, c = categories[0]; ++i < categories.length;) {293 if (c.x + c.dx / 2 > (c = categories[i]).x + c.dx / 2) {294 categories.sort(function(a, b) { return a.x + a.dx / 2 - b.x - b.dx / 2; });295 nodes = layout(tree, dimensions, ordinal);296 updateRibbons();297 updateCategories(g);298 highlight(d.node);299 event.sortCategories();300 break;301 }302 }303 var x = 0,304 p = spacing / (categories.length - 1);305 categories.forEach(function(e) {306 if (d === e) e.x0 = d3.event.x;307 e.x = x;308 x += e.count / total * (width - spacing) + p;309 });310 d3.select(this)311 .attr("transform", function(d) { return "translate(" + d.x0 + ")"; })312 .transition();313 ribbon.filter(function(r) { return r.source.node === d || r.target.node === d; })314 .attr("d", ribbonPath);315 })316 .on("dragend", function(d) {317 dragging = false;318 unhighlight();319 updateRibbons();320 transition(d3.select(this))321 .attr("transform", "translate(" + d.x + ")")322 .tween("ribbon", ribbonTweenX);323 }));324 category.transition().duration(duration)325 .attr("transform", function(d) { return "translate(" + d.x + ")"; })326 .tween("ribbon", ribbonTweenX);327 categoryEnter.append("rect")328 .attr("width", function(d) { return d.dx; })329 .attr("y", -20)330 .attr("height", 20);331 categoryEnter.append("line")332 .style("stroke-width", 2);333 categoryEnter.append("text")334 .attr("dy", "-.3em");335 category.select("rect")336 .attr("width", function(d) { return d.dx; })337 .attr("class", function(d) {338 return "category-" + (d.dimension === dimensions[0] ? ordinal(d.name) : "background");339 });340 category.select("line")341 .attr("x2", function(d) { return d.dx; });342 category.select("text")343 .text(truncateText(function(d) { return d.name; }, function(d) { return d.dx; }));344 }345 });346 }347 parsets.dimensionFormat = function(_) {348 if (!arguments.length) return dimensionFormat;349 dimensionFormat = _;350 return parsets;351 };352 parsets.dimensions = function(_) {353 if (!arguments.length) return dimensions_;354 dimensions_ = d3.functor(_);355 return parsets;356 };357 parsets.value = function(_) {358 if (!arguments.length) return value_;359 value_ = d3.functor(_);360 return parsets;361 };362 parsets.width = function(_) {363 if (!arguments.length) return width;364 width = +_;365 return parsets;366 };367 parsets.height = function(_) {368 if (!arguments.length) return height;369 height = +_;370 return parsets;371 };372 parsets.spacing = function(_) {373 if (!arguments.length) return spacing;374 spacing = +_;375 return parsets;376 };377 parsets.tension = function(_) {378 if (!arguments.length) return tension;379 tension = +_;380 return parsets;381 };382 parsets.duration = function(_) {383 if (!arguments.length) return duration;384 duration = +_;385 return parsets;386 };387 parsets.tooltip = function(_) {388 if (!arguments.length) return tooltip;389 tooltip_ = _ == null ? defaultTooltip : _;390 return parsets;391 };392 parsets.categoryTooltip = function(_) {393 if (!arguments.length) return categoryTooltip;394 categoryTooltip = _ == null ? defaultCategoryTooltip : _;395 return parsets;396 };397 var body = d3.select("body");398 var tooltip = body.append("div")399 .style("display", "none")400 .attr("class", "parsets tooltip");401 return d3.rebind(parsets, event, "on").value(1).width(960).height(600);402 function dimensionFormatName(d, i) {403 return dimensionFormat.call(this, d.name, i);404 }405 function showTooltip(html) {406 var m = d3.mouse(body.node());407 tooltip408 .style("display", null)409 .style("left", m[0] + 30 + "px")410 .style("top", m[1] - 20 + "px")411 .html(html);412 }413 function hideTooltip() {414 tooltip.style("display", "none");415 }416 function transition(g) {417 return duration ? g.transition().duration(duration).ease(parsetsEase) : g;418 }419 function layout(tree, dimensions, ordinal) {420 var nodes = [],421 nd = dimensions.length,422 y0 = 45,423 dy = (height - y0 - 2) / (nd - 1);424 dimensions.forEach(function(d, i) {425 d.categories.forEach(function(c) {426 c.dimension = d;427 c.count = 0;428 c.nodes = [];429 });430 d.y = y0 + i * dy;431 });432 // Compute per-category counts.433 var total = (function rollup(d, i) {434 if (!d.children) return d.count;435 var dim = dimensions[i],436 total = 0;437 dim.categories.forEach(function(c) {438 var child = d.children[c.name];439 if (!child) return;440 c.nodes.push(child);441 var count = rollup(child, i + 1);442 c.count += count;443 total += count;444 });445 return total;446 })(tree, 0);447 // Stack the counts.448 dimensions.forEach(function(d) {449 d.categories = d.categories.filter(function(d) { return d.count; });450 var x = 0,451 p = spacing / (d.categories.length - 1);452 d.categories.forEach(function(c) {453 c.x = x;454 c.dx = c.count / total * (width - spacing);455 c.in = {dx: 0};456 c.out = {dx: 0};457 x += c.dx + p;458 });459 });460 var dim = dimensions[0];461 dim.categories.forEach(function(c) {462 var k = c.name;463 if (tree.children.hasOwnProperty(k)) {464 recurse(c, {node: tree.children[k], path: k}, 1, ordinal(k));465 }466 });467 function recurse(p, d, depth, major) {468 var node = d.node,469 dimension = dimensions[depth];470 dimension.categories.forEach(function(c) {471 var k = c.name;472 if (!node.children.hasOwnProperty(k)) return;473 var child = node.children[k];474 child.path = d.path + "\0" + k;475 var target = child.target || {node: c, dimension: dimension};476 target.x = c.in.dx;477 target.dx = child.count / total * (width - spacing);478 c.in.dx += target.dx;479 var source = child.source || {node: p, dimension: dimensions[depth - 1]};480 source.x = p.out.dx;481 source.dx = target.dx;482 p.out.dx += source.dx;483 child.node = child;484 child.source = source;485 child.target = target;486 child.major = major;487 nodes.push(child);488 if (depth + 1 < dimensions.length) recurse(c, child, depth + 1, major);489 });490 }491 return nodes;492 }493 // Dynamic path string for transitions.494 function ribbonPath(d) {495 var s = d.source,496 t = d.target;497 return ribbonPathString(s.node.x0 + s.x0, s.dimension.y0, s.dx, t.node.x0 + t.x0, t.dimension.y0, t.dx, tension0);498 }499 // Static path string for mouse handlers.500 function ribbonPathStatic(d) {501 var s = d.source,502 t = d.target;503 return ribbonPathString(s.node.x + s.x, s.dimension.y, s.dx, t.node.x + t.x, t.dimension.y, t.dx, tension);504 }505 function ribbonPathString(sx, sy, sdx, tx, ty, tdx, tension) {506 var m0, m1;507 return (tension === 1 ? [508 "M", [sx, sy],509 "L", [tx, ty],510 "h", tdx,511 "L", [sx + sdx, sy],512 "Z"]513 : ["M", [sx, sy],514 "C", [sx, m0 = tension * sy + (1 - tension) * ty], " ",515 [tx, m1 = tension * ty + (1 - tension) * sy], " ", [tx, ty],516 "h", tdx,517 "C", [tx + tdx, m1], " ", [sx + sdx, m0], " ", [sx + sdx, sy],518 "Z"]).join("");519 }520 function compareY(a, b) {521 a = height * a.y, b = height * b.y;522 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : a <= a ? -1 : b <= b ? 1 : NaN;523 }524 };525 d3.parsets.tree = buildTree;526 function autoDimensions(d) {527 return d.length ? d3.keys(d[0]).sort() : [];528 }529 function cancelEvent() {530 d3.event.stopPropagation();531 d3.event.preventDefault();532 }533 function dimensionName(d) { return d.name; }534 function getTotal(dimensions) {535 return dimensions[0].categories.reduce(function(a, d) {536 return a + d.count;537 }, 0);538 }539 // Given a text function and width function, truncates the text if necessary to540 // fit within the given width.541 function truncateText(text, width) {542 return function(d, i) {543 var t = this.textContent = text(d, i),544 w = width(d, i);545 if (this.getComputedTextLength() < w) return t;546 this.textContent = "â¦" + t;547 var lo = 0,548 hi = t.length + 1,549 x;550 while (lo < hi) {551 var mid = lo + hi >> 1;552 if ((x = this.getSubStringLength(0, mid)) < w) lo = mid + 1;553 else hi = mid;554 }555 return lo > 1 ? t.substr(0, lo - 2) + "â¦" : "";556 };557 }558 var percent = d3.format("%"),559 comma = d3.format(",f"),560 parsetsEase = "elastic",561 parsetsId = 0;562 // Construct tree of all category counts for a given ordered list of563 // dimensions. Similar to d3.nest, except we also set the parent.564 function buildTree(root, data, dimensions, value) {565 zeroCounts(root);566 var n = data.length,567 nd = dimensions.length;568 for (var i = 0; i < n; i++) {569 var d = data[i],570 v = +value(d, i),571 node = root;572 for (var j = 0; j < nd; j++) {573 var dimension = dimensions[j],574 category = d[dimension],575 children = node.children;576 node.count += v;577 node = children.hasOwnProperty(category) ? children[category]578 : children[category] = {579 children: j === nd - 1 ? null : {},580 count: 0,581 parent: node,582 dimension: dimension,583 name: category584 };585 }586 node.count += v;587 }588 return root;589 }590 function zeroCounts(d) {591 d.count = 0;592 if (d.children) {593 for (var k in d.children) zeroCounts(d.children[k]);594 }595 }596 function identity(d) { return d; }597 function translateY(d) { return "translate(0," + d.y + ")"; }598 function defaultTooltip(d) {599 var count = d.count,600 path = [];601 while (d.parent) {602 if (d.name) path.unshift(d.name);603 d = d.parent;604 }605 return path.join(" â ") + "<br>" + comma(count) + " (" + percent(count / d.count) + ")";606 }607 function defaultCategoryTooltip(d) {608 return d.name + "<br>" + comma(d.count) + " (" + percent(d.count / d.dimension.count) + ")";609 }...
Using AI Code Generation
1var stryker = require('stryker-parent');2var ts = stryker.parseTS('test.ts');3var stryker = require('stryker');4var ts = stryker.parseTS('test.ts');5var stryker = require('stryker-parent');6var ts = stryker.parseTS('test.ts');7var stryker = require('stryker');8var ts = stryker.parseTS('test.ts');9var stryker = require('stryker-parent');10var ts = stryker.parseTS('test.ts');11var stryker = require('stryker');12var ts = stryker.parseTS('test.ts');13var stryker = require('stryker-parent');14var ts = stryker.parseTS('test.ts');15var stryker = require('stryker');16var ts = stryker.parseTS('test.ts');17var stryker = require('stryker-parent');18var ts = stryker.parseTS('test.ts');19var stryker = require('stryker');20var ts = stryker.parseTS('test.ts');21var stryker = require('stryker-parent');22var ts = stryker.parseTS('test.ts');23var stryker = require('stryker');24var ts = stryker.parseTS('test.ts');25var stryker = require('stryker-parent');26var ts = stryker.parseTS('test.ts');27var stryker = require('stry
Using AI Code Generation
1var stryker = require('stryker-parent');2var strykerOptions = {3};4var files = stryker.parseTS(strykerOptions);5var stryker = require('stryker-typescript');6var strykerOptions = {7};8var files = stryker.parseTS(strykerOptions);9var stryker = require('stryker-typescript');10var strykerOptions = {11};12var files = stryker.parseTS(strykerOptions);13 at Object.parseTS (C:\Users\me\Documents\projects\stryker-typescript\node_modules\stryker-typescript\src\parseTS.js:18:33)14 at Object.create (C:\Users\me\Documents\projects\stryker-typescript\src\StrykerTypescript.js:20:33)
Using AI Code Generation
1const { parseTS } = require('stryker-parent');2import { parseTS } from 'stryker-parent';3const { parseTS } = require('stryker');4import { parseTS } from 'stryker';5const { parseTS } = require('stryker-core');6import { parseTS } from 'stryker-core';7const { parseTS } = require('stryker-api');8import { parseTS } from 'stryker-api';9const { parseTS } = require('stryker');10import { parseTS } from 'stryker';11const { parseTS } = require('stryker-parent');12import { parseTS } from 'stryker-parent';13const { parseTS } = require('stryker');14import { parseTS } from 'stryker';15const { parseTS } = require('stryker-parent');16import { parseTS } from 'stryker-parent';
Using AI Code Generation
1module.exports = {2 parseTS: function () {3 }4}5{6}7module.exports = function (config) {8 config.set({9 });10};11var strykerParent = require('stryker-parent');12strykerParent.parseTS();13var strykerParent = require('./stryker-parent');14strykerParent.parseTS();15var strykerParent = require('./stryker-parent/index');16strykerParent.parseTS();17var strykerParent = require('./stryker-parent/index.js');18strykerParent.parseTS();19var strykerParent = require('./stryker-parent/stryker.conf.js');20strykerParent.parseTS();21var strykerParent = require('./stryker-parent/stryker.conf');22strykerParent.parseTS();23var strykerParent = require('stryker-parent/stryker.conf');24strykerParent.parseTS();25var strykerParent = require('stryker-parent/stryker.conf.js');26strykerParent.parseTS();27var strykerParent = require('stryker-parent/stryker.conf.js');28strykerParent.parseTS();29var strykerParent = require('stryker-parent/stryker.conf.js');30strykerParent.parseTS();31var strykerParent = require('stryker-parent/stryker.conf');32strykerParent.parseTS();33var strykerParent = require('stryker-parent/stryker.conf.js');34strykerParent.parseTS();35var strykerParent = require('stryker-parent/stryker.conf.js');36strykerParent.parseTS();37var strykerParent = require('stryker-parent/stryker.conf');38strykerParent.parseTS();
Using AI Code Generation
1const strykerParent = require('stryker-parent');2const result = strykerParent.parseTS('some string');3console.log(result);4module.exports = {5 parseTS: (input) => {6 return 'parsed' + input;7 }8};
Using AI Code Generation
1const { parseTS } = require('stryker-parent');2const ts = require('typescript');3console.log(parseTS('const x = 1;', ts));4const { parseTS } = require('stryker-parent');5const ts = require('typescript');6console.log(parseTS('const x = 1;', ts));7const { parseTS } = require('stryker-parent');8const ts = require('typescript');9console.log(parseTS('const x = 1;', ts));10const { parseTS } = require('stryker-parent');11const ts = require('typescript');12console.log(parseTS('const x = 1;', ts));13const { parseTS } = require('stryker-parent');14const ts = require('typescript');15console.log(parseTS('const x = 1;', ts));16const { parseTS } = require('stryker-parent');17const ts = require('typescript');18console.log(parseTS('const x = 1;', ts));19const { parseTS } = require
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!!