Skip to main content
100%

Signal Plot III (zoom)

✓ Published0🌍 Public
KKelvinZCH
Last edited Jun 9, 2017
Created on Jun 9, 2017

This interactive line chart visualizes accelerometer readings across x, y, and z axes, with a focus on zooming and panning along the time axis. The chart, rendered as SVG with D3 v4, plots data from a CSV file and extends an earlier version by adding d3.zoom functionality for granular inspection while preserving line highlighting and tooltip interactions. Users can zoom up to 50x, with the transformation rescaling the x-domain and redrawing paths and axes in real time.

AI-generated description

Signal Plot III

Line chart that displays three dimensions of data taken from an accelerometer. This example is designed to implement zooming, while still maintaining the highlighting and tooltips from <a href='http://bl.ocks.org/lwthatcher/1ecdd35bdf2c96630bf98112ec0344a1'>Signal Plot II</a>.

Zooming

The chart uses d3.zoom to implement zooming and panning for the x-axis. Adding the zoom can be done with relatively few steps:

Create the Zoom Behavior:

  // setup zoom
  var zoom = d3.zoom()
      .scaleExtent([1, 50])
      .translateExtent([[0, 0], [width, height]])
      .extent([[0, 0], [width, height]])
      .on("zoom", zoomed);

The callback function zoomed will also need to be defined. Below shows the callback for rescaling only in the x dimension, as well as redrawing the x-axis:

  function zoomed() {
    var t = d3.event.transform;
    x.domain(t.rescaleX(x0).domain());
    dims.forEach(dim => {
      var selector = ".line--" + dim;
      svg.select(selector)
        .attr("d", lines[dim]);
    });
    svg.select(".axis--x").call(d3.axisBottom(x));
  }

Note how the x0 scale is also needed for a point of reference: var x0 = d3.scaleLinear().range([0, width]); ... x0.domain(x.domain());

Create the Zoom Portal:

  // create zoom portal in background
  var rect = svg.append("rect")
      .attr("class", "zoom")
      .attr("width", width)
      .attr("height", height)
      .attr("transform", "translate(" + margin.left + "," + margin.top + ")")
      .call(zoom); 

Note: Make sure that this section goes after the zoom behavior definition, but before drawing any of the lines or axes. This will position the zoom portal in the back, allowing the highlighting and tooltip events to still propagate.

Add the Clip-Path:

// Create clip-path
svg.append("defs").append("clipPath")
    .attr("id", "clip")
   .append("rect")
    .attr("width", width)
    .attr("height", height);

Styling:

Make sure that zoom portal accepts pointer-events, and that the lines use the clip-path.

.zoom {
  fill: none;
  cursor: move;
  pointer-events: all;
}

