Skip to content

Commit

Permalink
Resolve images against atlasUrl iff the result from require is not ab…
Browse files Browse the repository at this point in the history
…solute
  • Loading branch information
alfonsomunozpomer committed Oct 10, 2017
1 parent 900563b commit 857bb72
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/AnatomogramSvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ const initialiseSvgElements = (getSvgElementById, {idsWithMarkup, onMouseOver,on
}

const loadSvg = (species, selectedView) => require(`./svg/${species}${selectedView ? `.${selectedView}` : ``}.svg`)
const resolve = (uri, baseUrl) => URI(uri).is(`absolute`) ? URI(uri) : URI(uri, baseUrl)

// ReactSVG loads the SVG file asynchronously (hence the callback prop). We don’t use componentDidUpdate or
// componentDidMount because they can’t guarantee that the SVG is already loaded when they’re run. If
// componentDidMount because they can’t guarantee that the SVG is already loaded when they’re run.
const AnatomogramSvg = (props) =>
<div className={`gxa-anatomogram-svg-wrapper`}>
<ReactSVG
path={URI(loadSvg(props.species, props.selectedView), props.atlasUrl)}
path={resolve(loadSvg(props.species, props.selectedView), props.atlasUrl).toString()}
callback={svgDomNode => { initialiseSvgElements(getSvgElementById(svgDomNode), props) }}
className={`gxa-anatomogram-svg`}
style={{paddingLeft: props.selectedView ? `10px` : ``}} />
Expand Down
3 changes: 2 additions & 1 deletion src/Switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import {getAnatomogramViews} from './Assets'
import './Switcher.css'

const loadIcon = (view, selectedView) => require(`./img/${view}.${view === selectedView ? `` : `un`}selected.png`)
const resolve = (uri, baseUrl) => URI(uri).is(`absolute`) ? URI(uri) : URI(uri, baseUrl)

const Switcher = ({atlasUrl, species, selectedView, onChangeView}) =>
<div className={`gxa-anatomogram-switcher`}>
{getAnatomogramViews(species).map((view) =>
<img key={view} className={`gxa-anatomogram-switcher-icon`} onClick={() => onChangeView(view)}
src={URI(loadIcon(view, selectedView), atlasUrl).toString()} />
src={resolve(loadIcon(view, selectedView), atlasUrl).toString()} />
)}
</div>

Expand Down

0 comments on commit 857bb72

Please sign in to comment.