function go() {
const data = [
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC23173204",
"_score" : null,
"_source" : {
"mls_status" : "ACT",
"mls_sold_date" : 1697608800000,
"mls_list_price" : "995000",
"mls_sold_price" : null,
"mls_list_date" : 1697608800000
},
"sort" : [
1697608800000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC23173109",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1697695200000,
"mls_list_price" : "450000",
"mls_sold_price" : "520000",
"mls_list_date" : 1695794400000
},
"sort" : [
1695794400000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC23107468",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1693461600000,
"mls_list_price" : 775000,
"mls_sold_price" : "851000",
"mls_list_date" : 1689919200000
},
"sort" : [
1689919200000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC23041606",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1681797600000,
"mls_list_price" : 995000,
"mls_sold_price" : "1000000",
"mls_list_date" : 1679551200000
},
"sort" : [
1679551200000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC23002857",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1677222000000,
"mls_list_price" : 749000,
"mls_sold_price" : "749000",
"mls_list_date" : 1673247600000
},
"sort" : [
1673247600000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC22261304",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1676358000000,
"mls_list_price" : 1275000,
"mls_sold_price" : "1300000",
"mls_list_date" : 1673247600000
},
"sort" : [
1673247600000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC22151061",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1659247200000,
"mls_list_price" : 985000,
"mls_sold_price" : "975000",
"mls_list_date" : 1658988000000
},
"sort" : [
1658988000000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC22151522",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1659506400000,
"mls_list_price" : 1150000,
"mls_sold_price" : "1140000",
"mls_list_date" : 1657605600000
},
"sort" : [
1657605600000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC22123681",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1657000800000,
"mls_list_price" : 1995000,
"mls_sold_price" : "2000000",
"mls_list_date" : 1655445600000
},
"sort" : [
1655445600000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC21241191",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1639897200000,
"mls_list_price" : 230000,
"mls_sold_price" : "225000",
"mls_list_date" : 1640156400000
},
"sort" : [
1640156400000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC21075928",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1620540000000,
"mls_list_price" : 919000,
"mls_sold_price" : "933400",
"mls_list_date" : 1618812000000
},
"sort" : [
1618812000000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC20108860",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1594879200000,
"mls_list_price" : 650000,
"mls_sold_price" : "635000",
"mls_list_date" : 1591941600000
},
"sort" : [
1591941600000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC20091110",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1592719200000,
"mls_list_price" : 350000,
"mls_sold_price" : "350000",
"mls_list_date" : 1589695200000
},
"sort" : [
1589695200000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC20079724",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1592114400000,
"mls_list_price" : 875000,
"mls_sold_price" : "900000",
"mls_list_date" : 1589263200000
},
"sort" : [
1589263200000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC20060435",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1588658400000,
"mls_list_price" : 650000,
"mls_sold_price" : "646720",
"mls_list_date" : 1585893600000
},
"sort" : [
1585893600000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC19079283",
"_score" : null,
"_source" : {
"mls_status" : "WDN",
"mls_sold_date" : 1697608800000,
"mls_list_price" : 349000,
"mls_sold_price" : null,
"mls_list_date" : 1556863200000
},
"sort" : [
1556863200000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC19075083",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1563084000000,
"mls_list_price" : 759000,
"mls_sold_price" : "750000",
"mls_list_date" : 1554444000000
},
"sort" : [
1554444000000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC19073915",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1558504800000,
"mls_list_price" : 1688000,
"mls_sold_price" : "1700000",
"mls_list_date" : 1554357600000
},
"sort" : [
1554357600000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC19049000",
"_score" : null,
"_source" : {
"mls_status" : "ACT",
"mls_sold_date" : 1557813600000,
"mls_list_price" : 949000,
"mls_sold_price" : "930000",
"mls_list_date" : 1551942000000
},
"sort" : [
1551942000000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC18233234",
"_score" : null,
"_source" : {
"mls_status" : "WDN",
"mls_sold_date" : 1697608800000,
"mls_list_price" : 1715000,
"mls_sold_price" : null,
"mls_list_date" : 1540879200000
},
"sort" : [
1540879200000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC18046929",
"_score" : null,
"_source" : {
"mls_status" : "ACT",
"mls_sold_date" : 1523944800000,
"mls_list_price" : 949000,
"mls_sold_price" : "955000",
"mls_list_date" : 1520920800000
},
"sort" : [
1520920800000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC17267094",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1514444400000,
"mls_list_price" : 659000,
"mls_sold_price" : "660000",
"mls_list_date" : 1512111600000
},
"sort" : [
1512111600000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC17230343",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1512889200000,
"mls_list_price" : 728000,
"mls_sold_price" : "710000",
"mls_list_date" : 1507356000000
},
"sort" : [
1507356000000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC17080557",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1493532000000,
"mls_list_price" : 1457000,
"mls_sold_price" : "1457000",
"mls_list_date" : 1492236000000
},
"sort" : [
1492236000000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC17031485",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1491890400000,
"mls_list_price" : 349000,
"mls_sold_price" : "312333",
"mls_list_date" : 1487142000000
},
"sort" : [
1487142000000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC17031840",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1491890400000,
"mls_list_price" : 349000,
"mls_sold_price" : "312334",
"mls_list_date" : 1487142000000
},
"sort" : [
1487142000000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC17031560",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1491890400000,
"mls_list_price" : 349000,
"mls_sold_price" : "312333",
"mls_list_date" : 1487142000000
},
"sort" : [
1487142000000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC17001339",
"_score" : null,
"_source" : {
"mls_status" : "SLD",
"mls_sold_date" : 1490508000000,
"mls_list_price" : 649000,
"mls_sold_price" : "644500",
"mls_list_date" : 1483599600000
},
"sort" : [
1483599600000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC16098285",
"_score" : null,
"_source" : {
"mls_status" : "ACT",
"mls_sold_date" : 1470808800000,
"mls_list_price" : 475000,
"mls_sold_price" : "465000",
"mls_list_date" : 1462773600000
},
"sort" : [
1462773600000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC16089913",
"_score" : null,
"_source" : {
"mls_status" : "ACT",
"mls_sold_date" : 1466056800000,
"mls_list_price" : 1029000,
"mls_sold_price" : "1034000",
"mls_list_date" : 1461909600000
},
"sort" : [
1461909600000
]
},
{
"_index" : "bk_vre_full11",
"_type" : "_doc",
"_id" : "10_CAMRMLS-Q||OC16088187",
"_score" : null,
"_source" : {
"mls_status" : "ACT",
"mls_sold_date" : 1466575200000,
"mls_list_price" : 689000,
"mls_sold_price" : "689000",
"mls_list_date" : 1461736800000
},
"sort" : [
1461736800000
]
}
]
const width = 500;
const height = 300;
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height);
const parsedData = data.map(d => ({
date: new Date(d._source.mls_list_date),
price: d._source.mls_list_price,
status: d._source.mls_status
}));
// sort data by date
parsedData.sort((a, b) => a.date - b.date);
const simulation = d3.forceSimulation(parsedData)
.force("x", d3.forceX(width / 2))
.force("y", d3.forceY(height / 2))
.force("collide", d3.forceCollide(d => Math.sqrt(d.price / 1000)))
.on("tick", ticked);
function ticked() {
const circles = svg.selectAll("circle")
.data(parsedData, d => d.date);
circles.enter().append("circle")
.attr("r", d => Math.sqrt(d.price / 1000))
.attr("fill", d => d.status === "SLD" ? "green" : "red")
.merge(circles)
.attr("cx", d => d.x)
.attr("cy", d => d.y);
circles.exit().remove();
}
return svg.node()
}