//highcharts中categories分组
//var t = [
//	['Project1', 'Phase 1', "haha1", "11"],
//	['Project1', 'Phase 2', "haha1", "22"],
//	['Project1', 'Phase 2', "haha2", "33"],
//	['Project1', 'Phase 3', "haha4", "33"],
//	['Project2', 'Phase 1', "haha2", "33"],
//	['Project2', 'Phase 1', "haha3", "33"]
//]
import { Highcharts } from "react-highcharts"
export default t => {
	if(t.length==0||t[0].length==0) return []
	var options = []
	if(t[0].length == 1) {
		jQuery.each(t, function(lineNo, line) {
			var items = line,
				itemsNum = items.length,
				hasThisCategory = false,
				categoryIndex = -1,
				categoryPath = options;
			Highcharts.each(categoryPath, function(category, i) {
				if(category.name === items[0]) {
					hasThisCategory = true;
					categoryIndex = i;
				}
			});
			if(!hasThisCategory) {
				categoryPath.push(items[items.length - 1]);
			}
			if(categoryIndex === -1) categoryIndex = categoryPath.length - 1;
			categoryPath = categoryPath[categoryIndex].categories;
		})
		return options
	}
	jQuery.each(t, function(lineNo, line) {
		var items = line,
			itemsNum = items.length,
			hasThisCategory = false,
			categoryIndex = -1,
			categoryPath = options;
		Highcharts.each(categoryPath, function(category, i) {
			if(category.name === items[0]) {
				hasThisCategory = true;
				categoryIndex = i;
			}
		});
		if(!hasThisCategory) {
			categoryPath.push({
				name: items[0],
				categories: []
			});
		}
		if(categoryIndex === -1) categoryIndex = categoryPath.length - 1;
		categoryPath = categoryPath[categoryIndex].categories;

		function a(t) {
			hasThisCategory = false;
			categoryIndex = -1;
			Highcharts.each(categoryPath, function(category, i) {
				if(category.name === items[t]) {
					hasThisCategory = true;
					categoryIndex = i;
				}
			});
			if(!hasThisCategory) {
				categoryPath.push({
					name: items[t],
					categories: []
				});
			}
			if(categoryIndex === -1) categoryIndex = categoryPath.length - 1;
			categoryPath = categoryPath[categoryIndex].categories;
		}
		if(items.length > 1) {
			for(let t = 1; t < items.length - 1; t++) {
				a(t)
			}
		}
		hasThisCategory = false;
		categoryIndex = -1;
		Highcharts.each(categoryPath, function(category, i) {
			if(category === items[items.length - 1]) {
				hasThisCategory = true;
			}
		});
		if(!hasThisCategory) {
			categoryPath.push(items[items.length - 1]);
		}
	});
	return options
}