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
// The data that have been used for this sample can be taken from the CDN
5
// https://cdn.anychart.com/svg-data/seat-map/sport-mall.svg
6
// https://cdn.anychart.com/text-data/sport_mall_data.js
7
$('#container').append(
8
'<div class="seat-map-title">' +
9
'<h1>Sport Mall</h1>' +
10
'<p>Source <a href="https://cdn.anychart.com/svg-data/' +
11
'seat-map/sport-mall.svg"' +
12
'target="_blank">SVG Image</a></p></div>'
13
);
14
15
// set svg file
16
$.ajax({
17
type: 'GET',
18
url: 'https://cdn.anychart.com/svg-data/seat-map/sport-mall.svg',
19
// The data that have been used for this sample can be taken from the CDN
20
// load SVG image using jQuery ajax
21
success: function (svgData) {
22
// data for creating a SeatMap
23
var chart = anychart.seatMap([
24
{ id: 'nike', value: 'Nike' },
25
{ id: 'adidas', value: 'Adidas' },
26
{ id: 'puma', value: 'Puma' },
27
{ id: 'reebok', value: 'Reebok' }
28
]);
29
// set svg data
30
chart.geoData(svgData);
31
// load svg-file how it looked(colors stroke/fill)
32
chart
33
.unboundRegions('as-is')
34
// set chart padding
35
.padding([10]);
36
37
// create chart legend
38
var legend = chart.legend();
39
legend
40
.enabled(true)
41
// items source mode categories
42
.itemsSourceMode('categories')
43
.position('right')
44
.itemsLayout('vertical');
45
46
var series = chart.getSeries(0);
47
// set color scale.
48
series.colorScale(
49
anychart.scales.ordinalColor([
50
{ equal: 'Nike', color: 'rgb(127, 210, 235)' },
51
{ equal: 'Adidas', color: 'rgb(111, 193, 117)' },
52
{ equal: 'Puma', color: 'rgb(242, 203, 117)' },
53
{ equal: 'Reebok', color: 'rgb(188, 139, 191)' }
54
])
55
);
56
57
// sets stroke/fill series
58
series.stroke(returnColor);
59
series.fill(returnColor);
60
61
// sets fill on hover series and select series
62
series.hovered().fill(returnColorHoverAndSelect);
63
series.selected().fill(returnColorHoverAndSelect);
64
65
// Create chart tooltip own title
66
series.tooltip().title().useHtml(true);
67
series.tooltip().titleFormat(function () {
68
var openTime = {};
69
70
switch (this.regionProperties.id) {
71
case 'nike':
72
openTime = {
73
workingTime: '9AM-8PM',
74
workingTime24Format: '9-20'
75
};
76
break;
77
case 'adidas':
78
openTime = {
79
workingTime: '12AM-9PM',
80
workingTime24Format: '12-21'
81
};
82
break;
83
case 'puma':
84
openTime = {
85
workingTime: '10AM-9PM',
86
workingTime24Format: '10-21'
87
};
88
break;
89
case 'reebok':
90
openTime = {
91
workingTime: '8AM-4PM',
92
workingTime24Format: '8-16'
93
};
94
break;
95
default:
96
}
97
98
var state = isOpen(openTime.workingTime24Format);
99
100
return (
101
this.value +
102
' - ' +
103
state +
104
'<br><span style="font-size: 10px;">' +
105
openTime.workingTime +
106
'</span>'
107
);
108
});
109
// Create chart tooltip own text
110
series.tooltip().format(function () {
111
var textCompany = aboutCompany(); // eslint-disable-line no-undef
112
113
switch (this.regionProperties.id) {
114
case 'nike':
115
return textCompany.nike;
116
case 'adidas':
117
return textCompany.adidas;
118
case 'puma':
119
return textCompany.puma;
120
case 'reebok':
121
return textCompany.reebok;
122
default:
123
}
124
});
125
126
// set container id for the chart
127
chart.container(stage);
128
// initiate chart drawing
129
chart.draw();
130
}
131
});
132
});
133
134
function returnColor() {
135
var attrs = this.attributes;
136
if (attrs) {
137
// attr in svg.file
138
var itemClass = attrs.class;
139
switch (itemClass) {
140
case 'nike':
141
return 'rgb(127, 210, 235)';
142
case 'adidas':
143
return 'rgb(111, 193, 117)';
144
case 'puma':
145
return 'rgb(242, 203, 117)';
146
case 'reebok':
147
return 'rgb(188, 139, 191)';
148
case 'nike-logo':
149
case 'adidas-logo':
150
case 'puma-logo':
151
case 'reebok-logo':
152
return '#606061';
153
default:
154
return this.sourceColor;
155
// it returns the original color for
156
// those elements that are not fill/stroke over
157
}
158
}
159
}
160
161
function returnColorHoverAndSelect() {
162
var attrs = this.attributes;
163
if (attrs) {
164
// attr in svg.file
165
var itemClass = attrs.class;
166
switch (itemClass) {
167
case 'nike':
168
case 'adidas':
169
case 'puma':
170
case 'reebok':
171
return anychart.color.lighten(this.sourceColor, 0.25);
172
case 'nike-logo':
173
case 'adidas-logo':
174
case 'puma-logo':
175
case 'reebok-logo':
176
return anychart.color.darken(this.sourceColor, 0.5);
177
default:
178
return this.sourceColor;
179
// it returns the original color for
180
// those elements that are not fill/stroke over
181
}
182
}
183
}
184
185
// function return state open or close.
186
function isOpen(date) {
187
var d = new Date(); // for now
188
var min = 60;
189
var currentTime = d.getHours() * min + d.getMinutes();
190
// if it is not Sunday
191
if (d.getDay() !== 0) {
192
if (
193
currentTime >= date.split('-')[0] * min &&
194
currentTime <= date.split('-')[1] * min
195
) {
196
return 'open';
197
}
198
return 'close';
199
}
200
return 'close';
201
}