summaryrefslogtreecommitdiff
path: root/resources/views/modules/statistics-chart/custom.phtml
blob: 0858373ca8c68d09b44e7074a3ed75eb793a43f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?php

use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\View;

?>

<div class="container pt-3">
    <h4 class="border-bottom p-2 mb-4">
        <?= I18N::translate('Create your own chart') ?>
    </h4>

    <form method="get" action="<?= e(route('module', ['module' => $module->name(), 'action' => 'CustomChart'])) ?>" id="own-stats-form" class="wt-page-options wt-page-options-statistics">
        <input type="hidden" name="route" value="<?= e('/module/' . $module->name() . '/CustomChart') ?>">
        <input type="hidden" name="ged" value="<?= e($tree->name()) ?>">
        <div class="form-group row">
            <div class="col-sm-2 wt-page-options-label">
                <?= I18N::translate('Chart type') ?>
            </div>

            <div class="col-sm-4 wt-page-options-value">
                <fieldset>
                    <legend><?= I18N::translate('Individual') ?></legend>

                    <?= view('components/radios', [
                        'name' => 'x-as', 'selected' => $module::X_AXIS_BIRTH_MONTH, 'options' => [
                            $module::X_AXIS_BIRTH_MONTH           => I18N::translate('Month of birth'),
                            $module::X_AXIS_DEATH_MONTH           => I18N::translate('Month of death'),
                            $module::X_AXIS_FIRST_CHILD_MONTH     => I18N::translate('Month of birth of first child in a relation'),
                            $module::X_AXIS_AGE_AT_DEATH          => I18N::translate('Average age at death'),
                            $module::X_AXIS_AGE_AT_MARRIAGE       => I18N::translate('Age in year of marriage'),
                            $module::X_AXIS_AGE_AT_FIRST_MARRIAGE => I18N::translate('Age in year of first marriage'),

                        ],
                    ]) ?>
                </fieldset>

                <fieldset>
                    <legend><?= I18N::translate('Family') ?></legend>

                    <?= view('components/radios', [
                        'name' => 'x-as', 'selected' => $module::X_AXIS_BIRTH_MONTH, 'options' => [
                            $module::X_AXIS_MARRIAGE_MONTH       => I18N::translate('Month of marriage'),
                            $module::X_AXIS_FIRST_MARRIAGE_MONTH => I18N::translate('Month of first marriage'),
                            $module::X_AXIS_NUMBER_OF_CHILDREN   => I18N::translate('Number of children'),

                        ],
                    ]) ?>
                </fieldset>

                <fieldset>
                    <legend><?= I18N::translate('Map') ?></legend>

                    <?= view('components/radios', [
                        'name' => 'x-as', 'selected' => $module::X_AXIS_BIRTH_MONTH, 'options' => [
                            $module::X_AXIS_INDIVIDUAL_MAP => I18N::translate('Individuals'),
                            $module::X_AXIS_BIRTH_MAP      => I18N::translate('Births'),
                            $module::X_AXIS_MARRIAGE_MAP   => I18N::translate('Marriages'),
                            $module::X_AXIS_DEATH_MAP      => I18N::translate('Deaths'),
                        ],
                    ]) ?>
                </fieldset>
            </div>

            <div class="col-sm-2 wt-page-options-label">
                <?= I18N::translate('Details') ?>
            </div>

            <div class="col-sm-4 wt-page-options-value">
                <fieldset id="axes">
                    <legend><?= I18N::translate('Categories') ?></legend>

                    <label>
                        <input type="radio" id="z_none" name="z-as" value="<?= $module::Z_AXIS_ALL ?>" onclick="statusDisable('z-axis-boundaries-periods');">
                        <?= I18N::translate('none') ?>
                    </label>
                    <br>
                    <label>
                        <input type="radio" id="z_sex" name="z-as" value="<?= $module::Z_AXIS_SEX ?>" onclick="statusDisable('z-axis-boundaries-periods');">
                        <?= I18N::translate('gender') ?>
                    </label>
                    <br>
                    <label>
                        <input type="radio" id="z_time" name="z-as" value="<?= $module::Z_AXIS_TIME ?>" checked onclick="statusEnable('z-axis-boundaries-periods');">
                        <?= I18N::translate('date periods') ?>
                    </label>
                    <label for="z-axis-boundaries-periods" class="sr-only">
                        <?= I18N::translate('Date range') ?>
                    </label>
                    <select id="z-axis-boundaries-periods" class="form-control" name="z-axis-boundaries-periods">
                        <option value="1700,1750,1800,1850,1900,1950,2000" selected>
                            <?= /* I18N: from 1700 interval 50 years */
                            I18N::plural('from %1$s interval %2$s year', 'from %1$s interval %2$s years', 50, I18N::digits(1700), I18N::number(50)) ?>
                        </option>
                        <option value="1800,1840,1880,1920,1950,1970,2000">
                            <?= I18N::plural('from %1$s interval %2$s year', 'from %1$s interval %2$s years', 40, I18N::digits(1800), I18N::number(40)) ?>
                        </option>
                        <option value="1800,1850,1900,1950,2000">
                            <?= I18N::plural('from %1$s interval %2$s year', 'from %1$s interval %2$s years', 50, I18N::digits(1800), I18N::number(50)) ?>
                        </option>
                        <option value="1900,1920,1940,1960,1980,1990,2000">
                            <?= I18N::plural('from %1$s interval %2$s year', 'from %1$s interval %2$s years', 20, I18N::digits(1900), I18N::number(20)) ?>
                        </option>
                        <option value="1900,1925,1950,1975,2000">
                            <?= I18N::plural('from %1$s interval %2$s year', 'from %1$s interval %2$s years', 25, I18N::digits(1900), I18N::number(25)) ?>
                        </option>
                        <option value="1940,1950,1960,1970,1980,1990,2000">
                            <?= I18N::plural('from %1$s interval %2$s year', 'from %1$s interval %2$s years', 10, I18N::digits(1940), I18N::number(10)) ?>
                        </option>
                    </select>
                </fieldset>

                <fieldset id="zyaxes">
                    <legend><?= I18N::translate('Results') ?></legend>

                    <label>
                        <input type="radio" name="y-as" value="<?= $module::Y_AXIS_NUMBERS ?>" checked>
                        <?= I18N::translate('numbers') ?>
                    </label>
                    <br>
                    <label>
                        <input type="radio" name="y-as" value="<?= $module::Y_AXIS_PERCENT ?>">
                        <?= I18N::translate('percentage') ?>
                    </label>
                </fieldset>

                <fieldset id="x_years" style="display:none;">
                    <legend><?= I18N::translate('Age interval') ?></legend>

                    <label for="x-axis-boundaries-ages" class="sr-only">
                        <?= I18N::translate('Age interval') ?>
                    </label>
                    <?= view('components/select', ['name' => 'x-axis-boundaries-ages', 'selected' => '1,5,10,20,30,40,50,60,70,80,90,100', 'options' => ['1,5,10,20,30,40,50,60,70,80,90,100' => I18N::plural('%s year', '%s years', 10, I18N::number(10)), '5,20,40,60,75,80,85,90' => I18N::plural('%s year', '%s years', 20, I18N::number(20)), '10,25,50,75,100' => I18N::plural('%s year', '%s years', 25, I18N::number(25))]]) ?>
                </fieldset>

                <fieldset id="x_years_m" style="display:none;">
                    <legend><?= I18N::translate('Age interval') ?></legend>

                    <label for="x-axis-boundaries-ages_m" class="sr-only">
                        <?= I18N::translate('Select the desired age interval') ?>
                    </label>
                    <?= view('components/select', ['name' => 'x-axis-boundaries-ages_m', 'selected' => '16,18,20,22,24,26,28,30,32,35,40,50', 'options' => ['16,18,20,22,24,26,28,30,32,35,40,50' => I18N::plural('%s year', '%s years', 2, I18N::number(2)), '20,25,30,35,40,45,50' => I18N::plural('%s year', '%s years', 5, I18N::number(5))]]) ?>
                </fieldset>

                <div id="map_opt" style="display:none;">
                    <fieldset id="chart_type">
                        <legend><?= I18N::translate('Chart type') ?></legend>

                        <label for="chart_type" class="sr-only"><?= I18N::translate('Chart type') ?></label>
                        <select name="chart_type" class="form-control" onchange="statusShowSurname(this);">
                            <option value="indi_distribution_chart" selected>
                                <?= I18N::translate('Individuals') ?>
                            </option>
                            <option value="surname_distribution_chart">
                                <?= I18N::translate('Surnames') ?>
                            </option>
                        </select>

                        <div id="surname_opt" class="form-group" style="display:none;">
                            <label for="SURN"><?= I18N::translate('Surname') ?></label>
                            <input data-autocomplete-type="SURN" class="form-control" type="text" id="SURN" name="SURN">
                        </div>
                    </fieldset>

                    <fieldset>
                        <legend id="label-area"><?= I18N::translate('Geographic area') ?></legend>

                        <label for="chart_shows" class="sr-only"><?= I18N::translate('Geographic area') ?></label>
                        <select id="chart_shows" class="form-control" name="chart_shows">
                            <option value="world" selected>
                                <?= I18N::translate('World') ?>
                            </option>
                            <option value="150">
                                <?= I18N::translate('Europe') ?>
                            </option>
                            <option value="021">
                                <?= I18N::translate('Northern America') ?>
                            </option>
                            <option value="005">
                                <?= I18N::translate('South America') ?>
                            </option>
                            <option value="142">
                                <?= I18N::translate('Asia') ?>
                            </option>
                            <option value="145">
                                <?= I18N::translate('Middle East') ?>
                            </option>
                            <option value="002">
                                <?= I18N::translate('Africa') ?>
                            </option>
                        </select>
                    </fieldset>
                </div>
            </div>
        </div>

        <p>
            <button type="submit" class="btn btn-primary">
                <?= view('icons/save') ?>
                <?= I18N::translate('show the chart') ?>
            </button>
        </p>
    </form>

    <div id="custom-chart" class="wt-ajax-load">
        <!-- Not initially empty, to disable spinner -->
    </div>
