Last active
April 27, 2022 09:46
Revisions
-
curran revised this gist
Feb 9, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ <!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://unpkg.com/d3@4.10.0/build/d3.js"></script> <script src="https://unpkg.com/d3-component@3.0"></script> <script src="https://unpkg.com/redux@3/dist/redux.min.js"></script> <script src="https://unpkg.com/d3-tip@0.7.1"></script> <link rel="stylesheet" href="https://unpkg.com/bootstrap@4.0.0-alpha.6/dist/css/bootstrap.min.css"> -
curran revised this gist
Sep 23, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ This example demonstrates usage of a new library called [d3-component](https://github.com/curran/d3-component) and [Redux](http://redux.js.org/) to create a scatter plot with menus for X, Y, and color, and some animations. It's an experiment to see how things play out when pairing D3 directly with Redux, without React in the middle. The data shown here comes from the [UCI Machine Learning Repository: Auto MPG Data Set](https://archive.ics.uci.edu/ml/datasets/auto+mpg). Built with [blockbuilder.org](http://blockbuilder.org) forked from <a href='http://bl.ocks.org/curran/'>curran</a>'s block: <a href='http://bl.ocks.org/curran/685fa8300650c4324d571c6b0ecc55de'>Spinner with d3-component</a> -
curran revised this gist
Mar 25, 2017 . 1 changed file with 39 additions and 40 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ <head> <meta charset="utf-8"> <script src="https://unpkg.com/d3@4"></script> <script src="https://unpkg.com/d3-component@3"></script> <script src="https://unpkg.com/redux@3/dist/redux.min.js"></script> <script src="https://unpkg.com/d3-tip@0.7.1"></script> <link rel="stylesheet" href="https://unpkg.com/bootstrap@4.0.0-alpha.6/dist/css/bootstrap.min.css"> @@ -32,7 +32,7 @@ // This stateless component renders a static "wheel" made of circles, // and rotates it depending on the value of props.angle. var wheel = d3.component("g") .create(function (selection){ var minRadius = 4, maxRadius = 10, numDots = 10, @@ -45,32 +45,32 @@ angle = d3.scaleLinear() .domain([0, numDots]) .range([0, Math.PI * 2]); selection .selectAll("circle").data(d3.range(numDots)) .enter().append("circle") .attr("cx", function (d){ return Math.sin(angle(d)) * wheelRadius; }) .attr("cy", function (d){ return Math.cos(angle(d)) * wheelRadius; }) .attr("r", radius); }) .render(function (selection, d){ selection.attr("transform", "rotate(" + d + ")"); }); // This component with a local timer makes the wheel spin. var spinner = (function (){ var timer = d3.local(); return d3.component("g") .create(function (selection, d){ timer.set(selection.node(), d3.timer(function (elapsed){ selection.call(wheel, elapsed * d.speed); })); }) .render(function (selection, d){ selection.attr("transform", "translate(" + d.x + "," + d.y + ")"); }) .destroy(function(selection, d){ timer.get(selection.node()).stop(); return selection .attr("fill-opacity", 1) .transition().duration(3000) .attr("transform", "translate(" + d.x + "," + d.y + ") scale(10)") @@ -81,24 +81,24 @@ var axis = (function (){ var axisLocal = d3.local(); return d3.component("g") .create(function (selection, d){ axisLocal.set(selection.node(), d3["axis" + d.type]()); selection .attr("opacity", 0) .call(axisLocal.get(selection.node()) .scale(d.scale) .ticks(d.ticks || 10)) .transition("opacity").duration(2000) .attr("opacity", 0.8); }) .render(function (selection, d){ selection .attr("transform", "translate(" + [ d.translateX || 0, d.translateY || 0 ] + ")") .transition("ticks").duration(3000) .call(axisLocal.get(selection.node())); }); }()); @@ -110,7 +110,7 @@ .range(d3.schemeCategory10); function render(selection, d){ var x = d.x, y = d.y, color = d.color, @@ -127,7 +127,7 @@ colorScale .domain(d3.extent(d.data, function (d){ return d[color]; })); selection .attr("transform", "translate(" + margin.left + "," + margin.top + ")") .call(axis, [ { @@ -143,7 +143,7 @@ } ]) var circles = selection.selectAll(".point").data(d.data); circles.exit().remove(); circles .enter().append("circle") @@ -197,8 +197,8 @@ // either displays a spinner or text, // depending on the value of the `loading` state. var svg = d3.component("svg") .render(function (selection, d){ var svgSelection = selection .attr("width", d.width) .attr("height", d.height) .call(spinner, !d.loading ? [] : { @@ -212,18 +212,18 @@ }); var label = d3.component("label", "col-sm-2 col-form-label") .render(function (selection, d){ selection.text(d); }); var option = d3.component("option") .render(function (selection, d){ selection.text(d); }); var select = d3.component("select", "form-control") .render(function (selection, d){ selection .call(option, d.columns) .property("value", d.value) .on("change", function (){ @@ -234,17 +234,16 @@ var rowComponent = d3.component("div", "row"); var colSm10 = d3.component("div", "col-sm-10"); var menu = d3.component("div", "col-sm-4") .render(function (selection, d){ var row = rowComponent(selection).call(label, d.label); colSm10(row).call(select, d); }); var menus = d3.component("div", "container-fluid") .create(function (selection){ selection.style("opacity", 0); }) .render(function (selection, d){ rowComponent(selection).call(menu, [ { label: "X", @@ -272,8 +271,8 @@ }); var app = d3.component("div") .render(function (selection, d){ selection.call(menus, d).call(svg, d); }); function loadData(actions){ -
curran revised this gist
Mar 14, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ <head> <meta charset="utf-8"> <script src="https://unpkg.com/d3@4"></script> <script src="https://unpkg.com/d3-component@2.2"></script> <script src="https://unpkg.com/redux@3/dist/redux.min.js"></script> <script src="https://unpkg.com/d3-tip@0.7.1"></script> <link rel="stylesheet" href="https://unpkg.com/bootstrap@4.0.0-alpha.6/dist/css/bootstrap.min.css"> -
curran revised this gist
Mar 10, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ This example demonstrates usage of a new library called [d3-component](https://github.com/curran/d3-component) and [Redux](http://redux.js.org/) to create a scatter plot with menus for X, Y, and color, and some animations. It's an experiment to see how things play out when pairing D3 directly with Redux, without React in the middle. Built with [blockbuilder.org](http://blockbuilder.org) -
curran revised this gist
Mar 10, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ This example demonstrates usage of [d3-component](https://github.com/curran/d3-component) and [Redux](http://redux.js.org/) to create a scatter plot with menus for X, Y, and color, and some animations. It's an experiment to see how things play out when pairing D3 directly with Redux, without React in the middle. Built with [blockbuilder.org](http://blockbuilder.org) -
curran revised this gist
Mar 10, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ This example demonstrates usage of [d3-component](https://github.com/curran/d3-component) and [Redux](http://redux.js.org/) to create a scatter plot with menus for X, Y, and color, and some animations. Built with [blockbuilder.org](http://blockbuilder.org) -
Building blocks revised this gist
Mar 10, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
curran revised this gist
Mar 10, 2017 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -124,6 +124,8 @@ yScale .domain(d3.extent(d.data, function (d){ return d[y]; })) .range([innerHeight, 0]); colorScale .domain(d3.extent(d.data, function (d){ return d[color]; })); d3.select(this) .attr("transform", "translate(" + margin.left + "," + margin.top + ")") @@ -287,7 +289,6 @@ ordinalColumns = [ "cylinders", "origin", "year" ]; @@ -311,9 +312,9 @@ height: 500 - 38, loading: true, margin: {top: 12, right: 12, bottom: 40, left: 50}, x: "acceleration", y: "horsepower", color: "cylinders" }; switch (action.type) { case "INGEST_DATA": -
curran revised this gist
Mar 10, 2017 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,2 @@ license: mit border: no -
curran revised this gist
Mar 10, 2017 . No changes.There are no files selected for viewing
-
curran revised this gist
Mar 10, 2017 . No changes.There are no files selected for viewing
-
curran revised this gist
Mar 10, 2017 . 1 changed file with 28 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -238,28 +238,35 @@ }); var menus = d3.component("div", "container-fluid") .create(function (){ d3.select(this).style("opacity", 0); }) .render(function (d){ var selection = d3.select(this); rowComponent(selection).call(menu, [ { label: "X", value: d.x, action: d.setX, columns: d.numericColumns }, { label: "Y", value: d.y, action: d.setY, columns: d.numericColumns }, { label: "Color", value: d.color, action: d.setColor, columns: d.ordinalColumns } ], d); if(!d.loading && selection.style("opacity") === "0"){ selection.transition().duration(2000) .style("opacity", 1); } }); var app = d3.component("div") -
curran revised this gist
Mar 10, 2017 . 1 changed file with 3 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -352,11 +352,9 @@ function main(){ var store = Redux.createStore(reducer), actions = actionsFromDispatch(store.dispatch); renderApp = function(){ d3.select("body").call(app, store.getState(), actions); } renderApp(); store.subscribe(renderApp); loadData(actions); -
curran revised this gist
Mar 10, 2017 . 1 changed file with 17 additions and 28 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -268,23 +268,21 @@ }); function loadData(actions){ var numericColumns = [ "acceleration", "cylinders", "displacement", "horsepower", "weight", "year", "mpg" ], ordinalColumns = [ "cylinders", "origin", "name", "year" ]; setTimeout(function (){ // Show off the spinner for a few seconds ;) d3.csv("auto-mpg.csv", type, function (data){ @@ -340,22 +338,13 @@ }); }, setX: function (column){ dispatch({ type: "SET_X", column: column }); }, setY: function (column){ dispatch({ type: "SET_Y", column: column }); }, setColor: function (column){ dispatch({ type: "SET_COLOR", column: column }); } }; } -
curran revised this gist
Mar 10, 2017 . 1 changed file with 59 additions and 65 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -301,81 +301,75 @@ } function reducer (state, action){ var state = state || { width: 960, height: 500 - 38, loading: true, margin: {top: 12, right: 12, bottom: 40, left: 50}, x: "displacement", y: "horsepower", color: "origin" }; switch (action.type) { case "INGEST_DATA": return Object.assign({}, state, { loading: false, data: action.data, numericColumns: action.numericColumns, ordinalColumns: action.ordinalColumns }); case "SET_X": return Object.assign({}, state, { x: action.column }); case "SET_Y": return Object.assign({}, state, { y: action.column }); case "SET_COLOR": return Object.assign({}, state, { color: action.column }); default: return state; } } function actionsFromDispatch(dispatch){ return { ingestData: function (data, numericColumns, ordinalColumns){ dispatch({ type: "INGEST_DATA", data: data, numericColumns: numericColumns, ordinalColumns: ordinalColumns }); }, setX: function (column){ dispatch({ type: "SET_X", column: column }); }, setY: function (column){ dispatch({ type: "SET_Y", column: column }); }, setColor: function (column){ dispatch({ type: "SET_COLOR", column: column }); } }; } function main(){ var store = Redux.createStore(reducer), actions = actionsFromDispatch(store.dispatch); function renderApp(){ d3.select("body").call(app, store.getState(), actions); } renderApp(); store.subscribe(renderApp); loadData(actions); } main(); -
curran revised this gist
Mar 10, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -174,7 +174,7 @@ // Wish we could use D3 here for DOM manipulation.. tip.html(function(d) { return [ "<h4>" + d.year + " " + d.name + "</h4>", "<div><strong>" + state.x + ": </strong>", "<span>" + d[state.x] + "</span></div>", "<div><strong>" + state.y + ": </strong>", -
curran revised this gist
Mar 10, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -147,8 +147,8 @@ .enter().append("circle") .attr("class", "point") .attr("r", 0) .attr("cx", d.width / 2 - margin.left) .attr("cy", d.height / 2 - margin.top) .merge(circles) .on("mouseover", d.show) .on("mouseout", d.hide) -
curran revised this gist
Mar 10, 2017 . 1 changed file with 21 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -221,7 +221,6 @@ var select = d3.component("select", "form-control") .render(function (d){ d3.select(this) .call(option, d.columns) .property("value", d.value) @@ -240,27 +239,27 @@ var menus = d3.component("div", "container-fluid") .render(function (d){ rowComponent(d3.select(this)) .call(menu, [ { label: "X", value: d.x, action: d.setX, columns: d.numericColumns }, { label: "Y", value: d.y, action: d.setY, columns: d.numericColumns }, { label: "Color", value: d.color, action: d.setColor, columns: d.ordinalColumns } ], d); }); var app = d3.component("div") -
curran revised this gist
Mar 10, 2017 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -240,8 +240,7 @@ var menus = d3.component("div", "container-fluid") .render(function (d){ var row = rowComponent(d3.select(this)); row.call(menu, [ { label: "X", -
curran revised this gist
Mar 10, 2017 . 1 changed file with 4 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -231,16 +231,11 @@ }); var rowComponent = d3.component("div", "row"); var colSm10 = d3.component("div", "col-sm-10"); var menu = d3.component("div", "col-sm-4") .render(function (d){ var row = rowComponent(d3.select(this)).call(label, d.label); colSm10(row).call(select, d); }); var menus = d3.component("div", "container-fluid") @@ -271,10 +266,7 @@ var app = d3.component("div") .render(function (d){ d3.select(this).call(menus, d).call(svg, d); }); function loadData(actions){ -
curran revised this gist
Mar 10, 2017 . 1 changed file with 4 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ <head> <meta charset="utf-8"> <script src="https://unpkg.com/d3@4"></script> <script src="https://unpkg.com/d3-component@2.1"></script> <script src="https://unpkg.com/redux@3/dist/redux.min.js"></script> <script src="https://unpkg.com/d3-tip@0.7.1"></script> <link rel="stylesheet" href="https://unpkg.com/bootstrap@4.0.0-alpha.6/dist/css/bootstrap.min.css"> @@ -164,6 +164,7 @@ .render(render); }()); // Leverage the d3-tip library for tooltips. var tooltip = (function (){ var tip = d3.tip() .attr("class", "d3-tip") @@ -181,9 +182,7 @@ "<div><strong>" + state.color + ": </strong>", "<span>" + d[state.color] + "</span></div>" ].join(""); }); svgSelection.call(tip); return { show: tip.show, @@ -231,13 +230,11 @@ }) }); var rowComponent = d3.component("div", "row"); var menu = d3.component("div", "col-sm-4") .render(function (d){ var row = rowComponent(d3.select(this)); row.call(label, d.label) var col = row.selectAll("div").data([1]); -
Building blocks revised this gist
Mar 10, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
curran revised this gist
Mar 10, 2017 . No changes.There are no files selected for viewing
-
curran revised this gist
Mar 10, 2017 . 1 changed file with 8 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -170,10 +170,16 @@ .offset([-10, 0]); return function (svgSelection, state){ // Wish we could use D3 here for DOM manipulation.. tip.html(function(d) { return [ "<h3>" + d.year + " " + d.name + "</h3>", "<div><strong>" + state.x + ": </strong>", "<span>" + d[state.x] + "</span></div>", "<div><strong>" + state.y + ": </strong>", "<span>" + d[state.y] + "</span></div>", "<div><strong>" + state.color + ": </strong>", "<span>" + d[state.color] + "</span></div>" ].join(""); //"<strong>Frequency:</strong> <span style='color:red'>" + d.frequency + "</span>"; }); -
curran revised this gist
Mar 10, 2017 . 1 changed file with 21 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,6 +12,17 @@ stroke: currentColor; fill-opacity: 0.3; } /* Tooltip styles copied from http://bl.ocks.org/Caged/6476579 */ .d3-tip { line-height: 1; padding: 12px; background: rgba(0, 0, 0, 0.8); color: #fff; border-radius: 2px; } </style> </head> <body> @@ -156,11 +167,17 @@ var tooltip = (function (){ var tip = d3.tip() .attr("class", "d3-tip") .offset([-10, 0]); return function (svgSelection, state){ tip.html(function(d) { return [ "<strong>" + state.x + ":</strong>", "<span>" + d[state.x] + "</span>" ].join(""); //"<strong>Frequency:</strong> <span style='color:red'>" + d.frequency + "</span>"; }); svgSelection.call(tip); return { show: tip.show, -
curran revised this gist
Mar 10, 2017 . 1 changed file with 27 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ <script src="https://unpkg.com/d3@4"></script> <script src="https://unpkg.com/d3-component@2"></script> <script src="https://unpkg.com/redux@3/dist/redux.min.js"></script> <script src="https://unpkg.com/d3-tip@0.7.1"></script> <link rel="stylesheet" href="https://unpkg.com/bootstrap@4.0.0-alpha.6/dist/css/bootstrap.min.css"> <style> .point { @@ -77,7 +78,7 @@ .scale(d.scale) .ticks(d.ticks || 10)) .transition("opacity").duration(2000) .attr("opacity", 0.8); }) .render(function (d){ d3.select(this) @@ -96,6 +97,8 @@ yScale = d3.scaleLinear(), colorScale = d3.scaleOrdinal() .range(d3.schemeCategory10); function render(d){ var x = d.x, y = d.y, @@ -136,6 +139,8 @@ .attr("cx", innerWidth / 2) .attr("cy", innerHeight / 2) .merge(circles) .on("mouseover", d.show) .on("mouseout", d.hide) .transition() .duration(2000) .delay(function (d, i){ return i * 5; }) @@ -148,20 +153,38 @@ .render(render); }()); var tooltip = (function (){ var tip = d3.tip() .attr("class", "d3-tip") .offset([-10, 0]) .html(function(d) { return "<strong>Frequency:</strong> <span style='color:red'>" + d.frequency + "</span>"; }); return function (svgSelection, d){ svgSelection.call(tip); return { show: tip.show, hide: tip.hide }; } }()); // This component manages an svg element, and // either displays a spinner or text, // depending on the value of the `loading` state. var svg = d3.component("svg") .render(function (d){ var svgSelection = d3.select(this) .attr("width", d.width) .attr("height", d.height) .call(spinner, !d.loading ? [] : { x: d.width / 2, y: d.height / 2, speed: 0.2 }); var tipCallbacks = tooltip(svgSelection, d); svgSelection .call(scatterPlot, d.loading ? [] : d, tipCallbacks); }); var label = d3.component("label", "col-sm-2 col-form-label") -
curran revised this gist
Mar 10, 2017 . No changes.There are no files selected for viewing
-
curran revised this gist
Mar 10, 2017 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,8 +7,9 @@ <link rel="stylesheet" href="https://unpkg.com/bootstrap@4.0.0-alpha.6/dist/css/bootstrap.min.css"> <style> .point { fill: currentColor; stroke: currentColor; fill-opacity: 0.3; } </style> </head> @@ -141,7 +142,7 @@ .attr("r", 10) .attr("cx", function (d){ return xScale(d[x]); }) .attr("cy", function (d){ return yScale(d[y]); }) .attr("color", function (d){ return colorScale(d[color]); }) } return d3.component("g") .render(render); -
curran revised this gist
Mar 10, 2017 . 1 changed file with 57 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ <link rel="stylesheet" href="https://unpkg.com/bootstrap@4.0.0-alpha.6/dist/css/bootstrap.min.css"> <style> .point { fill-opacity: 0.2; stroke: black; } </style> @@ -92,10 +92,13 @@ // This component displays the visualization. var scatterPlot = (function (){ var xScale = d3.scaleLinear(), yScale = d3.scaleLinear(), colorScale = d3.scaleOrdinal() .range(d3.schemeCategory10); function render(d){ var x = d.x, y = d.y, color = d.color, margin = d.margin, innerWidth = d.width - margin.left - margin.right, innerHeight = d.height - margin.top - margin.bottom; @@ -137,7 +140,8 @@ .delay(function (d, i){ return i * 5; }) .attr("r", 10) .attr("cx", function (d){ return xScale(d[x]); }) .attr("cy", function (d){ return yScale(d[y]); }) .attr("fill", function (d){ return colorScale(d[color]); }) } return d3.component("g") .render(render); @@ -171,6 +175,7 @@ var select = d3.component("select", "form-control") .render(function (d){ //console.log(d.columns) d3.select(this) .call(option, d.columns) .property("value", d.value) @@ -179,7 +184,9 @@ }) }); var row = d3.component("div", "row"); var menu = d3.component("div", "col-sm-4") .render(function (d){ var row = d3.select(this).selectAll("div").data([1]); row = row.merge(row.enter().append("div") @@ -198,26 +205,36 @@ row = row.merge(row.enter().append("div").attr("class", "row")); row.call(menu, [ { label: "X", value: d.x, action: d.setX, columns: d.numericColumns }, { label: "Y", value: d.y, action: d.setY, columns: d.numericColumns }, { label: "Color", value: d.color, action: d.setColor, columns: d.ordinalColumns } ], d); }); var app = d3.component("div") .render(function (d){ console.log(d); d3.select(this) .call(menus, d) .call(svg, d); }); function loadData(actions){ var numericColumns = [ "acceleration", "cylinders", @@ -227,9 +244,17 @@ "year", "mpg" ]; var ordinalColumns = [ "cylinders", "origin", "name", "year" ]; setTimeout(function (){ // Show off the spinner for a few seconds ;) d3.csv("auto-mpg.csv", type, function (data){ actions.ingestData(data, numericColumns, ordinalColumns) }); }, 2000); @@ -249,14 +274,15 @@ margin: {top: 12, right: 12, bottom: 40, left: 50}, x: "displacement", y: "horsepower", color: "origin" }; switch (action.type) { case "INGEST_DATA": return Object.assign({}, state, { loading: false, data: action.data, numericColumns: action.numericColumns, ordinalColumns: action.ordinalColumns }); case "SET_X": return Object.assign({}, state, { @@ -266,19 +292,25 @@ return Object.assign({}, state, { y: action.column }); case "SET_COLOR": return Object.assign({}, state, { color: action.column }); default: return state; } } function main(){ var store = Redux.createStore(reducer), actions = { ingestData: function (data, numericColumns, ordinalColumns){ store.dispatch({ type: "INGEST_DATA", data: data, numericColumns: numericColumns, ordinalColumns: ordinalColumns }); }, setX: function (column){ @@ -292,20 +324,25 @@ type: "SET_Y", column: column }); }, setColor: function (column){ store.dispatch({ type: "SET_COLOR", column: column }); } }; function renderApp(){ d3.select("body") .call(app, store.getState(), actions); } renderApp(); store.subscribe(renderApp); loadData(actions); } main(); </script>
NewerOlder