Skip to content

Commit

Permalink
Merge branch 'master' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
nekronhuang committed Mar 10, 2017
2 parents 152d864 + 1acd91d commit 9ba1931
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 18 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"node": true,
"mocha": true
},
"parser": "babel-eslint",
"extends": [
"eslint-config-airbnb"
],
Expand Down
10 changes: 10 additions & 0 deletions lib/chart/indicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ class Indicator extends NonEcharts {
});
}
});
const tmpArr = [];
measures.forEach(key => {
mersuresArray.forEach((item, index) => {
if (key === item.name) {
tmpArr.push(item);
mersuresArray.splice(index, 1);
}
});
});
mersuresArray = tmpArr.concat(mersuresArray);
li = (
<li key={index} className={`d2indicator-item ${extraClassname}`}>
<div className={firstClassName}>
Expand Down
3 changes: 1 addition & 2 deletions lib/chart/option-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class OptionGenerator {
data: coordinates,
}, extraOption.category);

console.log('extraOption.yAxis', extraOption.yAxis);
if (extraOption.yAxis) {
option[measuresAxis] = extraOption.yAxis;
} else {
Expand All @@ -64,7 +63,7 @@ class OptionGenerator {
}
});
});
_.merge(option.xAxis, this._configXLabel(coordinates, option.grid.bottom));
_.merge(option.xAxis, this._configXLabel());
_.merge(option[measuresAxis][0], {
name: option['data-yAxisName'] || ''
});
Expand Down
5 changes: 5 additions & 0 deletions lib/chart/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ const rechartsWithDataAndCoordinates = _.extend({
measures: React.PropTypes.array,
}, rechartsWithData);

const rechartsWithDataAndSuggest = _.extend({
suggest: React.PropTypes.func
}, rechartsWithData);

const propTypes = {
recharts,
rechartsWithData,
rechartsWithDataAndCoordinates,
rechartsWithDataAndSuggest
};

util.propTypes = propTypes;
Expand Down
30 changes: 29 additions & 1 deletion lib/chart/smart.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ const Text = require('./text');
const rules = [];

class Smart extends React.Component {
componentDidMount() {
this.props.suggest({
candidates: this.candidateChartTypes,
current: this.currentChartType
});
}

componentDidUpdate() {
this.props.suggest({
candidates: this.candidateChartTypes,
current: this.currentChartType
});
}

currentChartType = '';
candidateChartTypes = [];

suggestChart(dataSet, props) {
return this.constructor.suggestChart(dataSet, props);
}
Expand All @@ -29,7 +46,15 @@ class Smart extends React.Component {
]);
const dataSet = DataSet.try2init(data);
const dimensionAndMeasures = util.props2DimensionAndMeasures(props, dataSet);

const ChartComponent = Smart.suggestChart(dataSet, dimensionAndMeasures);
const currentChartType = ChartComponent.name;

const allSuggestChartTypes = _.map(Smart.suggestAllCharts(dataSet, dimensionAndMeasures), Chart => Chart.name);
_.remove(allSuggestChartTypes, currentChartType);
this.candidateChartTypes = allSuggestChartTypes;
this.currentChartType = currentChartType;

return (
<ChartComponent data={dataSet} {...extraOption}/>
);
Expand Down Expand Up @@ -85,7 +110,10 @@ _.extend(Smart, {
},
});

Smart.propTypes = propTypes.rechartsWithData;
Smart.propTypes = propTypes.rechartsWithDataAndSuggest;
Smart.defaultProps = {
suggest: () => {}
};

// register default rules
require('../rule/default')(Smart);
Expand Down
28 changes: 14 additions & 14 deletions lib/theme/warm-color.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@

{
"color": [
"#8fd3e8",
"#c0f0a2",
"#fcc978",
"#fa8072",
"#7d6951",
"#ffd621",
"#73bb4e",
"#a0d772",
"#60a8a4",
"#4682b4",
"#6495ed",
"#475569"
"#f46e65",
"#faaf76",
"#7ec2f3",
"#3dbd7d",
"#76cdd3",
"#a7e1c4",
"#f79992",
"#f78e3d",
"#3db8c1",
"#fa90ba",
"#49a9ee",
"#b3acf2"
],
"backgroundColor": "rgba(0, 0, 0, 0)",
"textStyle": {},
Expand All @@ -35,8 +35,8 @@
"width": 2
}
},
"symbolSize": 4,
"symbol": "image://",
"symbolSize": 6,
"symbol": "circle",
"smooth": false
},
"radar": {
Expand Down
8 changes: 8 additions & 0 deletions lib/util/guess-items-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,13 @@ module.exports = (arr) => {
typeWithMaxFreq = type;
}
});

// if types of items are all string, check if numeric numeric like
if (_.keys(itemsTypesMap).length === 1
&& typeWithMaxFreq === 'string'
&& _.every(arr, item => !isNaN(parseFloat(item, 10)))) {
typeWithMaxFreq = 'number';
}

return typeWithMaxFreq;
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d2recharts",
"version": "0.3.22",
"version": "0.3.25",
"description": "data driven react components of echarts",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -46,10 +46,12 @@
"devDependencies": {
"babel-cli": "~6.14.0",
"babel-core": "~6.14.0",
"babel-eslint": "^7.1.1",
"babel-loader": "~6.2.5",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "~6.14.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.22.0",
"babel-preset-stage-2": "^6.18.0",
"chai": "~3.5.0",
"commander": "~2.9.0",
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
presets: [
'es2015',
'react',
'stage-0',
]
}
},
Expand Down

0 comments on commit 9ba1931

Please sign in to comment.