Vanilla JS

Interactive Body Chart for Vanilla JS

Documentation for the pure JavaScript version, free version and Pro: add a clickable anatomy chart to any website by editing one config file.

This documentation covers the Interactive Body Chart Vanilla JS package, including the free version and Pro. For the WordPress plugin, see the WordPress docs.

This documentation covers both the free version (Body Chart JS) and Interactive Body Chart - Pro. Sections and options marked Pro are only in Pro, and notes marked Free describe how the free version differs. In the free version the download is body-chart.zip, the folder is body-chart-js, the global is BodyChart (instead of BodyChartPro), and class and event names start with ibca (instead of ibcap), for example ibca:click. It has the Male Front and Female Front layers, one-line text tooltips and links, any number of charts on a page, and shows a small "Body chart by Human Anatomy Illustrations" credit link under the chart. Pro is available at humananatomyillustrations.com.

Introduction

Free The free version has the Male Front and Female Front layers: every part is clickable, with a one-line tooltip, a link and its own colors, and a layer switcher, color theming, size and alignment, and several charts can share a page. Regions, pins, zoom, rich tooltips, popups (modal windows) and the other 6 layers are in Pro.

Interactive Body Chart - Pro (JS) gives any website a clickable anatomy chart. You describe the chart in one file, config.js, load three scripts, and the chart does the rest: tooltips, links, popups (modal windows), layer switching and zoom. It is plain JavaScript with no libraries, so it works in static HTML, React, Vue, a hospital CMS, or anywhere else you can add a script tag.

The package has eight layers of clean, non-explicit educational illustrations: Male Front, Male Back, Female Front, Female Back, Internal Organs, Muscular Front, Muscular Back and Skeleton. Each chart can offer any mix of them. On top of the layers you can define:

  • parts: the clickable areas of the body, each with its own tooltip, colors and click action
  • regions: groups of parts that light up and act together, such as "Left leg"
  • pins: markers placed anywhere on the artwork, with a built-in or custom icon
The demo page that comes with the package
The demo page (index.html) that comes with the package.

You can make as many charts as you like, each with its own layers: see Several charts.

Several charts

Free The free version has several charts too, with the Male Front and Female Front layers: for example Male Front on one page and Female Front on another, or both on the same page. The other 6 layers are in Pro.

You don't have to put everything in one chart. Make a separate chart for each use, give it only the layers it needs, and use each chart on its own. In the JavaScript version a chart is one config object, so each chart is a config with its own views. For example:

// Men's health page: male front and back
BodyChartPro.create('#male-chart', { views: ['male-front', 'male-back'] /* parts, colors... */ });

// Women's health page: female front and back
BodyChartPro.create('#female-chart', { views: ['female-front', 'female-back'] });

// Physiotherapy page: muscular front and back
BodyChartPro.create('#muscles-chart', { views: ['muscular-front', 'muscular-back'] });

// Orthopedics page: the skeleton alone
BodyChartPro.create('#skeleton-chart', { views: ['skeleton-front'] });

Every chart is independent: its own layers, parts, regions, pins, colors, tooltips, click actions and zoom. Each one can go on its own page, or several can share a page (see Several charts on one page). A simple way to keep them apart is one config file per chart, for example config-male.js and config-skeleton.js, each setting its own variable.

Three charts: Male Body Chart, Female Body Chart and Skeleton Only
You can create as many charts as you need. This example shows a male chart, a female chart, and a skeleton-only chart, each with its own layers.

Setup

Free The free download is body-chart.zip: Body Chart/JS Version/body-chart-js/ holds index.html, config.js and assets/, with the outlines of its 2 layers. The pin picker and the events panel are in Pro. In the code below, use BodyChart instead of BodyChartPro.

Unzip the download, body-chart-pro.zip. The JavaScript package is in the folder "JS Version" and the layout is:

