Keefe Reuther
  • About
    • Keefe Reuther
    • Contact Us
  • Teaching
  • Scholarship
    • Publications
    • Presentations
    • Projects
  • GenAI
    • Tools & Resources
    • Community
  • Blog

Table of contents

  • Simple Interactive Circle
    • That’s it!
Skip to main content

A simple D3 interactive example

OJS
D3
Example
This is a minimal example of an OJS D3 webapp with one input and one output.
Author

Keefe Reuther

Published

April 16, 2025


Simple Interactive Circle

Use the slider below to control the size of the circle.

d3 = require("d3@7");

// Single Input: Slider for circle radius
viewof circleRadius = Inputs.range([10, 100], {label: "Circle Radius", value: 30, step: 1});

// Single Output: An SVG circle whose radius is determined by the slider
svgCircle = {
  const width = 220;
  const height = 220;
  const margin = {top: 10, right: 10, bottom: 10, left: 10};
  
  const svgNode = d3.create("svg")
    .attr("width", width)
    .attr("height", height)
    .attr("viewBox", [0, 0, width, height]);

  // Clear previous circle if any (important for reactivity)
  svgNode.selectAll("circle").remove();

  // Draw the circle
  svgNode.append("circle")
    .attr("cx", width / 2)
    .attr("cy", height / 2)
    .attr("r", circleRadius) // Use the value from the slider
    .attr("fill", "steelblue");

  return svgNode.node(); // Return the SVG node for display
};

// Optional: Display the current radius value as text
radiusValue = `Current Radius: **${circleRadius}**`;

That’s it!

Reuse

CC BY 4.0

Citation

BibTeX citation:
@online{reuther2025,
  author = {Reuther, Keefe},
  title = {A Simple {D3} Interactive Example},
  date = {2025-04-16},
  url = {https://keefereuther.com/docs/blog/posts/OJStest/},
  langid = {en}
}
For attribution, please cite this work as:
Reuther, Keefe. 2025. “A Simple D3 Interactive Example.” April 16, 2025. https://keefereuther.com/docs/blog/posts/OJStest/.

UCSD Bio UCSD EBE UCSD

 
  • This site combines my original content with GAI-aided portions from tools like ChatGPT. All content is curated and verified by me, Keefe Reuther.
  • License