{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# AM4 Performance\n", "\n", "\n", "* Wenchang Yang (wenchang@princeton.edu)\n", "* Department of Geosciences, Princeton University" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2018-11-27T17:04:24.285121Z", "start_time": "2018-11-27T17:04:23.632836Z" }, "code_folding": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Tue Nov 27 12:04:23 EST 2018\r\n" ] } ], "source": [ "# import\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "plt.rcParams['hatch.color']='g'\n", "import xarray as xr\n", "import pandas as pd\n", "import os, sys, glob, datetime\n", "from subprocess import check_output\n", "import math\n", "\n", "import geoxarray\n", "from geoplots import mapplot\n", "\n", "!date\n", "%matplotlib notebook" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2018-11-27T16:52:56.292583Z", "start_time": "2018-11-27T16:52:56.281036Z" }, "code_folding": [ 0 ] }, "outputs": [], "source": [ "def get_dataframe(cases=None):\n", "# if cases is None:\n", "# cases = glob.glob('run_FLOR_ctl_*') \n", " \n", " columns = ('expname', 'ntasks-per-node', 'tot_pes', 'tot_nodes', 'tot_spmy', 'tot_throughput', 'tot_cost')\n", "\n", " records = []\n", " for case in cases:\n", " slurm_logs = glob.glob(f'{case}/slurm-*')\n", " if slurm_logs:\n", " slurm_logs.sort()\n", " else:\n", " continue\n", " \n", " # ntasks-per-node\n", " s = check_output(f'grep ntasks-per-node {case}/test_AM4_*', shell=True) \\\n", " .decode('utf-8').strip().split('=')\n", " ntasks_per_node = int(s[-1])\n", " \n", "\n", " for slog in slurm_logs:\n", " # each slurm output has a single PE layout\n", " try:\n", " s = check_output(f'grep \"statistics\" {slog} -A326 |grep \"Total runtime\" -m 1', shell=True) \\\n", " .decode('utf-8').strip().split()\n", " except:\n", " continue # this is from a failed run\n", " tot_pes = int(s[-1]) - int(s[-2]) + 1\n", "# tot_nodes = tot_pes//ntasks_per_node\n", " tot_nodes = math.ceil(tot_pes/ntasks_per_node)\n", " \n", " \n", " # expname\n", " expname = check_output(f'grep expname {slog}', shell=True) \\\n", " .decode('utf-8').strip().split()[-1]\n", " \n", " \n", " # tot seconds per model years and throughput (model years per day)\n", " ss = check_output(f'grep \"statistics\" {slog} -A326 |grep \"Total runtime\"', shell=True) \\\n", " .decode('utf-8').strip().split('\\n')\n", " tot_spmy_list = []\n", " tot_throughput_list = []\n", " tot_cost_list = []\n", " for s in ss:\n", " spmy = float(s.split()[4])\n", " throughput = 24/(spmy/3600)\n", " tot_spmy_list.append(spmy)\n", " tot_throughput_list.append(throughput)\n", " cost = tot_nodes * 40 * (spmy/3600)\n", " tot_cost_list.append(cost)\n", " \n", " # create records\n", " for (tot_spmy,tot_throughput, tot_cost) in zip(tot_spmy_list, tot_throughput_list,tot_cost_list):\n", " \n", " record = (expname, ntasks_per_node, tot_pes, tot_nodes, tot_spmy, tot_throughput, tot_cost)\n", " records.append(record)\n", "\n", "\n", " df = pd.DataFrame(records, columns=columns)\n", " return df" ] }, { "cell_type": "markdown", "metadata": { "ExecuteTime": { "end_time": "2018-04-02T15:34:28.465428Z", "start_time": "2018-04-02T15:34:28.343191Z" } }, "source": [ "## FLOR_tiger2_intelmpi_18" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T16:05:38.735649Z", "start_time": "2018-11-29T16:05:33.904192Z" }, "code_folding": [], "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "DataFrame created for cases: ['288PE_36x', '288PE_40x', '384PE_36x', '384PE_40x', '432PE_36x', '432PE_40x', '576PE_36x', '576PE_39x', '576PE_40x', '768PE_36x', '768PE_40x', '864PE_36x', '864PE_40x']\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
expnamentasks-per-nodetot_pestot_nodestot_spmytot_throughputtot_cost
0test_AM4_tigercpu_intelmpi_18_288PE_36x3628886892.29577712.535736612.648514
1test_AM4_tigercpu_intelmpi_18_288PE_40x4028887147.20083612.088649635.306741
2test_AM4_tigercpu_intelmpi_18_384PE_36x36384115539.35988915.597470677.032875
3test_AM4_tigercpu_intelmpi_18_384PE_36x36384115463.06340615.815302667.707750
4test_AM4_tigercpu_intelmpi_18_384PE_36x36384115425.06197415.926085663.063130
5test_AM4_tigercpu_intelmpi_18_384PE_40x40384105867.41535614.725394651.935040
6test_AM4_tigercpu_intelmpi_18_384PE_40x40384105711.34591515.127783634.593991
7test_AM4_tigercpu_intelmpi_18_384PE_40x40384105638.24730215.323911626.471922
8test_AM4_tigercpu_intelmpi_18_432PE_36x36432124907.50585817.605685654.334114
9test_AM4_tigercpu_intelmpi_18_432PE_36x36432124895.48513817.648915652.731352
10test_AM4_tigercpu_intelmpi_18_432PE_36x36432124815.06568717.943680642.008758
11test_AM4_tigercpu_intelmpi_18_432PE_36x36432124768.18000818.120121635.757334
12test_AM4_tigercpu_intelmpi_18_432PE_36x36432124945.33392317.471014659.377856
13test_AM4_tigercpu_intelmpi_18_432PE_36x36432124914.47888517.580704655.263851
14test_AM4_tigercpu_intelmpi_18_432PE_40x40432115318.31504616.245747650.016283
15test_AM4_tigercpu_intelmpi_18_432PE_40x40432115302.63031916.293800648.099261
16test_AM4_tigercpu_intelmpi_18_432PE_40x40432115301.27229616.297974647.933281
17test_AM4_tigercpu_intelmpi_18_432PE_40x40432115341.86076116.174139652.894093
18test_AM4_tigercpu_intelmpi_18_432PE_40x40432115221.82909816.545926638.223556
19test_AM4_tigercpu_intelmpi_18_576PE_36x36576163970.52885321.760325705.871796
20test_AM4_tigercpu_intelmpi_18_576PE_36x36576163900.48855922.151071693.420188
21test_AM4_tigercpu_intelmpi_18_576PE_36x36576163891.66309322.201305691.851217
22test_AM4_tigercpu_intelmpi_18_576PE_36x36576163883.84774222.245980690.461821
23test_AM4_tigercpu_intelmpi_18_576PE_36x36576163933.33119621.966114699.258879
24test_AM4_tigercpu_intelmpi_18_576PE_36x36576163856.22775522.405316685.551601
25test_AM4_tigercpu_intelmpi_18_576PE_39x39576154054.77157221.308229675.795262
26test_AM4_tigercpu_intelmpi_18_576PE_39x39576154268.87055820.239546711.478426
27test_AM4_tigercpu_intelmpi_18_576PE_39x39576153992.37532021.641252665.395887
28test_AM4_tigercpu_intelmpi_18_576PE_40x40576154072.25933721.216723678.709889
29test_AM4_tigercpu_intelmpi_18_576PE_40x40576153900.29136122.152191650.048560
30test_AM4_tigercpu_intelmpi_18_576PE_40x40576153796.82544722.755853632.804241
31test_AM4_tigercpu_intelmpi_18_576PE_40x40576154044.33902621.363194674.056504
32test_AM4_tigercpu_intelmpi_18_576PE_40x40576154062.51797921.267598677.086330
33test_AM4_tigercpu_intelmpi_18_576PE_40x40576154031.69289421.430204671.948816
34test_AM4_tigercpu_intelmpi_18_768PE_36x36768223279.45700326.345825801.645045
35test_AM4_tigercpu_intelmpi_18_768PE_36x36768223320.89603426.017075811.774586
36test_AM4_tigercpu_intelmpi_18_768PE_36x36768223295.35229726.218745805.530561
37test_AM4_tigercpu_intelmpi_18_768PE_40x40768203451.49082925.032661766.997962
38test_AM4_tigercpu_intelmpi_18_768PE_40x40768203325.07154025.984403738.904787
39test_AM4_tigercpu_intelmpi_18_768PE_40x40768203402.55524225.392681756.123387
40test_AM4_tigercpu_intelmpi_18_864PE_36x36864242953.21509929.256250787.524026
41test_AM4_tigercpu_intelmpi_18_864PE_36x36864242904.18843429.750136774.450249
42test_AM4_tigercpu_intelmpi_18_864PE_36x36864242903.21376029.760123774.190336
43test_AM4_tigercpu_intelmpi_18_864PE_40x40864223226.23206526.780467788.634505
44test_AM4_tigercpu_intelmpi_18_864PE_40x40864223134.48370327.564348766.207127
45test_AM4_tigercpu_intelmpi_18_864PE_40x40864223104.54905427.830129758.889769
\n", "
" ], "text/plain": [ " expname ntasks-per-node tot_pes \\\n", "0 test_AM4_tigercpu_intelmpi_18_288PE_36x 36 288 \n", "1 test_AM4_tigercpu_intelmpi_18_288PE_40x 40 288 \n", "2 test_AM4_tigercpu_intelmpi_18_384PE_36x 36 384 \n", "3 test_AM4_tigercpu_intelmpi_18_384PE_36x 36 384 \n", "4 test_AM4_tigercpu_intelmpi_18_384PE_36x 36 384 \n", "5 test_AM4_tigercpu_intelmpi_18_384PE_40x 40 384 \n", "6 test_AM4_tigercpu_intelmpi_18_384PE_40x 40 384 \n", "7 test_AM4_tigercpu_intelmpi_18_384PE_40x 40 384 \n", "8 test_AM4_tigercpu_intelmpi_18_432PE_36x 36 432 \n", "9 test_AM4_tigercpu_intelmpi_18_432PE_36x 36 432 \n", "10 test_AM4_tigercpu_intelmpi_18_432PE_36x 36 432 \n", "11 test_AM4_tigercpu_intelmpi_18_432PE_36x 36 432 \n", "12 test_AM4_tigercpu_intelmpi_18_432PE_36x 36 432 \n", "13 test_AM4_tigercpu_intelmpi_18_432PE_36x 36 432 \n", "14 test_AM4_tigercpu_intelmpi_18_432PE_40x 40 432 \n", "15 test_AM4_tigercpu_intelmpi_18_432PE_40x 40 432 \n", "16 test_AM4_tigercpu_intelmpi_18_432PE_40x 40 432 \n", "17 test_AM4_tigercpu_intelmpi_18_432PE_40x 40 432 \n", "18 test_AM4_tigercpu_intelmpi_18_432PE_40x 40 432 \n", "19 test_AM4_tigercpu_intelmpi_18_576PE_36x 36 576 \n", "20 test_AM4_tigercpu_intelmpi_18_576PE_36x 36 576 \n", "21 test_AM4_tigercpu_intelmpi_18_576PE_36x 36 576 \n", "22 test_AM4_tigercpu_intelmpi_18_576PE_36x 36 576 \n", "23 test_AM4_tigercpu_intelmpi_18_576PE_36x 36 576 \n", "24 test_AM4_tigercpu_intelmpi_18_576PE_36x 36 576 \n", "25 test_AM4_tigercpu_intelmpi_18_576PE_39x 39 576 \n", "26 test_AM4_tigercpu_intelmpi_18_576PE_39x 39 576 \n", "27 test_AM4_tigercpu_intelmpi_18_576PE_39x 39 576 \n", "28 test_AM4_tigercpu_intelmpi_18_576PE_40x 40 576 \n", "29 test_AM4_tigercpu_intelmpi_18_576PE_40x 40 576 \n", "30 test_AM4_tigercpu_intelmpi_18_576PE_40x 40 576 \n", "31 test_AM4_tigercpu_intelmpi_18_576PE_40x 40 576 \n", "32 test_AM4_tigercpu_intelmpi_18_576PE_40x 40 576 \n", "33 test_AM4_tigercpu_intelmpi_18_576PE_40x 40 576 \n", "34 test_AM4_tigercpu_intelmpi_18_768PE_36x 36 768 \n", "35 test_AM4_tigercpu_intelmpi_18_768PE_36x 36 768 \n", "36 test_AM4_tigercpu_intelmpi_18_768PE_36x 36 768 \n", "37 test_AM4_tigercpu_intelmpi_18_768PE_40x 40 768 \n", "38 test_AM4_tigercpu_intelmpi_18_768PE_40x 40 768 \n", "39 test_AM4_tigercpu_intelmpi_18_768PE_40x 40 768 \n", "40 test_AM4_tigercpu_intelmpi_18_864PE_36x 36 864 \n", "41 test_AM4_tigercpu_intelmpi_18_864PE_36x 36 864 \n", "42 test_AM4_tigercpu_intelmpi_18_864PE_36x 36 864 \n", "43 test_AM4_tigercpu_intelmpi_18_864PE_40x 40 864 \n", "44 test_AM4_tigercpu_intelmpi_18_864PE_40x 40 864 \n", "45 test_AM4_tigercpu_intelmpi_18_864PE_40x 40 864 \n", "\n", " tot_nodes tot_spmy tot_throughput tot_cost \n", "0 8 6892.295777 12.535736 612.648514 \n", "1 8 7147.200836 12.088649 635.306741 \n", "2 11 5539.359889 15.597470 677.032875 \n", "3 11 5463.063406 15.815302 667.707750 \n", "4 11 5425.061974 15.926085 663.063130 \n", "5 10 5867.415356 14.725394 651.935040 \n", "6 10 5711.345915 15.127783 634.593991 \n", "7 10 5638.247302 15.323911 626.471922 \n", "8 12 4907.505858 17.605685 654.334114 \n", "9 12 4895.485138 17.648915 652.731352 \n", "10 12 4815.065687 17.943680 642.008758 \n", "11 12 4768.180008 18.120121 635.757334 \n", "12 12 4945.333923 17.471014 659.377856 \n", "13 12 4914.478885 17.580704 655.263851 \n", "14 11 5318.315046 16.245747 650.016283 \n", "15 11 5302.630319 16.293800 648.099261 \n", "16 11 5301.272296 16.297974 647.933281 \n", "17 11 5341.860761 16.174139 652.894093 \n", "18 11 5221.829098 16.545926 638.223556 \n", "19 16 3970.528853 21.760325 705.871796 \n", "20 16 3900.488559 22.151071 693.420188 \n", "21 16 3891.663093 22.201305 691.851217 \n", "22 16 3883.847742 22.245980 690.461821 \n", "23 16 3933.331196 21.966114 699.258879 \n", "24 16 3856.227755 22.405316 685.551601 \n", "25 15 4054.771572 21.308229 675.795262 \n", "26 15 4268.870558 20.239546 711.478426 \n", "27 15 3992.375320 21.641252 665.395887 \n", "28 15 4072.259337 21.216723 678.709889 \n", "29 15 3900.291361 22.152191 650.048560 \n", "30 15 3796.825447 22.755853 632.804241 \n", "31 15 4044.339026 21.363194 674.056504 \n", "32 15 4062.517979 21.267598 677.086330 \n", "33 15 4031.692894 21.430204 671.948816 \n", "34 22 3279.457003 26.345825 801.645045 \n", "35 22 3320.896034 26.017075 811.774586 \n", "36 22 3295.352297 26.218745 805.530561 \n", "37 20 3451.490829 25.032661 766.997962 \n", "38 20 3325.071540 25.984403 738.904787 \n", "39 20 3402.555242 25.392681 756.123387 \n", "40 24 2953.215099 29.256250 787.524026 \n", "41 24 2904.188434 29.750136 774.450249 \n", "42 24 2903.213760 29.760123 774.190336 \n", "43 22 3226.232065 26.780467 788.634505 \n", "44 22 3134.483703 27.564348 766.207127 \n", "45 22 3104.549054 27.830129 758.889769 " ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# data\n", "cases = glob.glob('???PE_??x')\n", "cases.sort()\n", "csv_file = 'wy_AM4_PE_scale.csv'\n", "try:\n", " 1/0\n", " df = pd.read_csv(csv_file)\n", " print('DataFrame loaded from', csv_file)\n", "except:\n", " df = get_dataframe(cases)\n", " df.to_csv(csv_file)\n", " print('DataFrame created for cases:', cases)\n", "df" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "ExecuteTime": { "end_time": "2018-11-29T16:05:44.909249Z", "start_time": "2018-11-29T16:05:44.388652Z" }, "code_folding": [ 0 ], "scrolled": false }, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('