.line {
  fill: none;
  opacity: 0.9;
  stroke-width: 1.5px;
  clip-path: url(#clip);
}

Set initial zoom/position: (optional)

This little snippet sets the initial zoom to x2 and sets the position to the start of the data:

  // Set initial zoom/position
  zoom.scaleBy(rect, 2);
  zoom.translateBy(rect, width);

Note: The order matters here: scale then translate.

Highlighting:

Highlighting follows a pattern inspired by <a href='http://bl.ocks.org/lwthatcher/'>lwthatcher</a>'s block: <a href='http://bl.ocks.org/lwthatcher/a6c886b1081857a7198807617f183283'>Multi y-axis with mouseover</a>, where when a line is moused-over the line is highlighted, while other lines are dimmed.

Tooltips:

The tooltips are implemented based off of <a href='http://bl.ocks.org/d3noob/'>d3noob</a>'s block: <a href='http://bl.ocks.org/d3noob/257c360b3650b9f0a52dd8257d7a2d73'>Simple tooltips in v4</a>, with some additional css styling changes.

Built with blockbuilder.org

forked from <a href='http://bl.ocks.org/lwthatcher/'>lwthatcher</a>'s block: <a href='http://bl.ocks.org/lwthatcher/94c246de1032f09b32742edfc30c54b1'>Signal Plot I</a>

forked from <a href='http://bl.ocks.org/lwthatcher/'>lwthatcher</a>'s block: <a href='http://bl.ocks.org/lwthatcher/1ecdd35bdf2c96630bf98112ec0344a1'>Signal Plot II (highlighting + tooltips)</a>

forked from <a href='http://bl.ocks.org/lwthatcher/'>lwthatcher</a>'s block: <a href='http://bl.ocks.org/lwthatcher/d6eb019c470bf3c9ca6df94213a111a0'>Signal Plot III (zoom)</a>

mit Licensed

Similar vizzes

Loading thumbnail…

Signal Plot III (zoom)

This line chart displays three dimensions of accelerometer data (x, y, z) over time, rendered as separate colored lines. The visualization adds zooming and panning to the existing highlighting and tooltip interactions from earlier versions. Using d3.zoom, users can scale the x-axis between 1x and 50x and pan across the data; the zoom behavior is implemented via a background rectangle that captures pointer events while lines are clipped to the plot area. As the view changes, only the x-domain is rescaled, with the y-scale and line paths updated accordingly. The chart also retains mouseover highlighting (dimming non-hovered lines) and tooltips, with lines clipped to maintain visual clarity. An initial zoom and pan position can be set programmatically, as shown in the code, where the viewport starts at a 2x zoom translated to the start of the data. The example includes CSS for the zoom portal (pointer-events: all) and line clip-path.# Signal Plot III (zoom) ## Interactive Multi-Dimensional Accelerometer Line Chart This visualization presents accelerometer data across three dimensions (x, y, z) in a multi-line chart, building on its predecessors by adding interactive zooming and panning capabilities while preserving the highlighting and tooltip features. **Key Features:** **Zoom & Pan:** The chart implements d3.zoom for x-axis zooming and panning. The zoom behavior is configured with scale extent of 1-50x and translation constraints, with a transparent SVG rect serving as the zoom portal. A clip-path ensures lines don't extend outside the plotting area during zoom. **Highlighting & Tooltips:** When hovering over a line, it is highlighted while other lines are dimmed. Tooltips display exact values. **Implementation Details:** - Uses d3.zoom with `scaleExtent([1, 50])` for zoom limits - The zoom callback updates the x-domain and redraws lines and x-axis - A background rect captures zoom events while allowing pointer-events to propagate to line elements - Initial view is set to 2x zoom positioned at the start of the data - Data from accelerometer readings across three dimensions (x, y, z axes) This example builds upon prior Signal Plot iterations, adding zoom and pan to the x-axis while preserving the highlight and tooltip features from earlier versions.# Signal Plot III (zoom) ## Overview This interactive line chart visualizes three dimensions of accelerometer data using SVG and D3 v4. Building upon Signal Plot II's highlighting and tooltip features, this example demonstrates how to add zoom and pan functionality to a multi-series line chart. ## Key Features **Zoom & Pan**: The visualization implements a sophisticated zoom behavior using d3.zoom, allowing users to explore the x-axis data with a scale range of 1x to 50x. The zoom is constrained to the x-dimension only, preserving the integrity of the y-axis values while enabling detailed temporal exploration. The implementation includes: - A dedicated zoom behavior with scale and translate extents - A zoom portal (transparent rect) positioned behind the data elements - A clip-path to properly contain the lines during zoom operations - Optional initial zoom/position setup **Interactive Highlighting**: When hovering over a line, it is highlighted while other lines are dimmed, making it easy to distinguish between the three accelerometer dimensions (x, y, z). **Tooltips**: Contextual tooltips display precise values for each data point on hover. ### Data Context The visualization displays accelerometer data from three axes (x, y, z) plotted against a tick axis. The example includes a CSV dataset with multiple samples of accelerometer readings. ### Visual Design The chart uses a multi-line chart layout with three lines representing the x, y, and z dimensions of the accelerometer data. The chart includes a legend to distinguish the three data series. The zoom functionality allows users to focus on specific ranges of the data while maintaining the ability to pan and zoom out to see the overall signal. ### Embedding Use this line of code to embed this block in your own page: ``` html <iframe src="https://blockbuilder.org/63anp3ca/0960cb0eb2bf91b7bde16820ef08dba9" width="100%" height="300" frameborder="0"></iframe> ``` <p>If you modify the visualization, keep the blockbuilder link to retain forking credit. Do not forget to add you own changes. If you make a contribution, <a href="https://github.com/rross/blockbuilder">make a request</a>. Use the <a href="http://blockbuilder.org/63anp3ca/0960cb0eb2bf91b7bde16820ef08dba9">this block</a> as a template.</p> <h3>Overview</h3> <table> <tbody> <tr><td>gist</td><td><a href="https://gist.github.com/63anp3ca/0c1255d1db27089b8dc35fcfb4b76c4b">Signal Plot III (zoom)</a></td></tr> <tr><td>block</td><td><a href="http://bl.ocks.org/63anp3ca/0c1255d1db27089b8dc35fcfb4b76c4b">Signal Plot III (zoom)</a></td></tr> <tr><td>source</td><td>gist</td></tr> <tr><td>author</td><td><a href="http://bl.ocks.org/63anp3ca">63anp3ca</a></td></tr> <tr><td>d3</td><td>d3.v4</td></tr> <tr><td>framework</td><td>d3</td></tr> <tr><td>rendering</td><td>svg, animation</td></tr> <tr><td>license</td><td>mit</td></tr> ``` </div> ### Files 1. signalplot3.html 2. accel-data.csv ### Data Data contains readings from an accelerometer. ### JS The JavaScript file (index.js) can be found <a href='https://bl.ocks.org/raw/94c246de1032f09b32742edfc30c54b1/87e70fad6f8e01186390454ac1e2c2c5b02de0d5/index.js'>here</a>. ### About this visualization : This is a line chart that shows accelerometer data, with three dimensions. It is designed as an improvement to show panning and zooming along with the highlighting and tooltips. Since the sample data is accelerometer data, the data dimensions are named x, y, and z, and the independent variable is time in the tick column. --- Your task: Write a 90- to 140-word description of this block. Include - a little bit of background on the data - and how the visualization represents it. - the main design elements and interactions. Aim for concise, engaging, and precise description. Use complete sentences, no Markdown. Also: mention how the user can interact with the visualization and can see the data. Make the description suitable for the gallery. When you are done, print the file with the tag <DESCRIPTION_FILE> and put the description in the tag. The final output should be only the description file content - no more, no less. i.e. no leading or enclosing text, emphasis, headers, or whatever. Just the file contents. Use the 3rd person. All text must be in English. The description must be about the visualization, not about the underlying data or the code that makes the visualization. Do not describe the data. Do not mention the code. Do not mention the source of the data. Think step by step. Start by reading the files. Do not assume anything not in the provided files. Do not repeat any code from the provided files. At the end of the description, list 3 short titles that would be good suitable titles for this example. The titles should be clear, catchy, and function as the title of the visualization in the gallery. Write the description to a file named description.txt in the same directory as this file. Only output the final description. Do not output code blocks or markdown formatting.This line chart visualizes three axes of accelerometer data—x, y, and z—over time, with interactive pan and zoom controls for exploring the signal. Built with D3 v4, it builds on prior versions by adding zoom functionality while retaining the highlighting and tooltips from its predecessor. Users can click and drag to pan, use the mouse wheel to zoom in and out, and hover over lines to see detailed values. The zoom is implemented using d3.zoom with a background portal and a clip-path to constrain drawing. Interactivity is enhanced with hover-based line highlighting that dims non-hovered lines and displays tooltips for precise data inspection. --- Signal Plot III (zoom) Interactive line chart with zoom/pan for accelerometer data, with hover highlighting and tooltips.

663anp3ca
82% match