Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
feat(graph): remove dep
Browse files Browse the repository at this point in the history
removes dependency on immutable and adds title prop support for tooltip
  • Loading branch information
eddier committed Mar 21, 2017
1 parent 73a689a commit b06a1c1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"glob": "^7.1.1",
"gulp": "^3.9.1",
"html-loader": "^0.4.4",
"immutable": "^3.8.1",
"javascript-natural-sort": "^0.7.1",
"jest": "^19.0.2",
"nsp": "^2.6.2",
Expand Down
1 change: 1 addition & 0 deletions src/components/charts/BarChart/BarChart.examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Standard Area AreaChart
xDataType='date'
showIcon
showXLabel
tooltipTitle='OPERATIONS'
/>
</div>

Expand Down
17 changes: 9 additions & 8 deletions src/components/charts/BarChart/BarChart.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import React, { PropTypes } from 'react'
import Rect from './Rect'
import ToolTip from './BarChartTooltip'

import * as ChartUtils from '../Chart/utils'
import Immutable from 'immutable'
var d3 = Object.assign({}, require('d3-time-format'), require('d3-axis'))

const { array, number, object, string, bool } = PropTypes

class BarChart extends React.Component {
constructor (props) {
super(props)
this.state = {
tooltip: {
display: false,
color: null,
title: '',
data: { key: '', value: '' },
pos: { x: '', y: '' }
}
Expand All @@ -28,6 +25,7 @@ class BarChart extends React.Component {
tooltip: {
display: true,
color: e.target.getAttribute('fill'),
title: this.props.tooltipTitle,
data: {
key: e.target.getAttribute('data-key'),
value: e.target.getAttribute('data-value')
Expand Down Expand Up @@ -55,8 +53,9 @@ class BarChart extends React.Component {
const innerHeight = height - (margin.top + margin.bottom)
const transform = `translate(-${margin.left}, ${margin.top})`
let xScale = null
const data = Immutable.fromJS(this.props.data).toJS()
const xScaleTimeLineData = Immutable.fromJS(this.props.data).toJS()
const data = JSON.parse(JSON.stringify(this.props.data))
const xScaleTimeLineData = JSON.parse(JSON.stringify(this.props.data))

if (this.props.xDataType === 'date') {
const parseDate = d3.timeParse('%m-%d-%Y %H:%M:%S')
data.forEach((d) => {
Expand Down Expand Up @@ -108,7 +107,8 @@ BarChart.propTypes = {
width: number,
xDataType: string,
showXLabel: bool,
showIcon: bool
showIcon: bool,
tooltipTitle: string
}

BarChart.defaultProps = {
Expand All @@ -119,7 +119,8 @@ BarChart.defaultProps = {
width: 200,
xDataType: 'month',
showXLabel: false,
showIcon: false
showIcon: false,
tooltipTitle: ''
}

export default BarChart
2 changes: 1 addition & 1 deletion src/components/charts/BarChart/BarChartTooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const ToolTip = (props) => {
transform={transformLine}
/>
<text is visibility={visibility} transform={transformText} >
<tspan is x='0' y='10' text-anchor='left' font-size='12px' fill='#657d8e'>{`OPERATIONS (${props.tooltip.data.value})`}</tspan>
<tspan is x='0' y='10' text-anchor='left' font-size='12px' fill='#657d8e'>{`${props.tooltip.title} (${props.tooltip.data.value})`}</tspan>
<tspan is x='0' y='20' text-anchor='left' dy='12px' font-size='12px' fill='#657d8e'>{props.tooltip.data.key}</tspan>
</text>

Expand Down
4 changes: 0 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4380,10 +4380,6 @@ image-size@~0.5.0:
version "0.5.1"
resolved "https://registry.yarnpkg.com/image-size/-/image-size-0.5.1.tgz#28eea8548a4b1443480ddddc1e083ae54652439f"

immutable@^3.8.1:
version "3.8.1"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-3.8.1.tgz#200807f11ab0f72710ea485542de088075f68cd2"

import-regex@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/import-regex/-/import-regex-1.1.0.tgz#a55c52e4c705c765ca210e9242a06bbcc8aa7f66"
Expand Down

0 comments on commit b06a1c1

Please sign in to comment.