HTMLcopy
1
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
var stage = acgraph.create('container');
3
4
$('#container').append(
5
'<div class="seat-map-title">' +
6
'<h1>Boeing 737</h1>' +
7
'<p>Source <a href="https://cdn.anychart.com/svg-data/seat-map/boeing_737.svg"' +
8
'target="_blank">SVG Image</a></p></div>'
9
);
10
11
// get svg file
12
$.ajax({
13
type: 'GET',
14
url: 'https://cdn.anychart.com/svg-data/seat-map/boeing_737.svg',
15
// The data that have been used for this sample can be taken from the CDN
16
// load SVG image using jQuery ajax
17
success: function (svgData) {
18
// data for creating a SeatMap
19
// from the CDN https://cdn.anychart.com/csv-data/boeing_737.js to data file
20
var data = boeingData(); // eslint-disable-line no-undef
21
var chart = anychart.seatMap(data);
22
// set svg data,
23
chart.geoData(svgData);
24
chart
25
.padding([105, 0, 20, 0])
26
// load svg-file how it looked(colors stroke/fill except
27
// for elements of series)
28
.unboundRegions('as-is');
29
30
var series = chart.getSeries(0);
31
// sets fill series
32
series
33
.fill(function () {
34
var attrs = this.attributes;
35
36
return attrs ? attrs.fill : this.sourceColor;
37
})
38
// sets stroke series
39
.stroke(function () {
40
var attrs = this.attributes;
41
42
return attrs ? attrs.stroke : this.sourceColor;
43
});
44
45
// sets fill on hover series and select series
46
series.hovered().fill(returnColorHoverAndSelect);
47
series.selected().fill(returnColorHoverAndSelect);
48
49
// Create chart tooltip own title
50
series.tooltip().titleFormat('Place');
51
52
// Create chart tooltip own text
53
series.tooltip().format('{%Id}');
54
55
// create label zoom
56
var zoomLabel = chart.label(0);
57
zoomLabel
58
.text('2x Zoom.')
59
.background('#9E9E9E')
60
.fontColor('#fff')
61
.padding(5)
62
.position('center-top')
63
.offsetX(5)
64
.offsetY(60);
65
66
zoomLabel.listen('click', function () {
67
// zoom map in 2 times
68
chart.zoom(2);
69
});
70
71
// set color for label hover
72
zoomLabel.listen('mouseOver', mouseOverLabel);
73
zoomLabel.listen('mouseOut', mouseOutLabel);
74
75
// create label zoom to
76
var zoomToLabel = chart.label(1);
77
zoomToLabel
78
.text('1x Zoom.')
79
.background('#9E9E9E')
80
.fontColor('#fff')
81
.position('center-top')
82
.padding(5)
83
.offsetX(-75)
84
.offsetY(60);
85
86
zoomToLabel.listen('click', function () {
87
// zoomTo map
88
chart.zoomTo(1);
89
});
90
91
// set color for label hover
92
zoomToLabel.listen('mouseOver', mouseOverLabel);
93
zoomToLabel.listen('mouseOut', mouseOutLabel);
94
95
// label hover info
96
var labelHoverPlaceInfo = chart.label(2);
97
var labelHoverPlaceInfoFormat =
98
'<span style="color: #545f69; font-size: 14px">' +
99
'<b>Class</b>: %s<br/><b>Place</b>: %s<br/><b>Price</b>: %s</span>';
100
labelHoverPlaceInfo
101
.useHtml(true)
102
.padding(10)
103
.hAlign('left')
104
.position('right-top')
105
.anchor('right-top')
106
.offsetY(85)
107
.offsetX(20)
108
.width(250);
109
labelHoverPlaceInfo.background({
110
fill: '#FCFCFC',
111
stroke: '#E1E1E1',
112
corners: 3,
113
cornerType: 'ROUND'
114
});
115
labelHoverPlaceInfo.text(
116
anychart.format.subs(labelHoverPlaceInfoFormat, '-', '-', '0')
117
);
118
119
// label select info
120
var labelSelectPlace = chart.label(3);
121
var labelSelectPlaceFormat =
122
'<span style="color: #545f69; font-size: 14px">' +
123
'<b>Seat Reservation<br/></b><b>Places</b>: %s<br/><b>Total Price</b>: %s</span>';
124
labelSelectPlace
125
.useHtml(true)
126
.padding(10)
127
.hAlign('left')
128
.position('right-top')
129
.anchor('right-top')
130
.offsetY(160)
131
.offsetX(20)
132
.width(250);
133
labelSelectPlace.background({
134
fill: '#FCFCFC',
135
stroke: '#E1E1E1',
136
corners: 3,
137
cornerType: 'ROUND'
138
});
139
labelSelectPlace.text(
140
anychart.format.subs(labelSelectPlaceFormat, '-', '0')
141
);
142
143
// label info
144
var labelInfo = chart.label(4);
145
labelInfo
146
.useHtml(true)
147
.padding(10)
148
.hAlign('left')
149
.position('left-top')
150
.anchor('left-top')
151
.offsetY(85)
152
.offsetX(20)
153
.width(270);
154
labelInfo.background({
155
fill: '#FCFCFC',
156
stroke: '#E1E1E1',
157
corners: 3,
158
cornerType: 'ROUND'
159
});
160
labelInfo
161
.text(
162
'<span style="color: #545f69; font-size: 14px"><b>Please select a location.' +
163
'</b><br><br>You can do this by clicking on the<br>desired location , so you can select' +
164
'<br>multiple locations with the aid<br>of a combination of keys:<br><b><i>shift/ctrl' +
165
' + target place</i></b>.</span>'
166
)
167
.useHtml(true);
168
169
// add pointsHover listener to get hovered place info
170
chart.listen('pointsHover', function (point) {
171
var placeInfo;
172
if (point.seriesStatus[0].points[0] !== undefined) {
173
placeInfo = placeInfoFunc(point.seriesStatus[0].points[0].id);
174
labelHoverPlaceInfo.text(
175
anychart.format.subs(
176
labelHoverPlaceInfoFormat,
177
placeInfo.class,
178
placeInfo.place,
179
placeInfo.price
180
)
181
);
182
}
183
});
184
185
// add pointsSelect listener to get select place info
186
chart.listen('pointsSelect', function (points) {
187
var placesInfo = points.seriesStatus[0].points;
188
var placesId = [];
189
var totalPrice = 0;
190
191
if (chart.getSelectedPoints().length) {
192
for (var i = 0; i < placesInfo.length; i++) {
193
placesId.push(points.seriesStatus[0].points[i].id);
194
totalPrice += parseInt(
195
placeInfoFunc(points.seriesStatus[0].points[i].id).price
196
);
197
}
198
199
totalPrice += '$';
200
201
labelSelectPlace
202
.text(
203
anychart.format.subs(
204
labelSelectPlaceFormat,
205
placesId,
206
totalPrice
207
)
208
)
209
.background({
210
fill: '#E5EEF5'
211
});
212
}
213
});
214
215
// add chartClick listener to reset labelSelectPlace values
216
chart.listen('click', function () {
217
if (chart.getSelectedPoints().length === 0) {
218
labelSelectPlace.background({
219
fill: '#FCFCFC'
220
});
221
labelHoverPlaceInfo.text(
222
anychart.format.subs(labelHoverPlaceInfoFormat, '-', '-', '0')
223
);
224
labelSelectPlace.text(
225
anychart.format.subs(labelSelectPlaceFormat, '-', '0')
226
);
227
}
228
});
229
230
// set container id for the chart
231
chart.container(stage);
232
// initiate chart drawing
233
chart.draw();
234
}
235
});
236
});
237
238
function returnColorHoverAndSelect() {
239
return '#64b5f6';
240
}
241
242
function mouseOverLabel() {
243
this.background(anychart.color.darken('#9E9E9E', 0.35));
244
}
245
246
function mouseOutLabel() {
247
this.background('#9E9E9E');
248
}
249
250
function placeInfoFunc(id) {
251
var ECONOM_PLUS_ROW_MIN = 21;
252
var regBusinessClass = /[1-3]{1}-(A|B|E|F)/;
253
var regeconomClass = /([7-9]{1}|[0-9]{2})-(A|B|C|D|E|F)/;
254
255
var businessClass = id.match(regBusinessClass)
256
? id.match(regBusinessClass)[0]
257
: false;
258
var economPlusClass =
259
id.match(regeconomClass) &&
260
id.match(regeconomClass)[1] <= ECONOM_PLUS_ROW_MIN
261
? id.match(regeconomClass)[0]
262
: false;
263
var economClass =
264
id.match(regeconomClass) &&
265
id.match(regeconomClass)[1] > ECONOM_PLUS_ROW_MIN
266
? id.match(regeconomClass)[0]
267
: false;
268
269
switch (id) {
270
case businessClass:
271
return {
272
place: id,
273
class: 'Business Class',
274
price: '350$'
275
};
276
case economPlusClass:
277
return {
278
place: id,
279
class: 'Econom-Plus Class',
280
price: '250$'
281
};
282
case economClass:
283
return {
284
place: id,
285
class: 'Econom Class',
286
price: '150$'
287
};
288
default:
289
}
290
}