Skip to content

Commit

Permalink
Added a Truncate test page
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Wright committed May 31, 2018
1 parent 6d62abe commit 22c86cd
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions pages/Truncate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<html>
<head>
<style>
body { background: #CCC; }
</style>
</head>
<body>
<svg width="1000" height="1000"></svg>
</body>
</html>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="../build/d3plus-text.full.js"></script>
<script type="text/javascript">
const radius = 150;

// Use the d3Plus TextBox class
const d3PlusWrap = (gs, data) => {
gs.each(function(d, i, elements) {
console.log(d, i, elements);
new d3plus
.TextBox()
.data([d])
.select(this)
.fontResize(true)
.height(radius)
.width(radius)
.text(d => d.name)
.x(d => -radius / 2)
.y(d => -radius / 2)
.ellipsis(text => {
// return text.splice()
// console.log(text);
return text.replace(/\.|,$/g, "") + "...";
})
.verticalAlign("middle")
.textAnchor("middle")
.render();
});
};

const circles = [
{ x: 500, y: 150, name: "ABCDEFGHIJKLMNOPQRSTUVWXYZ12" },
{ x: 500, y: 500, name: "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" },
];

const join = d3
.select("svg")
.selectAll("g")
.data(circles);

const g = join.enter()
.append("g")
.attr("transform", d => `translate(${d.x}, ${d.y})`);

g.append("circle")
.attr("r", radius)
.style("fill", "#009600");

d3PlusWrap(g, circles);

</script>

0 comments on commit 22c86cd

Please sign in to comment.