// Numbas version: exam_results_page_options {"name": "Testing JSXGraph for a network diagram", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"advice": "", "statement": "

Goal: Make a diagram so students can click on the edges in a network diagram and create a tree.

", "metadata": {"licence": "None specified", "description": ""}, "rulesets": {}, "ungrouped_variables": ["a", "b"], "variablesTest": {"maxRuns": 100, "condition": "a<>b"}, "preamble": {"js": "", "css": ""}, "name": "Testing JSXGraph for a network diagram", "tags": [], "parts": [{"showCorrectAnswer": true, "marks": 0, "gaps": [{"showFeedbackIcon": true, "marks": 1, "variableReplacements": [], "type": "numberentry", "maxValue": "1", "correctAnswerStyle": "plain", "mustBeReducedPC": 0, "minValue": "1", "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "variableReplacementStrategy": "originalfirst", "mustBeReduced": false, "correctAnswerFraction": false, "scripts": {"validate": {"order": "instead", "script": "console.log('Validating');\nreturn true;"}, "mark": {"order": "instead", "script": "console.log('Marking');\n\nvar selectedEdges=[]\n\nvar totalVertices=Object.keys(this.PointDict).length;\nconsole.log(\"There are \"+totalVertices+\" in this graph\");\n\nfor (i=0;i0){\n // grab the \"first\" item in the set (and remove it from the set)\n var chosenPoint=newPoints.values().next()['value'];\n newPoints.delete(chosenPoint);\n oldPoints.add(chosenPoint);\n \n // Loop (backwards) over all the selected edges looking for new points\n // remove edges that get used to reduced redundancy\n for (j=selectedEdges.length-1;j>=0;j--){\n // Make foundPoint a 'falsey' value\n foundPoint=false;\n if (selectedEdges[j][0]==chosenPoint){\n foundPoint=selectedEdges[j][1];\n } else if (selectedEdges[j][1]==chosenPoint){\n foundPoint=selectedEdges[j][0]; \n }\n // Check the truthy-ness of foundPoint\n if (foundPoint){\n // splice out the found edge\n selectedEdges.splice(j,1);\n console.log(\"Splicing\");\n console.log(selectedEdges);\n if (oldPoints.has(foundPoint)){\n } else {\n newPoints.add(foundPoint);\n // console.log(newPoints);\n }\n }\n }\n }\n console.log(oldPoints);\n if (oldPoints.size < totalVertices){\n this.setCredit(0,\"Your graph is not connected\");\n } else {\n if (totalSelected > totalVertices-1) {\n this.setCredit(0,\"Your graph contains loops.\");\n } else {\n this.setCredit(1,\"Your have created a tree. Good work!\");\n }\n }\n}\n//Check if all points were connected\n\n\n// Find all edges containing this edge and add the other points to the \"new\" set \n\n// Place this vertex in the \"old\" set remove it from the \"new\"\n\n// Pick a vertex from the \"new\" set and iterate\n\n// Now the loop has terminated we have all vertices connected to \"A\".\n// Check if the number of vertices we have found equals the number of vertices we should have.\n\n"}}, "allowFractions": false}], "variableReplacementStrategy": "originalfirst", "variableReplacements": [], "type": "gapfill", "scripts": {}, "prompt": "

{createNetwork()}

\n

This will be the information only part.

", "showFeedbackIcon": true}], "variables": {"b": {"definition": "random(0.1..1#0.1)", "name": "b", "description": "", "templateType": "randrange", "group": "Ungrouped variables"}, "a": {"definition": "random(0.1..1#0.1)", "name": "a", "description": "", "templateType": "randrange", "group": "Ungrouped variables"}}, "variable_groups": [], "functions": {"createNetwork": {"definition": "// This function creates the board and sets it up, then returns an\n// HTML div tag containing the board.\n \n// The line is described by the equation \n// y = a*x + b\n\n// This function takes as its parameters the coefficients a and b,\n// and the coordinates (x2,y2) of a point on the line.\n\n// First, make the JSXGraph board.\n// The function provided by the JSXGraph extension wraps the board up in \n// a div tag so that it's easier to embed in the page.\nvar div = Numbas.extensions.jsxgraph.makeBoard('400px','266px',\n{boundingBox: [-3,2,3,-2],\n axis: false,\n showNavigation: false,\n // grid: true\n});\n\n// div.board is the object created by JSXGraph, which you use to \n// manipulate elements\n\nvar blueColor='#0000ff';\nvar grayColor='#9b9b9b';\n\nvar PointStyle={face:'o', size:5, fixed:true};\nvar LineStyle={straightFirst:false,straightLast:false,strokeWidth:5,dash:0,strokeColor:blueColor};\n\n//Setting .studentAnswer(0) prevents grading errors due to \n//undefined .studentAnswer\nquestion.parts[0].gaps[0].display.studentAnswer(0);\n\n//Create a function for changing the line styles based on state\nfunction changelinestyle(){\n// console.log(this);\n if(this.selected==true){\n this.selected=false;\n this.setAttribute({dash:1,strokeColor:grayColor});\n } else {\n this.selected=true ;\n this.setAttribute({dash:0,strokeColor:blueColor});\n }\n};\n\nvar board = div.board; \n\nvar PointDict={\"A\":0\n ,\"B\":1\n ,\"C\":2\n ,\"D\":3\n ,\"E\":4\n ,\"F\":5\n ,\"G\":6\n ,\"H\":7\n ,\"I\":8};\n\nvar PointInfoArray=[[[-2.0, 0.0],\"A\"]\n ,[[-1.0, 1.0],\"B\"]\n ,[[ 0.0, 0.0],\"C\"]\n ,[[ 1.0, 1.0],\"D\"]\n ,[[ 2.0, 0.0],\"E\"]\n ,[[ 1.0, .33],\"F\"]\n ,[[ 1.0,-.33],\"G\"]\n ,[[-1.0,-1.0],\"H\"]\n ,[[ 1.0,-1.0],\"I\"]];\n \nPointArray=[];\n\nfor (i=0;i