Skip to content

Experiments

RobinFrugte97 edited this page Nov 11, 2019 · 9 revisions

Datacleaning

I started cleaning the survey data from CMD. I tried loading in a csv file with d3.csv but I ran into some issues.

d3.csv("https://gist.github.com/RobinFrugte97/a5e17cb2420bb1a671ff3912fb1d8cda")
    .then((data) => console.log(data))

First I tried loading in the data from my csv hosted on a gist on Github. I got an error related to gist, so I put the csv file locally.


SPARQL data

I am fetching my SPARQL query data with an asynchoronous function;

async function runQuery(queryUrl, query){
    let getData = await fetch(queryUrl+"?query="+ encodeURIComponent(query) +"&format=json")
    let responseData = await getData.json()
    let data = responseData.results.bindings
    console.log(data)
    return data
}

I await the fetch results before I put it in a variable and turn it into JSON.


D3 experiment

 <svg viewbox="0 0 1000 1000">
        <defs>
            <radialGradient id="myGradient">
                <stop offset="10%" stop-color="gold" />
                <stop offset="95%" stop-color="red" />
            </radialGradient>
        </defs>
        
        <!-- using my linear gradient -->
        <g>
            <circle cx="500" cy="250" r="120" fill="url('#myGradient')">
                <animate attributeName="r" values="150;175;150" dur="3s" repeatCount="indefinite" />
            </circle>
            <circle cx="450" cy="200" r="20" fill="black"></circle>
            <circle cx="550" cy="200" r="20" fill="black"></circle>
            <ellipse cx="500" cy="300" rx="40" ry="20" fill="black"></ellipse>
            <rect width="20" height="20" x="510" y="250" fill="white">
            </rect>
        </g>
    </svg>

For my first experiment with D3 I played around with different kinds of D3 supported elements. The first thing I did was create an SVG tag to render. After that I created a circle around the middle of my screen to create a smiley with. I added a circular gradient to the circle to play around with. I defined the gradient inside a defs tag, which allows me to call to the gradient inside it with an id. I then made the eyes by creating two circles and tweaking the offset. The mouth is a horizontally dominant ellipse. There is a rect tag for a tooth inside the mouth.

    <!-- using my linear gradient -->
    <g>
        <circle cx="500" cy="250" r="120" fill="url('#myGradient')">
            <animate attributeName="r" values="150;175;150" dur="3s" repeatCount="indefinite" />
        </circle>
        <circle cx="450" cy="200" r="20" fill="black"></circle>
        <circle cx="550" cy="200" r="20" fill="black"></circle>
        <ellipse cx="500" cy="300" rx="40" ry="20" fill="black"></ellipse>
        <rect width="20" height="20" x="510" y="250" fill="white">
        </rect>
    </g>
</svg>

Clone this wiki locally