Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head>
    <title>Event Tagger</title>
    <meta name="viewport" content="width=device-width,initial-scale=1">

    <link rel="stylesheet" href="styles.css">
</head>

<body>
    
    <div id="title-bar-container">
        <div id="title">
            <h3>Event tagger</h3>
            <span>Simple match event tagger & x/y export. Click your event name, then the location. Simple. Add events with the text box - enter to add what you type. The centre circle marks location (0,0).</span>
        </div>
    </div>
    
    <div id="event-container">
    
        <button class="event-button" id="test">Pass</button>
        <button class="event-button">Assist pass</button>
        <button class="event-button">Shot</button>
        <button class="event-button">Take-on</button>
        <button class="event-button">Possession start</button>
    
    
    </div>
    
    <div id="input-container">
        <input type = "text" id="add-event" placeholder="Add event type" onkeypress="handler(event)">
    </div>
 
 
  
    <div id="pitch-container">    
		<canvas id = "myCanvas" width = "1000" height = "680">
  
		</canvas>
    </div>
    
    <div id="table-button-container">
    
        <div id="table-container">
            <table id="data">
                <thead>
                    <tr>
                        <th>Event Name</th>
                        <th>X Location</th>
                        <th>Y Location</th>
                    </tr>
                </thead>
                <tbody id="data-body">

                </tbody>



            </table>
        </div>

        <div id = "button-container">
            <p><button id="undo">Delete Last</button></p>
            <p><button id="clear">Delete All</button></p>
            <p><button id="export" onclick="exportTableToCSV('shotcoords.csv')">Export Table To CSV File</button></p>
            
        </div>
        
    </div>
           
        

</body>
              
            
!

CSS

              
                body{
    background-color: #fff;
    font-family: arial;
}

#title-bar-container{
    width:100%;
}

#title{
    width:58%;
    margin: 0 auto;
}

#title>h3{
    display:inline;
    margin-right: 10px;
}

#event-container, #input-container{
    width:35%;
    margin: 0 auto;
    text-align: center;
}

#event-container {
    margin-top: 40px;
}

#add-event{
    margin: 30 auto;
}

.event-button{
    margin-left: 20px;
    margin-top: 10px;
}

#pitch-container{
    width:20%;
    display:inline-block;
    margin:0 auto;
    margin-left: 20%;
    margin-top: 40px;
    
}

#table-button-container{
    width:50%;
    margin:0 auto;
    margin-top: 800px;
    display:inline-block;
    vertical-align: top;
}

#myCanvas{
    margin:0 auto;
    display:block;
    margin:auto;
}

#table-container{
    width:40%;
    overflow-y: scroll;
    height:300px;
    margin-top:10px;
    display:inline;
    float:left;
    margin: 0 auto;
    margin-left: 10%;
}

#data{
    height:200px;
    margin: 0 auto;
}

#button-container{
    width:30%;
    text-align: center;
    margin-top: 15px;
    margin: 0 auto;
    display: inline;
    float:right;
    margin-right: 20%;
}

#export{
    margin:0 auto;
}




#button-container>button{
    margin-top:5px;
}

td{
    text-align: center;
}

#myCanvas{
  border: 1px solid grey;
  background-color: #ffff;
}

@media only screen and (max-width: 1600px) {
    #pitch-container{
        margin-left:20%;
    }
    
    #table-button-container{
        width: 50%;
        display: inline-block;
    }
}


@media only screen and (max-width: 1100px) {
    #title{
        width:80%;
    }
    #pitch-container{
        margin-left: 2.5%;
    }
    
    #table-button-container{
        width:60%;
    }
    
    #button-container{
        width:30%;
        float:left;
        margin: 0 auto;
    }
    #table-container{
        width:40%;
    }
    body{
        font-size:14px;
    }
}

@media only screen and (max-width: 900px) {
    
    #pitch-container{
        display: block;
        margin: 0;
        padding-left: 25%;
    }
    #table-button-container{
        display: block;
        margin: 0 auto;
        margin-top: 50px;
    }

@media only screen and (max-width: 800px) {
    #title{
        width:95%;
    }
    #event-container{
        width: 95%;
    }
    #table-container{
        width:100%;
        margin: 0 auto;
        height: 150px;
    }
    #button-container{
        width:90%;
        margin: 0 auto;
        position: inherit;
    }
    
 
    #event-container{
        margin:5px 5px;
    }
    
    .event-button{
        margin: 2px;
    }
    #input-container{
        margin: 2px auto;
        text-align: center;
        width: 90%;
    }
    
    
    @media only screen and (max-width: 500px) {
        #pitch-container{
            margin-left: 0px;
        }
    }

              
            
!

JS

              
                var eventType = "Pass"

var eventButtons = document.getElementsByClassName("event-button");

var changeEvent = function() {
    eventType = this.innerHTML;
    };

for (var i = 0; i < eventButtons.length; i++){
    eventButtons[i].onclick = changeEvent;
};

var addEventButton = function(){
    var buttonText = document.getElementById("add-event").value;
    var buttonHTML = "<button class=\"event-button\" id=\"" +buttonText+ "\">"+buttonText+"</button>"
    document.getElementById("event-container").innerHTML += buttonHTML;
    for (var i = 0; i < eventButtons.length; i++){
        eventButtons[i].onclick = changeEvent;
    };
}

