Skip to content
Snippets Groups Projects
Commit c63f0b34 authored by IsolatedSushi's avatar IsolatedSushi
Browse files

Small chart alterations

parent fe5f9512
No related branches found
No related tags found
No related merge requests found
...@@ -28,12 +28,12 @@ function generatePoint(){ ...@@ -28,12 +28,12 @@ function generatePoint(){
var xVal = Math.floor(Math.random()*20); var xVal = Math.floor(Math.random()*20);
var yVal = Math.floor(Math.random()*20); var yVal = Math.floor(Math.random()*20);
count++; count++;
console.log("Generated point. ID: " + count + " x: " + xVal + " y: " + yVal);
return {id:count, x:xVal,y:yVal}; return {id:count, x:xVal,y:yVal};
} }
//SERVICE //SERVICE
function sendPoint(call, callback) { function sendPoint(call, callback) {
callback(null, generatePoint()); callback(null, generatePoint());
console.log("sent point!");
} }
/** /**
* @param {!Object} call * @param {!Object} call
...@@ -43,13 +43,12 @@ function sendPointStream(call) { ...@@ -43,13 +43,12 @@ function sendPointStream(call) {
function sender(point) { function sender(point) {
return (callback) => { return (callback) => {
call.write(point); call.write(point);
_.delay(callback, 500); // in ms _.delay(callback, 1); // in ms
}; };
} }
var senders = []; var senders = [];
var count = 10; var count = 10;
console.log("Will send " + count);
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
senders[i] = sender(generatePoint()); senders[i] = sender(generatePoint());
} }
......
<template> <template>
<div id="app" class="my-10"> <div id="app" class="my-10">
<h3>ScatterPlot in d3</h3> <h3>ScatterPlot in d3</h3>
<svg id="chart" viewBox="0 0 500 500"></svg> <svg id="chart" width ='500' height ='500'></svg>
</div> </div>
</template> </template>
...@@ -68,14 +68,17 @@ export default { ...@@ -68,14 +68,17 @@ export default {
this.xAxis.call(d3.axisBottom(this.x)); this.xAxis.call(d3.axisBottom(this.x));
this.yAxis.call(d3.axisLeft(this.y)); this.yAxis.call(d3.axisLeft(this.y));
var color = d3.scaleOrdinal()
.domain([-1, 0, 1])
.range([ "#F8766D", "#00BA38", "#619CFF"])
this.chart.selectAll(".point") this.chart.selectAll(".point")
.data(this.dataPoints) .data(this.dataPoints)
.join("g") .join("g")
.attr("class", "point") .attr("class", "point")
.attr("transform", d => `translate(${this.x(d.x)}, ${this.y(d.y)})`) .attr("transform", d => `translate(${this.x(d.x)}, ${this.y(d.y)})`)
.append("circle") .append("circle")
.attr("r", 5); .attr("r", 8)
.style('fill',function (d) { return color((d.x*d.x+d.y*d.y)%3) });
}, },
addPointToPlot(point) { addPointToPlot(point) {
this.dataPoints.push({ this.dataPoints.push({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment