Subversion Repositories SmartDukaan

Rev

Rev 28468 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
28468 tejbeer 1
package com.spice.profitmandi.service;
2
 
3
import java.time.LocalDate;
4
import java.time.LocalDateTime;
5
import java.time.format.DateTimeFormatter;
6
import java.util.ArrayList;
7
import java.util.LinkedHashSet;
8
import java.util.List;
9
import java.util.Map;
10
import java.util.Map.Entry;
11
 
12
import org.springframework.stereotype.Component;
13
 
14
import com.spice.profitmandi.common.model.ChartModel;
15
import com.spice.profitmandi.common.model.DataModel;
16
import com.spice.profitmandi.common.model.DatasetModel;
17
import com.spice.profitmandi.common.model.HoverModel;
18
import com.spice.profitmandi.common.model.LegendModel;
19
import com.spice.profitmandi.common.model.OptionsModel;
20
import com.spice.profitmandi.common.model.TitleModel;
21
import com.spice.profitmandi.common.model.Tooltips;
22
 
23
@Component
24
public class ChartServiceImpl implements ChartService {
25
 
26
	@Override
27
	public ChartModel createChart(int monthValue, Map<String, List<Double>> sortedBrandValue, List<String> colorList,
28
			List<String> borderList, String title) {
29
 
30
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
31
 
32
		LinkedHashSet<String> labels = new LinkedHashSet<String>();
33
 
34
		for (int i = monthValue; i >= 0; i--) {
35
 
36
			LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
37
			labels.add(startMonth.format(DateTimeFormatter.ofPattern("MMM''uu")).toString());
38
		}
39
 
40
		List<DatasetModel> datasets = new ArrayList<>();
41
 
42
		int i = 0;
43
 
44
		for (Entry<String, List<Double>> brandValue : sortedBrandValue.entrySet()) {
45
 
46
			DatasetModel lmsModel = new DatasetModel();
47
			lmsModel.setLabel(brandValue.getKey());
48
			lmsModel.setBackgroundColor(colorList.get(i));
49
 
50
			lmsModel.setData(brandValue.getValue());
51
 
52
			lmsModel.setType("line");
53
			lmsModel.setOrder(1);
54
			lmsModel.setFill("false");
55
			lmsModel.setBorderColor(borderList.get(i));
56
			datasets.add(lmsModel);
57
 
58
			i++;
59
		}
60
 
61
		DataModel dm = new DataModel();
62
		dm.setDatasets(datasets);
63
		dm.setLabels(labels);
64
 
65
		LegendModel lm = new LegendModel();
66
		lm.setPosition("top");
67
 
68
		Tooltips tooltips = new Tooltips();
69
		tooltips.setBodyFontSize(15);
70
		tooltips.setTitleFontSize(15);
71
		tooltips.setMode("index");
72
		tooltips.setIntersect(false);
73
		tooltips.setBackgroundColor("rgba(0, 0, 0, .5)");
74
 
75
		HoverModel hover = new HoverModel();
76
		hover.setIntersect(false);
77
		hover.setMode("index");
78
 
79
		TitleModel tm = new TitleModel();
28473 tejbeer 80
		tm.setText(title);
28468 tejbeer 81
		tm.setDisplay(true);
82
		tm.setFontSize(20);
83
		tm.setFontColor("#111");
84
 
85
		OptionsModel om = new OptionsModel();
86
		om.setResponsive(true);
87
		om.setLegend(lm);
88
		om.setTitle(tm);
89
		om.setTooltips(tooltips);
90
		om.setHover(hover);
91
 
92
		ChartModel cm = new ChartModel();
93
 
94
		cm.setType("line");
95
		cm.setData(dm);
96
		cm.setOptions(om);
97
 
98
		return cm;
99
	}
100
 
101
}