Body Chart Pro/
└── JS Version/
    ├── body-chart-js-pro/       upload this folder to your site
    │   ├── index.html           demo page (open it to see the chart)
    │   ├── config.js            YOUR chart: layers, parts, regions, pins, colors
    │   └── assets/
    │       ├── css/body-chart.css          chart styles
    │       ├── js/body-chart.js            the engine (no dependencies)
    │       ├── js/body-chart-artwork.js    outlines of all 8 layers
    │       ├── artwork/*.webp              the illustrations
    │       ├── artwork/icons/*.webp        the round layer-switcher icons
    │       ├── img/pin-cross.svg           sample custom pin icon
    │       └── js|css/body-chart-tools.*   optional pin picker and events panel (demo page only)
    └── documentation/           this guide

You can open index.html straight from disk, or through any web server. To publish, upload the whole folder to any host, since there is no build step. Edit config.js and reload the page to see your changes.

Add a chart to your own page

<link rel="stylesheet" href="/body-chart/assets/css/body-chart.css">

<div id="body-chart"></div>

<script src="/body-chart/assets/js/body-chart-artwork.js"></script>
<script src="/body-chart/assets/js/body-chart.js"></script>
<script src="/body-chart/config.js"></script>
<script>
  BodyChartPro.create('#body-chart', window.BODY_CHART_CONFIG);
</script>

That is all. The layer switcher, tooltips, links, popups and zoom work with no further code. The illustrations are found next to the script (assets/artwork/). If you move them, pass { assetsUrl: '/images/body-chart/' } as the third argument of create().

Several charts on one page

Free The same works in the free version with BodyChart.create().

BodyChartPro.create('#chart-a', configA);
BodyChartPro.create('#chart-b', configB); // fully independent

You can also load a config from a JSON URL: BodyChartPro.load('#chart', '/charts/patient.json') returns a Promise for the chart.

Config reference

All keys are optional except views. These are the defaults:

KeyDefaultDescription
viewsfirst layerLayers to offer, in order: male-front, male-back, female-front, female-back, internal-front, muscular-front, muscular-back, skeleton-front.
defaultViewfirst of viewsLayer shown first.
viewLabels{}Custom layer names (tooltip of the icon, or the button text), for example { 'internal-front': 'Organs' }.
showSwitchertrueShow the layer switcher (hidden anyway when there is one layer).
switcherPosition'top''top' puts the layer switcher above the model image, 'bottom' puts it below. See Switcher position.
switcherStyle'icons''icons' shows a round picture per layer, with the layer name in a tooltip on hover or focus. 'text' shows buttons with the layer name. See Layer switcher.
tooltipstrueTurn all tooltips on or off.
mobileTap'tooltip-first'Or 'action-first'. See Tooltips.
maxWidth / maxHeight560 / 0Size limits in px (0 = no limit). They apply to the whole chart, layer switcher included: the width limits the whole chart, and the height limits the switcher and the illustration together. The chart is responsive below them.
lightImagesfalsetrue loads compressed, still transparent model images (assets/artwork/light/) so the chart loads faster. false loads the lossless images. See Lighter images.
align'center' (centered)'left', 'center' or 'right'.
themesee ThemingColors and font.
zoom Pro{ enabled: true, wheel: true, buttons: true, position: 'top-right' }See Zoom and pan. The maximum is always 1.5.
parts{}Settings per part, keyed 'layer/part-id'. See below.
regions Pro[]Groups of parts. See below.
pins Pro[]Markers. See below.

Part settings (parts['male-front/chest'])

KeyDescription
enabledfalse makes the part inert (no hover, no tooltip, no click).
tooltipHTML string (free version: one line of plain text). Leave it out for the name in capitals, or use '' for no tooltip.
action'none', 'link' or 'modal' (a popup, Pro).
url, newTabFor links.
modal, modalTitle, buttons ProFor popups (modal windows). modal is an HTML string: paragraphs, headings, bold, italic, underline, lists, images, links and video embeds all work. The popup shows only this content. modalTitle is optional: set it to show a title above the content. Without it there is no title, and the part name only labels the popup for screen readers. buttons is a list of { label, url, newTab }.
fill, fillOpacity, hover, activeColor overrides (hex) for this part.

Regions Pro

regions: [{
  id: 'leg-left', view: 'male-front', name: 'Left leg',
  parts: ['thigh-l', 'knee-l', 'leg-l', 'ankle-l'],
  hover: '#43a047', tooltip: '<strong>Left leg</strong>',
  action: 'link', url: 'https://example.com/legs', newTab: false
}]

Pins Pro

pins: [{
  id: 'p1', view: 'male-front', x: 56, y: 30,     // percent of the artwork
  name: 'Heart', icon: 'dot',                     // dot | plus | info | number | custom
  badge: '1',                                     // text for icon 'number'
  iconUrl: '',                                    // image for icon 'custom'
  size: 28, color: '#e53935',
  tooltip: '<strong>Heart</strong>', action: 'modal', modal: '<p>…</p>'
}]

Pins are positioned in percent of the artwork (x from the left, y from the top), so they stay in place at any size. The easiest way to find the right numbers is the pin picker.

Custom pin icons Pro

Built-in icons are dot, plus, info and number. For your own icon, use icon: 'custom' and point iconUrl at a PNG, JPG, WebP, GIF or SVG file. Square images of about 64×64 px look best. Icons are always shown in an <img> tag, so scripts inside an SVG never run.

{ id: 'clinic', view: 'female-front', x: 50, y: 42, name: 'Clinic',
  icon: 'custom', iconUrl: 'assets/img/pin-cross.svg', size: 30,
  tooltip: '<strong>Our clinic</strong>', action: 'link', url: 'https://example.com/clinic' },

Part IDs

Use these IDs in parts keys ('layer/id') and in region parts lists. The suffixes -r and -l mean the body's right and left. On front layers the body's right side is on the viewer's left, and on back layers it is on the viewer's right. The list is generated from the artwork that ships in the package.

Male Front (male-front, 33 parts)
head
eye-r
eye-l
nose
mouth
ear-r
ear-l
neck
chest
abdomen
pelvis
shoulder-r
shoulder-l
arm-r
arm-l
elbow-r
elbow-l
forearm-r
forearm-l
wrist-r
wrist-l
hand-r
hand-l
thigh-r
thigh-l
knee-r
knee-l
leg-r
leg-l
ankle-r
ankle-l
foot-r
foot-l
Male Back (male-back, 29 parts) Pro
head
neck
back
loin
buttocks
shoulder-r
shoulder-l
arm-r
arm-l
elbow-r
elbow-l
forearm-r
forearm-l
wrist-r
wrist-l
hand-r
hand-l
hamstring-r
hamstring-l
knee-r
knee-l
calf-r
calf-l
ankle-r
ankle-l
foot-r
foot-l
sole-r
sole-l
Female Front (female-front, 34 parts)
head
eye-r
eye-l
nose
mouth
ear-r
ear-l
neck
chest
breasts
abdomen
pelvis
shoulder-r
shoulder-l
arm-r
arm-l
elbow-r
elbow-l
forearm-r
forearm-l
wrist-r
wrist-l
hand-r
hand-l
thigh-r
thigh-l
knee-r
knee-l
leg-r
leg-l
ankle-r
ankle-l
foot-r
foot-l
Female Back (female-back, 29 parts) Pro
head
neck
back
loin
buttocks
shoulder-r
shoulder-l
arm-r
arm-l
elbow-r
elbow-l
forearm-r
forearm-l
wrist-r
wrist-l
hand-r
hand-l
hamstring-r
hamstring-l
knee-r
knee-l
calf-r
calf-l
ankle-r
ankle-l
foot-r
foot-l
sole-r
sole-l
Internal Organs (internal-front, 9 parts) Pro
heart
lungs
major-blood-vessels
stomach
spleen
liver
gallbladder
colon
intestine
Muscular Front (muscular-front, 45 parts) Pro
sternocleidomastoid-r
sternocleidomastoid-l
trapezius-r
trapezius-l
deltoid-r
deltoid-l
pectoralis-major-r
pectoralis-major-l
rectus-abdominis
serratus-anterior-r
serratus-anterior-l
abdominal-external-oblique-r
abdominal-external-oblique-l
biceps-brachii-r
biceps-brachii-l
brachioradialis-r
brachioradialis-l
flexor-carpi-radialis-r
flexor-carpi-radialis-l
palmaris-longus-r
palmaris-longus-l
gluteus-medius-r
gluteus-medius-l
vastus-lateralis-r
vastus-lateralis-l
rectus-femoris-r
rectus-femoris-l
sartorius-r
sartorius-l
pectineus-r
pectineus-l
adductor-longus-r
adductor-longus-l
vastus-medialis-r
vastus-medialis-l
gracilis-r
gracilis-l
gastrocnemius-r
gastrocnemius-l
soleus-r
soleus-l
tibialis-anterior-r
tibialis-anterior-l
peroneus-longus-r
peroneus-longus-l
Muscular Back (muscular-back, 33 parts) Pro
trapezius
infraspinatus-r
infraspinatus-l
teres-major-r
teres-major-l
teres-minor-r
teres-minor-l
latissimus-dorsi-r
latissimus-dorsi-l
deltoid-r
deltoid-l
triceps-brachii-r
triceps-brachii-l
extensor-carpi-ulnaris-r
extensor-carpi-ulnaris-l
flexor-carpi-ulnaris-r
flexor-carpi-ulnaris-l
gluteus-medius-r
gluteus-medius-l
gluteus-maximus-r
gluteus-maximus-l
vastus-lateralis-r
vastus-lateralis-l
biceps-femoris-r
biceps-femoris-l
semitendinosus-r
semitendinosus-l
semimembranosus-r
semimembranosus-l
adductor-magnus-r
adductor-magnus-l
gastrocnemius-r
gastrocnemius-l
Skeleton (skeleton-front, 28 parts) Pro
skull
spine
sacrum
pelvis
ribs
sternum
clavicle-r
clavicle-l
scapula-r
scapula-l
humerus-r
humerus-l
radius-r
radius-l
ulna-r
ulna-l
hand-r
hand-l
femur-r
femur-l
patella-r
patella-l
tibia-r
tibia-l
fibula-r
fibula-l
foot-r
foot-l

Theming

Set the colors under theme in config.js. The defaults give dark text on a white background for tooltips:

theme: {
  fill: '#1e6fd9', fillOpacity: 0,        // parts at rest (0 = invisible until hover)
  hover: '#1e6fd9', hoverOpacity: 0.4,    // on hover / focus
  active: '#0b4aa2', activeOpacity: 0.65, // the clicked part
  stroke: '#1e6fd9', strokeWidth: 1.5, outlines: false, // outline color, outline width
  tooltipBg: '#ffffff', tooltipText: '#1f2933',
  accent: '#1e6fd9', accentText: '#ffffff', // layer switcher
  regionHover: '#8e24aa', pinColor: '#e53935', pinText: '#ffffff',
  modalBg: '#ffffff', modalText: '#1f2933', overlay: '#0b1a2a', // popup (modal window)
  buttonBg: '#1e6fd9', buttonText: '#ffffff',
  background: '', font: ''                // '' = transparent / page font
}

Opacities are numbers from 0 (invisible) to 1 (solid). The chart also exposes CSS custom properties on .ibcap (for example --ibcap-accent), so your own stylesheet can override them.

Pin picker Pro

The pin picker works out pin positions for you. You click the chart where a pin should go, copy a ready-made snippet and paste it into config.js. It is off by default and your visitors never see it. To turn it on:

  • open the demo page with ?pinpicker=1 added to the address, for example index.html?pinpicker=1, or
  • set pinPicker: true in window.BODY_CHART_TOOLS at the top of config.js.

While it is on, the chart doesn't follow links or open popups, so you can click anywhere.

The pin picker with the Copy pin and Copy all pins buttons
The pin picker. New pins appear on the chart straight away.

Place and move pins

  • Click the artwork to place a new pin. It appears on the chart as a real pin, and its snippet is shown in the panel.
  • Drag any pin, new or existing, to move it. The snippet updates to the new position.
  • Positions are percent of the artwork, rounded to one decimal.

Copy pin: add one pin

"Copy pin" copies the pin you placed or moved last, as one object that ends with a comma:

{ id: 'pin-7', view: 'male-front', x: 51.4, y: 26.7, name: 'New pin', icon: 'dot', size: 28 },

Open config.js and paste it on a new line inside the pins list, right above the comment // NEW PINS GO ABOVE THIS LINE:

	"pins": [
		{
			"id": "p-info",
			...
		},
		{ id: 'pin-7', view: 'male-front', x: 51.4, y: 26.7, name: 'New pin', icon: 'dot', size: 28 },   // <-- paste here
		// NEW PINS GO ABOVE THIS LINE
	],

Because every copied pin ends with a comma, you can paste as many as you like, one after another, in any order. Save the file and reload the page. (Pasting before the first pin, in the middle of the list, or after the last pin all work too, for the same reason.)

Copy all pins: replace the whole list

"Copy all pins" copies the complete list with every pin as it is now, including pins you moved:

pins: [
	{ id: 'p-heart', view: 'male-front', x: 56, y: 30, name: 'Heart', icon: 'dot', size: 26, ... },
	{ id: 'p-info', view: 'male-front', x: 40, y: 58, name: 'Info pin', icon: 'info', ... },
	{ id: 'pin-7', view: 'male-front', x: 51.4, y: 26.7, name: 'New pin', icon: 'dot', size: 28 },
],

In config.js, the pins list sits between two comment lines. Select everything between them, keeping the two comment lines, and paste:

	// ===== PINS START =====
	"pins": [ ... ],            // <-- select from here ...
	// ===== PINS END =====      // ... to just above this line, and paste over it

Save the file and reload the page. Both ways give the same result, so use whichever you prefer: "Copy pin" while you add a few pins, "Copy all pins" when you have moved several or want to reorder the list.

The pin picker's snippets use the JavaScript object style (pins: [ and id: 'pin-7'), while the original list in config.js uses quoted keys ("pins": [). Both are valid JavaScript and can be mixed in the same file.

If the page shows an error after pasting

  • Open the browser console (F12). A message such as "Unexpected token" tells you the line of config.js that is wrong.
  • Check that every pin object ends with a comma and that nothing sits outside the pins list. Pasting "Copy pin" output below the closing ], or pasting "Copy all pins" inside the list (instead of over it) are the usual causes.

The pin picker is a helper for this package only. It is not part of the chart that visitors see.

Layer switcher

When a chart offers more than one layer, visitors get a layer switcher, above the illustration by default (see Switcher position). With switcherStyle: 'icons' (the default) it is a row of round icons, one per layer, each showing a small picture of that layer. The icons are fixed and match the artwork (they are in assets/artwork/icons/), so they can't be replaced per layer. Set switcherStyle: 'text' for pill-shaped buttons with the layer names instead.

  • Hover or keyboard focus on an icon shows the layer's name in a tooltip that looks exactly like the tooltip of a body part. Touch screens switch on tap without a tooltip.
  • The icon has a ring in theme.accent. On hover it lifts slightly and the ring and shadow get stronger. The active layer has a solid, thicker ring. Pressing an icon gives a short press effect, and keyboard focus shows a clear focus ring. Visitors who ask their system to reduce motion get no movement at all.
  • Each icon is a real button with the layer name as its accessible label (aria-label), and aria-pressed marks the active layer. Use Tab to move between icons and Enter or Space to choose.
  • The name comes from viewLabels if you set one for the layer, otherwise from the layer's default name.

The Skeleton layer has a front view only, so it has no back icon.

Round layer icons with the layer name in a tooltip
The icon switcher. The hovered icon shows its name in a tooltip.

Switcher position

Set switcherPosition: 'top' (the default) to show the switcher above the model image, or 'bottom' to show it below. The switcher is part of the chart, so the rest follows it: maxWidth and maxHeight cover the switcher and the image together, align aligns both, the zoom buttons stay in the corner of the image, and right-to-left pages mirror the row. With the switcher below the image, the layer name tooltip opens upward so it is never cut off.

BodyChartPro.create('#chart', { views: ['male-front', 'male-back'], switcherPosition: 'bottom' });
Layer switcher below the model image
switcherPosition: 'bottom': the switcher below the image, with its tooltip opening upward.

Lighter images

By default the chart shows the model images at full quality: lossless WebP with a transparent background, in assets/artwork/. Set lightImages: true to use the compressed copies in assets/artwork/light/ instead. They are still transparent, about 4 to 5 times smaller (for example Male Front about 100 KB instead of 435 KB), and load faster, with a small loss of fine detail. The browser only downloads the set you chose.

BodyChartPro.create('#chart', { views: ['male-front', 'male-back'], lightImages: true });

Layer loading

The chart shows its first layer as soon as that image has loaded, then loads the other layers listed in views in the background, so switching layers is instant, even before a visitor points at a layer icon. Layers that are not in views are never downloaded. If a visitor switches to a layer before it has finished loading, a small blurred preview of that layer, built into body-chart-artwork.js (no extra file), shows at once and fades into the full image as soon as it arrives. This works the same with or without lightImages, and nothing is loaded from other sites. No setting is needed.

Tooltips

Free In the free version a tooltip is one line of plain text, shown as text (never as HTML). Formatting, colors, lists and images in tooltips are in Pro.

  • Mouse: the tooltip follows the pointer, 12 px to the right and 22 px below it. Near the right edge it flips to the left, and near the bottom of the window it moves above the pointer. It never leaves the chart box.
  • Keyboard: tab to a part and the tooltip appears centered above it, or below it if there isn't room.
  • Phones and tablets (the default is mobileTap: 'tooltip-first'): the first tap shows the tooltip and the second tap opens the link or popup (modal window). A part with no link or popup just shows its tooltip. Tapping elsewhere or scrolling closes it. Set mobileTap: 'action-first' to skip the tooltip on touch.
  • The tooltip closes as soon as you click.

By default a tooltip has dark text on a white background (theme.tooltipBg and theme.tooltipText). If you leave a tooltip out, it shows the name in capitals (for example HEAD). You can write rich HTML (bold, links, lists, images; an image aligned left or right sits next to the text), or use '' for no tooltip.

Default tooltip
The default tooltip: dark text on white.

Zoom and pan Pro

Zoom is on by default. Turn it off with zoom: { enabled: false }. The other options are:

  • wheel: the mouse wheel zooms in and out at the pointer (default true).
  • buttons: show reset, + and − buttons (default true), placed at position: 'top-right' (the default) or 'bottom-right'.

The maximum zoom is 1.5 times and it isn't configurable, so the artwork stays sharp. One click on + goes straight to 1.5. A zoom button that would do nothing is inactive (dimmed, not clickable, and marked aria-disabled for screen readers): + at 1.5, and − and reset while the chart is at normal size. Further wheel turns and pinches do nothing more either, and the buttons switch back as soon as they are useful again. Visitors can also pinch on touch screens and drag to pan once zoomed in. The mouse pointer is a grab hand only while a pan drag is happening. Switching layers always resets the zoom.

Zoom buttons at normal size
At normal size, − and reset are inactive.
Zoom buttons at maximum zoom
At maximum zoom, + is inactive.

Links and popups (modal windows)

Free The free version has links. Popups (modal windows) are in Pro.

Every part, region and pin can do one of three things when clicked:

ActionConfigResult
Nothingaction: 'none'The item shows its active color. The tooltip still works.
Linkaction: 'link', url: '…', newTab: trueOpens the URL in the same tab or a new tab.
Popup (modal window)action: 'modal', modal: '<p>…</p>', buttons: [{label, url, newTab}]Opens an accessible popup that shows only your modal HTML (text, lists, images, links or a video embed), plus optional buttons. There is no automatic title: add modalTitle or a heading in the HTML if you want one. It closes with Esc, the × button or a click outside.

No JavaScript is needed for links and popups. They work from the config alone. Switching layers gives a fresh view: the selection, tooltip, popup and zoom are all cleared. The mouse pointer is a normal arrow over empty areas and a pointer (hand) over parts and pins.

Events (optional)

Free Events work the same in the free version, with the ibca: prefix: ibca:click, ibca:hover and ibca:viewchange. Zoom and popup (modal window) events, and the events panel of the demo page, are in Pro.

You don't need events. If you only want a body part to open a page or a popup (modal window), set action: 'link' or action: 'modal' and you're done. Events are for developers who want the chart to drive their own code, such as loading data into a side panel, filtering a list or sending analytics.

Every chart sends standard DOM CustomEvents from its container element. They bubble up, so you can also listen on document. event.detail.chart is always the chart instance.

Eventevent.detailWhen
ibcap:click{ chart, type, key, data, view }A part, region or pin is clicked. type is 'part', 'region' or 'pin', and key is its id. It can be canceled: event.preventDefault() stops the built-in link or popup.
ibcap:hover{ chart, type, key, data }The pointer (or the first tap) enters an item.
ibcap:viewchange{ chart, view }The visitor switches layers.
ibcap:zoom{ chart, scale }The zoom level changes.
ibcap:modalopen / ibcap:modalclose{ chart, data } / { chart }A popup opens or closes.
document.getElementById('body-chart').addEventListener('ibcap:click', function (e) {
  console.log(e.detail.type, e.detail.key, 'on', e.detail.view); // "part chest on male-front"
});

The demo page has an events panel that logs these events live. It is hidden unless you open index.html?debug=1 or set debug: true in window.BODY_CHART_TOOLS. It only shows what happens, and links and popups don't depend on it.

The events panel

Example: a hospital CMS

Say a hospital website lists departments and a patient portal shows visit notes. There are three ways to connect the chart, from no code at all to fully custom.

1. No code: links

Give each part a link to the right department page, for example chest → /departments/cardiology and head → /departments/neurology, with action: 'link'. Patients click the body and land on the department. No events are involved.

2. No code: popups

Use action: 'modal' with a short description and a button such as "Book an appointment". This also works without any JavaScript.

3. With events: fill your own panel

Leave the parts on action: 'none' (or cancel the built-in action) and let your CMS show content next to the chart:

<div id="body-chart"></div>
<aside id="dept-panel">Click a body area to see our departments.</aside>

<script>
  var chart = BodyChartPro.create('#body-chart', window.BODY_CHART_CONFIG);
  var panel = document.getElementById('dept-panel');

  chart.el.addEventListener('ibcap:click', function (e) {
    e.preventDefault(); // we handle it ourselves (skip the link/popup set in config)
    var area = e.detail.view + '/' + e.detail.key; // e.g. "male-front/chest"
    panel.textContent = 'Loading…';
    fetch('/api/departments?body_area=' + encodeURIComponent(area))
      .then(function (r) { return r.json(); })
      .then(function (list) {
        panel.innerHTML = '';
        list.forEach(function (d) {
          var a = document.createElement('a');
          a.href = d.url; a.textContent = d.name;   // textContent = safe from HTML injection
          panel.appendChild(a);
        });
      });
  });

  // Fresh panel when the visitor switches layers (the chart already clears itself).
  chart.el.addEventListener('ibcap:viewchange', function () {
    panel.textContent = 'Click a body area to see our departments.';
  });
</script>

JavaScript methods

Free In the free version the global is window.BodyChart. The zoom and popup (modal window) methods are in Pro.

The global is window.BodyChartPro.

MethodDescription
BodyChartPro.create(el, config, options)Builds a chart in an element or selector and returns the instance. Options: assetsUrl, i18n.
BodyChartPro.load(el, url, options)Same, with the config loaded from a JSON URL (returns a Promise).
BodyChartPro.get(el)Gets the instance of an existing chart.
BodyChartPro.instancesAll charts on the page.
chart.setView(id) / chart.getView()Switches or reads the layer. Switching always clears the selection, tooltip, popup and zoom.
chart.update(config)Replaces the config and redraws.
chart.zoomIn(), zoomOut(), resetZoom()Zoom control (maximum 1.5).
chart.openModal({ modal, buttons, modalTitle }), chart.closeModal()Opens your own popup (modal window) or closes the current one.
chart.clearActive()Clears the selected item and the tooltip.
chart.destroy()Removes the chart.

Translations: pass i18n: { views, zoomIn, zoomOut, zoomReset, close, pin } in the options to relabel the buttons.

Security notes

  • Link URLs that start with javascript:, vbscript: or data: are ignored by the engine.
  • Custom pin icons are shown in an <img> tag, so scripts inside an SVG never run.
  • The config is your own code, so tooltip and popup HTML is used as you wrote it. If you build a config from user input, escape that input first.

Updating from an earlier version

Version 3.3.6 comes with new artwork for all eight layers. The JavaScript package does not convert old configs, so check your config.js:

  • Use the new IDs from Part IDs. An ID that no longer exists is ignored without an error. The renamed or merged parts are: Male Back head-back, neck-back, upper-back, lower-back, gluteal, upper-arm-r/l, knee-back-r/l and heel-r/l are now head, neck, back, loin, buttocks, arm-r/l, knee-r/l and foot-r/l. Internal Organs small-intestine and large-intestine are intestine and colon. The small hand and foot bones of the Skeleton layer are now one hand-r/l and one foot-r/l part.
  • Pins keep their x and y in percent of the picture, so with the new models they can sit in a different place. Use the pin picker to place them again.
  • New options: switcherPosition ('top' or 'bottom'), and zoom.enabled is now true by default. Add zoom: { enabled: false } if you want zoom off.
  • The Female Front chest now covers the full chest, and breasts always sits on top of it (like the eyes on the head), so both stay clickable.
  • The Part IDs list each layer in a fixed anatomical order, from head to foot. The drawing order is separate (in paint in the artwork file), so smaller parts always stay on top and clickable.
  • Replace the whole assets folder, not only some files, so the scripts and the artwork match.

Coming from the free version

Replace the body-chart-js folder with body-chart-js-pro and keep your config.js: it works as it is. In your own code, use BodyChartPro instead of BodyChart, and ibcap instead of ibca in class and event names (for example ibcap:click). Pro reads tooltips as HTML, so a tooltip that contains < or & should be written as &lt; or &amp;.

FAQ

I updated the package but the page still looks like the old version.

Your browser has cached the old files. Reload with Ctrl+Shift+R (Cmd+Shift+R on a Mac). The demo page loads its files with a version in the address (?v=__VERSION__); do the same in your own page and change the number on each update, for example body-chart.js?v=__VERSION__.

The page is blank or shows an error after I edited config.js.

Open the browser console (F12) and read the first error. It names the line with the problem. A missing comma between two pins is the most common cause. Every pin object must end with a comma.

The pin picker doesn't show up.

Open the demo page as index.html?pinpicker=1, or set pinPicker: true in config.js. Make sure you are on the demo page that comes with the package, because the picker panel is part of it.

Can I show several charts on one page?

Yes. Call BodyChartPro.create() once per chart. Each one is independent.

Can I zoom further than 1.5 times?

No. The illustrations are raster images, and 1.5 times is the most they can be enlarged while staying sharp. The limit is fixed.

Do I need the events panel for links or popups?

No. Links and popups work from the config alone. The events panel is a developer tool that is hidden by default.

Does it need jQuery or any other library?

No. It is plain JavaScript with no dependencies.

Can I use it with React or Vue?

Yes. Load the scripts once, then call BodyChartPro.create() on an element after it is mounted, and chart.destroy() when it is removed.

Interactive Body Chart - Pro 3.3.6 · JavaScript version · humananatomyillustrations.com