</div>

<?php View::push('javascript') ?>
<script>
    function statusDisable(sel) {
        var cbox      = document.getElementById(sel);
        cbox.checked  = false;
        cbox.disabled = true;
    }

    function statusEnable(sel) {
        var cbox      = document.getElementById(sel);
        cbox.disabled = false;
    }

    function statusHide(sel) {
        var box           = document.getElementById(sel);
        box.style.display = "none";
        var box_m         = document.getElementById(sel + "_m");
        if (box_m) {
            box_m.style.display = "none";
        }
        if (sel === "map_opt") {
            var box_axes = document.getElementById("axes");
            if (box_axes) {
                box_axes.style.display = "";
            }
            var box_zyaxes = document.getElementById("zyaxes");
            if (box_zyaxes) {
                box_zyaxes.style.display = "";
            }
        }
    }

    function statusShow(sel) {
        var box           = document.getElementById(sel);
        box.style.display = "";
        var box_m         = document.getElementById(sel + "_m");
        if (box_m) {
            box_m.style.display = "none";
        }
        if (sel === "map_opt") {
            var box_axes = document.getElementById("axes");
            if (box_axes) {
                box_axes.style.display = "none";
            }
            var box_zyaxes = document.getElementById("zyaxes");
            if (box_zyaxes) {
                box_zyaxes.style.display = "none";
            }
        }
    }

    function statusChecked(sel) {
        var cbox     = document.getElementById(sel);
        cbox.checked = true;
    }

    function statusShowSurname(x) {
        if (x.value === "surname_distribution_chart") {
            document.getElementById("surname_opt").style.display = "";
        } else if (x.value !== "surname_distribution_chart") {
            document.getElementById("surname_opt").style.display = "none";
        }
    }

    function loadCustomChart() {
        $("#custom-chart").html("");
        var form = $("#own-stats-form");
        jQuery.get(form.attr("action"), form.serialize())
            .done(function (data) {
                $("#custom-chart").html(data);
            })
            .fail(function (jqXHR, textStatus) {
                // Server error?  Show something to get rid of the spinner.
                $("#custom-chart").html(textStatus);
            });
        return false;
    }

    $("[name='x-as']").change(function () {
        var x_axis = document.querySelector("[name='x-as']:checked").value;

        switch (x_axis) {
            case "<?= e($module::X_AXIS_BIRTH_MONTH) ?>":
            case "<?= e($module::X_AXIS_DEATH_MONTH) ?>":
            case "<?= e($module::X_AXIS_FIRST_CHILD_MONTH) ?>":
                statusEnable("z_sex");
                statusHide("x_years");
                statusHide("map_opt");
                break;

            case "<?= e($module::X_AXIS_AGE_AT_DEATH) ?>":
                statusEnable("z_sex");
                statusShow("x_years");
                statusHide("map_opt");
                break;

            case "<?= e($module::X_AXIS_AGE_AT_MARRIAGE) ?>":
            case "<?= e($module::X_AXIS_AGE_AT_FIRST_MARRIAGE) ?>":
                statusEnable("z_sex");
                statusHide("x_years");
                statusShow("x_years_m");
                statusHide("map_opt");
                break;

            case "<?= e($module::X_AXIS_MARRIAGE_MONTH) ?>":
            case "<?= e($module::X_AXIS_FIRST_MARRIAGE_MONTH) ?>":
                statusChecked("z_none");
                statusDisable("z_sex");
                statusHide("x_years");
                statusHide("map_opt");
                break;

            case "<?= e($module::X_AXIS_INDIVIDUAL_MAP) ?>":
                statusHide("x_years");
                statusShow("map_opt");
                statusShow("chart_type");
                break;

            case "<?= e($module::X_AXIS_BIRTH_MAP) ?>":
            case "<?= e($module::X_AXIS_MARRIAGE_MAP) ?>":
            case "<?= e($module::X_AXIS_DEATH_MAP) ?>":
                statusHide("x_years");
                statusShow("map_opt");
                statusHide("chart_type");
                statusHide("surname_opt");
                break;
        }
    });

    $("#own-stats-form").on("submit", loadCustomChart);
</script>
<?php View::endpush() ?>