1.0.4 • Published 5 years ago

react-taipei-metro v1.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

react-taipei-metro

Extensible React Component for Taipei Metro Map.

See the demo here.

Install

npm install react-taipei-metro

Example

import React from 'react';
import ReactDOM from 'react-dom';
import MetroMap from 'react-taipei-metro';

class Window extends React.Component {
  // Customized overlay when mouse hovers over the station.
  renderOverlay(station) {
    // Return a Promise if you fetch data with asynchronous methods.
    return new Promise((resolve) => {
      setTimeout(() => resolve((<span>{station.name.en}</span>)), 500);
    });
    // Or simply return a jsx.
    // return (<span>{userData.foo.bar}</span>);
  }

  // You can also render customized svg elements for each station.
  renderCustomizedContent(station, i, scale) {
    return (<text key={i} x={station.center.x} y={station.center.y}
        fontSize={10 * scale} fill={this.textColor}
        alignmentBaseline='middle' textAnchor='middle'>{station.name.en.length}</text>);
  }

  // See Props for more details.
  render() {
    return (<MetroMap
      width={800} height={900}
      showStationName={true} showOverlay={true}
      renderOverlay={station => this.renderOverlay(station)}
      renderUserData={(station, i, scale) => this.renderCustomizedContent(station, i, scale)} />);
  }
}

ReactDOM.render(
  <Window />,
  document.getElementById('root')
);

Props

NameDescriptionTypeRequiredDefault
widthWidth of component(px)numberx800
heightHeight of component (px)numberx900
bgColorBackground color of componentstringxwhite
textStyleStyle of svg text elementobjectx{ fill: 'black' }
showTextWhether to show station nameboolxtrue
showOverlayWhether to show station overlayboolxtrue
showUserDataWhether to show user databoolxtrue
renderOverlayFunction for rendering overlay when mouse hovers a stationfunc: station => Promise or JSXx-
renderUserDataFunction(s) for rendering user content for each stationfunc: (station, i, scale) => JSX or array<func: (station, i, scale)>x-

Function arguments

  • station
{
  name: { en: 'Yuanshan', zh: '圓山' },
  center: { x: 365, y: 373 },
  lines: ['R']
}
  • i: station index
  • scale: min(props.width / 800, props.height / 900)

Build

npm run build
1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago