HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
stage = acgraph.create('container');
3
$.ajax({
4
type: 'GET',
5
url: 'https://cdn.anychart.com/svg-data/seat-map/boeing_737.svg',
6
// The data that have been used for this sample can be taken from the CDN
7
// load SVG image using jQuery ajax
8
success: function (svgData) {
9
//data for creating a SeatMap
10
//from the CDN https://cdn.anychart.com/csv-data/boeing_737.js to data file
11
var data = boeingData();
12
var chart = anychart.seatMap(data);
13
//set svg data,
14
chart.geoData(svgData);
15
chart.padding([0, 200, 0, 0]);
16
//load svg-file how it looked(colors stroke/fill except
17
//for elements of series)
18
chart.unboundRegions('as-is');
19
20
series = chart.getSeries(0);
21
//sets fill series
22
series.fill(function () {
23
var attrs = this.attributes;
24
25
return attrs ? attrs.fill : this.sourceColor;
26
});
27
28
//sets stroke series
29
series.stroke(function () {
30
var attrs = this.attributes;
31
32
return attrs ? attrs.stroke : this.sourceColor;
33
});
34
35
function returnColorHoverAndSelect() {
36
return '#64b5f6';
37
}
38
39
//sets fill on hover series and select series
40
series.hovered().fill(returnColorHoverAndSelect);
41
series.selected().fill(returnColorHoverAndSelect);
42
43
//Create chart tooltip own title
44
series.tooltip().titleFormat(function () {
45
return 'Place'
46
});
47
48
//Create chart tooltip own text
49
series.tooltip().format(function () {
50
return this.id;
51
});
52
53
54
//label hover info
55
var labelHoverPlaceInfo = chart.label(2);
56
var labelHoverPlaceInfoFormat = "<span style='color: #545f69; font-size: 14px'>" +
57
"<b>Class</b>: %s<br/><b>Place</b>: %s<br/><b>Price</b>: %s</span>";
58
labelHoverPlaceInfo.padding(10).useHtml(true).hAlign("left");
59
labelHoverPlaceInfo.position("right-top");
60
labelHoverPlaceInfo.anchor("right-top");
61
labelHoverPlaceInfo.offsetY(85);
62
labelHoverPlaceInfo.offsetX(20);
63
labelHoverPlaceInfo.width(250);
64
labelHoverPlaceInfo.background({
65
fill: '#FCFCFC',
66
stroke: '#E1E1E1',
67
corners: 3,
68
cornerType: 'ROUND'
69
}).enabled(true);
70
labelHoverPlaceInfo.text(anychart.format.subs(labelHoverPlaceInfoFormat, '-', '-', '0'));
71
72
//label select info
73
var labelSelectPlace = chart.label(3);
74
var labelSelectPlaceFormat = "<span style='color: #545f69; font-size: 14px'>" +
75
"<b>Seat Reservation<br/></b><b>Places</b>: %s<br/><b>Total Price</b>: %s</span>";
76
labelSelectPlace.padding(10).useHtml(true).hAlign("left");
77
labelSelectPlace.position("right-top");
78
labelSelectPlace.anchor("right-top");
79
labelSelectPlace.offsetY(160);
80
labelSelectPlace.offsetX(20);
81
labelSelectPlace.width(250);
82
labelSelectPlace.background({
83
fill: '#FCFCFC',
84
stroke: '#E1E1E1',
85
corners: 3,
86
cornerType: 'ROUND'
87
}).enabled(true);
88
labelSelectPlace.text(anychart.format.subs(labelSelectPlaceFormat, '-', '0'));
89
90
91
function placeInfoFunc(id) {
92
const ECONOM_PLUS_ROW_MIN = 21;
93
var regBusinessClass = /[1-3]{1}-(A|B|E|F)/;
94
var regeconomClass = /([7-9]{1}|[0-9]{2})-(A|B|C|D|E|F)/;
95
96
var businessClass = id.match(regBusinessClass) ? id.match(regBusinessClass)[0] : false;
97
var economPlusClass = id.match(regeconomClass) && id.match(regeconomClass)[1] <= ECONOM_PLUS_ROW_MIN ? id.match(regeconomClass)[0] : false;
98
var economClass = id.match(regeconomClass) && id.match(regeconomClass)[1] > ECONOM_PLUS_ROW_MIN ? id.match(regeconomClass)[0] : false;
99
100
switch (id) {
101
case businessClass :
102
return {
103
place: id,
104
class: 'Business Class',
105
price: '350$'
106
};
107
case economPlusClass :
108
return {
109
place: id,
110
class: 'Econom-Plus Class',
111
price: '250$'
112
};
113
case economClass :
114
return {
115
place: id,
116
class: 'Econom Class',
117
price: '150$'
118
};
119
}
120
}
121
122
//add pointsHover listener to get hovered place info
123
chart.listen('pointsHover', function (point) {
124
var placeInfo;
125
if (point.seriesStatus[0].points[0] !== undefined) {
126
placeInfo = placeInfoFunc(point.seriesStatus[0].points[0].id);
127
labelHoverPlaceInfo.text(anychart.format.subs(labelHoverPlaceInfoFormat, placeInfo.class, placeInfo.place, placeInfo.price));
128
}
129
});
130
131
//add pointsSelect listener to get select place info
132
chart.listen('pointsSelect', function (points) {
133
var placesInfo = points.seriesStatus[0].points;
134
var placesId = [];
135
var totalPrice = 0;
136
137
if (chart.getSelectedPoints().length) {
138
139
for (var i = 0; i < placesInfo.length; i++) {
140
placesId.push(points.seriesStatus[0].points[i].id);
141
totalPrice += parseInt(placeInfoFunc(points.seriesStatus[0].points[i].id).price);
142
}
143
144
totalPrice += '$';
145
146
labelSelectPlace.text(anychart.format.subs(labelSelectPlaceFormat, placesId, totalPrice)).background({
147
fill: '#E5EEF5'
148
});
149
}
150
151
});
152
153
//add chartClick listener to reset labelSelectPlace values
154
chart.listen('click', function () {
155
if (chart.getSelectedPoints().length == 0) {
156
labelSelectPlace.background({
157
fill: '#FCFCFC'
158
});
159
labelHoverPlaceInfo.text(anychart.format.subs(labelHoverPlaceInfoFormat, '-', '-', '0'));
160
labelSelectPlace.text(anychart.format.subs(labelSelectPlaceFormat, '-', '0'));
161
}
162
});
163
164
//create zoom controls
165
var zoomController = anychart.ui.zoom();
166
zoomController.render(chart);
167
168
//set container id for the chart
169
chart.container(stage);
170
171
//initiate chart drawing
172
chart.draw();
173
174
}
175
});
176
});