var handler = function(e) {
    var key = e.keyCode;
    
    if (key==13){
        addEventButton();
    };
    
};

var myCanvas = document.getElementById("myCanvas");
var context = myCanvas.getContext("2d");

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
context.strokeStyle = "grey"
ctx.beginPath();
ctx.moveTo(55,0);
ctx.lineTo(55,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(110,0);
ctx.lineTo(110,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(165,0);
ctx.lineTo(165,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(220,0);
ctx.lineTo(220,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(275,0);
ctx.lineTo(275,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(330,0);
ctx.lineTo(330,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(385,0);
ctx.lineTo(385,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(440,0);
ctx.lineTo(440,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(945,0);
ctx.lineTo(945,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(890,0);
ctx.lineTo(890,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(835,0);
ctx.lineTo(835,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(780,0);
ctx.lineTo(780,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(725,0);
ctx.lineTo(725,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(670,0);
ctx.lineTo(670,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(615,0);
ctx.lineTo(615,680);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(560,0);
ctx.lineTo(560,680);
ctx.stroke();



ctx.beginPath();
ctx.moveTo(0,65.2);
ctx.lineTo(1000,65.2);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(0,111);
ctx.lineTo(1000,111);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(0,156.8);
ctx.lineTo(1000,156.8);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(0,202.6);
ctx.lineTo(1000,202.6);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(0,248.4);
ctx.lineTo(1000,248.4);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(0,294.2);
ctx.lineTo(1000,294.2);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(0,340);
ctx.lineTo(1000,340);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(0,385.8);
ctx.lineTo(1000,385.8);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(0,431.6);
ctx.lineTo(1000,431.6);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(0,477.4);
ctx.lineTo(1000,477.4);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(0,523.2);
ctx.lineTo(1000,523.2);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(0,569);
ctx.lineTo(1000,569);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(0,614.8);
ctx.lineTo(1000,614.8);
ctx.stroke();



context.strokeStyle = "black";

//Pitch, box, 6-yard rectangles
context.strokeRect(0,0,1000,680);
context.strokeRect(0,0,500,680);

context.strokeRect(0,140,165,400);
context.strokeRect(0,248.5,55,183);

context.strokeRect(835,140,839.5,400);
context.strokeRect(944.5,248.5,55,183);

//Centre circle & line

context.beginPath()
context.arc(500, 340, 90, 0, 2*Math.PI);
context.stroke();
context.closePath();

//Pen & centre spots

context.beginPath();
context.arc(500, 340, 3, 0, 2*Math.PI);
context.fillStyle = "black";
context.fill();
context.closePath();

context.beginPath();
context.arc(110, 340, 3, 0, 2*Math.PI);
context.fillStyle = "black";
context.fill();
context.closePath();  

context.beginPath();
context.arc(890, 340, 3, 0, 2*Math.PI);
context.fillStyle = "black";
context.fill();
context.closePath();

//Pen area D

context.beginPath();
context.arc(110,340,90,0.975,5.30,true);
context.stroke();
context.closePath();

context.beginPath();
context.arc(890,340,90,4.125,2.180,true);
context.stroke();
context.closePath

function getMousePos(canvas, evt) {
        var rect = myCanvas.getBoundingClientRect();
        return {
          x: evt.clientX - rect.left,
          y: evt.clientY - rect.top
        };
      }

	  
//Function adds x/y location & event. At standard size, 0,0 is centre spot
myCanvas.addEventListener('click', function(evt) {
        var mousePos = getMousePos(myCanvas, evt);
        var table = document.getElementById("data-body");
		var row = table.insertRow(-1);
		var cell1 = row.insertCell(0);
		var cell2 = row.insertCell(1);
		var cell3 = row.insertCell(2);
	  cell2.innerHTML = (Math.floor(mousePos.x)); 
		cell3.innerHTML = (Math.floor(mousePos.y));
		document.getElementById("table-container").scrollTop = document.getElementById("table-container").scrollHeight;
});

document.getElementById("undo").onclick = function(){
    
    var table = document.getElementById("data");
    if (table.rows.length > 1){
    table.deleteRow((table.rows.length)-1);
    };
    
};

document.getElementById("clear").onclick = function(){
    
    var table = document.getElementById("data");
    document.getElementById("data").innerHTML = 
        "<thead><tr><th>Event Name</th><th>X Location</th><th>Y Location</th></tr></thead><tbody id=\"data-body\"></tbody>";    
    
};


function downloadCSV(csv, filename) {
    var csvFile;
    var downloadLink;

    // CSV file
    csvFile = new Blob([csv], {type: "text/csv"});

    // Download link
    downloadLink = document.createElement("a");

    // File name
    downloadLink.download = filename;

    // Create a link to the file
    downloadLink.href = window.URL.createObjectURL(csvFile);

    // Hide download link
    downloadLink.style.display = "none";

    // Add the link to DOM
    document.body.appendChild(downloadLink);

    // Click download link
    downloadLink.click();
}


function exportTableToCSV(filename) {
    var csv = [];
    var rows = document.querySelectorAll("table tr");
    
    for (var i = 0; i < rows.length; i++) {
        var row = [], cols = rows[i].querySelectorAll("td, th");
        
        for (var j = 0; j < cols.length; j++) 
            row.push(cols[j].innerText);
        
        csv.push(row.join(","));        
    }

    // Download CSV file
    downloadCSV(csv.join("\n"), filename);
}
              
            
!
999px

Console