Pen Settings



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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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


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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.


                <div id="wrapper" class="wrapper">

  <div id="tooltip" class="tooltip">
      <div class="tooltip-date">
          <span id="date"></span>
      <div class="tooltip-humidity">
          Humidity: <span id="humidity"></span>
      <div class="tooltip-dew-point">
          Dew Point: <span id="dew-point"></span>



                .wrapper {
    position: relative;

.x-axis-label {
    fill: black;
    font-size: 1.4em;
    text-transform: capitalize;

.y-axis-label {
    fill: black;
    font-size: 1.4em;
    text-anchor: middle;
    transform: rotate(-90deg);

circle {
    fill: cornflowerblue;

.voronoi {
    fill: transparent;

body {
    display: flex;
    justify-content: center;
    padding: 3em 1em;
    font-family: sans-serif;

.tooltip {
    opacity: 0;
    position: absolute;
    top: -14px;
    left: 0;
    padding: 0.6em 1em;
    background: #fff;
    text-align: center;
    line-height: 1.4em;
    font-size: 0.9em;
    border: 1px solid #ddd;
    z-index: 10;
    transition: all 0.1s ease-out;
    pointer-events: none;

.tooltip:before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 12px;
    height: 12px;
    background: white;
    border: 1px solid #ddd;
    border-top-color: transparent;
    border-left-color: transparent;
    transform: translate(-50%, 50%) rotate(45deg);
    transform-origin: center center;
    z-index: 10;

.tooltip-date {
    margin-bottom: 0.2em;
    font-weight: 600;
    font-size: 1.1em;
    line-height: 1.4em;


                async function drawScatter() {
  // 1. Access data

  const dataset = await d3.json("");

  const xAccessor = d => d.dewPoint;
  const yAccessor = d => d.humidity;

  // 2. Create chart dimensions

  const width = d3.min([window.innerWidth * 0.9, window.innerHeight * 0.9]);
  let dimensions = {
    width: width,
    height: width,
    margin: {
      top: 10,
      right: 10,
      bottom: 50,
      left: 50
  dimensions.boundedWidth =
    dimensions.width - dimensions.margin.left - dimensions.margin.right;
  dimensions.boundedHeight =
    dimensions.height - - dimensions.margin.bottom;

  // 3. Draw canvas

  const wrapper = d3
    .attr("width", dimensions.width)
    .attr("height", dimensions.height);

  const bounds = wrapper
      `translate(${dimensions.margin.left}px, ${}px)`

  // 4. Create scales

  const xScale = d3
    .domain(d3.extent(dataset, xAccessor))
    .range([0, dimensions.boundedWidth])

  const yScale = d3
    .domain(d3.extent(dataset, yAccessor))
    .range([dimensions.boundedHeight, 0])

  const drawDots = dataset => {
    // 5. Draw data

    const dots = bounds.selectAll("circle").data(dataset, d => d[0]);

    const newDots = dots.enter().append("circle");

    const allDots = newDots
      .attr("cx", d => xScale(xAccessor(d)))
      .attr("cy", d => yScale(yAccessor(d)))
      .attr("r", 4);

    const oldDots = dots.exit().remove();

  // 6. Draw peripherals

  const xAxisGenerator = d3.axisBottom().scale(xScale);

  const xAxis = bounds
    .style("transform", `translateY(${dimensions.boundedHeight}px)`);

  const xAxisLabel = xAxis
    .attr("class", "x-axis-label")
    .attr("x", dimensions.boundedWidth / 2)
    .attr("y", dimensions.margin.bottom - 10)
    .html("dew point (&deg;F)");

  const yAxisGenerator = d3

  const yAxis = bounds.append("g").call(yAxisGenerator);

  const yAxisLabel = yAxis
    .attr("class", "y-axis-label")
    .attr("x", -dimensions.boundedHeight / 2)
    .attr("y", -dimensions.margin.left + 10)
    .text("relative humidity");

  const delaunay = d3.Delaunay.from(
    d => xScale(xAccessor(d)),
    d => yScale(yAccessor(d))

  const voronoi = delaunay.voronoi();
  voronoi.xmax = dimensions.boundedWidth;
  voronoi.ymax = dimensions.boundedHeight;

    .attr("class", "voronoi")
    .attr("d", (d, i) => voronoi.renderCell(i))
    .on("mouseenter", onMouseEnter)
    .on("mouseleave", onMouseLeave);

  // 7. Set up interactions

    .on("mouseenter", onMouseEnter)
    .on("mouseleave", onMouseLeave);

  const tooltip ="#tooltip");

  function onMouseEnter(datum, index) {
    const dayDot = bounds
      .attr("class", "tooltipDot")
      .attr("cx", xScale(xAccessor(datum)))
      .attr("cy", yScale(yAccessor(datum)))
      .attr("r", 7)
      .style("fill", "maroon")
      .style("pointer-events", "none");

    const formatHumidity = d3.format(".2f");"#humidity").text(formatHumidity(yAccessor(datum)));

    const formatDewPoint = d3.format(".2f");"#dew-point").text(formatDewPoint(xAccessor(datum)));

    const dateParser = d3.timeParse("%Y-%m-%d");
    const formatDate = d3.timeFormat("%B %A %-d, %Y");"#date").text(formatDate(dateParser(;

    const x = xScale(xAccessor(datum)) + dimensions.margin.left;
    const y = yScale(yAccessor(datum)) +;
      `translate(` + `calc( -50% + ${x}px),` + `calc(-100% + ${y}px)` + `)`
    );"opacity", 1);

  function onMouseLeave() {"opacity", 0);