Fixing the Mess - no cloning
http://stackoverflow.com/questions/23238348/duplicate-axis-nodes-when-resetting-d3-bar-chart-to-original-data-source
by Nivaldo
HTML
<b>Drag a bar or two and click the Reset button. Note how the table redraws properly but the chart doesn't.</b>
<p>
<table id="grid" cellpadding="0" cellspacing="0" border-collapse="collapse" border="1"></table>
<p><button class="btn btn-primary">Redraw</button></p>
<svg class="chart"></svg>
</p>
CSS
svg {
shape-rendering: crispEdges;
}
.bar {
fill: #4ae;
cursor: move;
opacity: 0.8;
}
.bar:hover {
opacity: 0.8;
stroke-opacity: 1;
}
.fixed {
fill: red;
}
.original {
fill: #4ae;
opacity: 0.2;
stroke: #4ae;
}
.moved {
}
.smooth {
shape-rendering: geometricPrecision;
opacity: 0.3;
}
.smooth:hover {
opacity: 1;
cursor: pointer;
}
.axis text, .label, td, th {
font: 13px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.y.axis g text {
fill: white;
/* The visibility attribute doesn't work for some reason so I make the text white */
visibility: hidden:
}
table, th, td {
border: 1px solid black;
padding: 2px;
border-collapse: collapse;
}
tr td:last-child {
text-align: right;
}
b {
font-family: sans-serif;
}
};
JavaScript
var data =
[{
"name": "Income tax",
"value": "170800",
"description": "Personal income taxes in Australia are imposed on the personal income of each person on a progressive basis, with higher rates applying to higher income levels. Individuals are also taxed on their share of any partnership or trust profits to which they are entitled for the financial year."
},
{
"name": "Fringe benefits tax",
"value": "4270",
"description": "Fringe benefits are benefits paid to an employee (or associate) in respect of employment, such as a car, car parking, low interest loan and payments of private expenses. Fringe Benefits Tax (FBT) is the tax payable on the provision of these benefits. FBT is separate from income tax and is calculated on the taxable value of the various benefits provided."
},
{
"name": "Company tax",
"value": "71650",
"description": "Companies pay tax on their profits."
},
{
"name": "Superannuation funds",
"value": "8340",
"description": "Superannuation (super) is money set aside over your lifetime to provide for your retirement. Super funds invest your money in many things, such as shares, property and managed funds."
},
{
"name": "Resource rent taxes",
"value": "3100",
"description": "The Minerals Resource Rent Tax (MRRT) is a tax on profits generated from the exploitation of non-renewable resources in Australia such as iron ore and coal. The Petroleum Resource Rent Tax (PRRT) is a tax generally on profits generated from the sale of marketable petroleum commodities."
},
{
"name": "Goods and services tax (GST)",
"value": "50443",
"description": "Goods and services tax (GST) is a broad-based tax of 10% on most goods, services and other childrens sold or consumed in Australia. Generally, businesses registered for GST will include GST in the price of sales to their customers, and claim credits for the GST included in the price of their business purchases."
},
{
"name": "Excise",
"value": "26560"
},
{
"name": "Other...