svghmi/pythonic.js
author Edouard Tisserant
Wed, 11 May 2022 12:12:16 +0200
changeset 3484 32eaba9cf30e
child 3485 5f417d3c2d03
permissions -rw-r--r--
SVGHMI: many fixes on xy trend graph. WIP.
3484
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
     1
/*
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
     2
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
     3
From https://github.com/keyvan-m-sadeghi/pythonic
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
     4
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
     5
Slightly modified in order to be usable in browser (i.e. not as a node.js module)
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
     6
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
     7
The MIT License (MIT)
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
     8
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
     9
Copyright (c) 2016 Assister.Ai
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    10
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    11
Permission is hereby granted, free of charge, to any person obtaining a copy of
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    12
this software and associated documentation files (the "Software"), to deal in
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    13
the Software without restriction, including without limitation the rights to
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    14
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    15
the Software, and to permit persons to whom the Software is furnished to do so,
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    16
subject to the following conditions:
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    17
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    18
The above copyright notice and this permission notice shall be included in all
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    19
copies or substantial portions of the Software.
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    20
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    21
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    22
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    23
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    24
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    25
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    26
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    27
*/
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    28
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    29
class Iterator {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    30
    constructor(generator) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    31
        this[Symbol.iterator] = generator;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    32
    }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    33
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    34
    async * [Symbol.asyncIterator]() {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    35
        for (const element of this) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    36
            yield await element;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    37
        }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    38
    }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    39
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    40
    map(callback) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    41
        const result = [];
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    42
        for (const element of this) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    43
            result.push(callback(element));
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    44
        }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    45
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    46
        return result;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    47
    }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    48
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    49
    filter(callback) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    50
        const result = [];
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    51
        for (const element of this) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    52
            if (callback(element)) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    53
                result.push(element);
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    54
            }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    55
        }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    56
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    57
        return result;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    58
    }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    59
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    60
    reduce(callback, initialValue) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    61
        let empty = typeof initialValue === 'undefined';
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    62
        let accumulator = initialValue;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    63
        let index = 0;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    64
        for (const currentValue of this) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    65
            if (empty) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    66
                accumulator = currentValue;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    67
                empty = false;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    68
                continue;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    69
            }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    70
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    71
            accumulator = callback(accumulator, currentValue, index, this);
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    72
            index++;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    73
        }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    74
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    75
        if (empty) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    76
            throw new TypeError('Reduce of empty Iterator with no initial value');
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    77
        }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    78
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    79
        return accumulator;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    80
    }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    81
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    82
    some(callback) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    83
        for (const element of this) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    84
            if (callback(element)) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    85
                return true;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    86
            }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    87
        }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    88
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    89
        return false;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    90
    }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    91
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    92
    every(callback) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    93
        for (const element of this) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    94
            if (!callback(element)) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    95
                return false;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    96
            }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    97
        }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    98
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
    99
        return true;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   100
    }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   101
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   102
    static fromIterable(iterable) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   103
        return new Iterator(function * () {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   104
            for (const element of iterable) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   105
                yield element;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   106
            }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   107
        });
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   108
    }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   109
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   110
    toArray() {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   111
        return Array.from(this);
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   112
    }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   113
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   114
    next() {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   115
        if (!this.currentInvokedGenerator) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   116
            this.currentInvokedGenerator = this[Symbol.iterator]();
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   117
        }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   118
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   119
        return this.currentInvokedGenerator.next();
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   120
    }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   121
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   122
    reset() {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   123
        delete this.currentInvokedGenerator;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   124
    }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   125
}
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   126
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   127
function rangeSimple(stop) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   128
    return new Iterator(function * () {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   129
        for (let i = 0; i < stop; i++) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   130
            yield i;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   131
        }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   132
    });
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   133
}
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   134
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   135
function rangeOverload(start, stop, step = 1) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   136
    return new Iterator(function * () {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   137
        for (let i = start; i < stop; i += step) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   138
            yield i;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   139
        }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   140
    });
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   141
}
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   142
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   143
function range(...args) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   144
    if (args.length < 2) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   145
        return rangeSimple(...args);
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   146
    }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   147
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   148
    return rangeOverload(...args);
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   149
}
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   150
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   151
function enumerate(iterable) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   152
    return new Iterator(function * () {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   153
        let index = 0;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   154
        for (const element of iterable) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   155
            yield [index, element];
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   156
            index++;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   157
        }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   158
    });
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   159
}
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   160
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   161
const _zip = longest => (...iterables) => {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   162
    if (iterables.length < 2) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   163
        throw new TypeError("zip takes 2 iterables at least, "+iterables.length+" given");
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   164
    }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   165
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   166
    return new Iterator(function * () {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   167
        const iterators = iterables.map(iterable => Iterator.fromIterable(iterable));
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   168
        while (true) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   169
            const row = iterators.map(iterator => iterator.next());
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   170
            const check = longest ? row.every.bind(row) : row.some.bind(row);
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   171
            if (check(next => next.done)) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   172
                return;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   173
            }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   174
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   175
            yield row.map(next => next.value);
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   176
        }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   177
    });
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   178
};
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   179
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   180
const zip = _zip(false), zipLongest= _zip(true);
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   181
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   182
function items(obj) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   183
    let {keys, get} = obj;
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   184
    if (obj instanceof Map) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   185
        keys = keys.bind(obj);
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   186
        get = get.bind(obj);
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   187
    } else {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   188
        keys = function () {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   189
            return Object.keys(obj);
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   190
        };
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   191
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   192
        get = function (key) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   193
            return obj[key];
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   194
        };
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   195
    }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   196
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   197
    return new Iterator(function * () {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   198
        for (const key of keys()) {
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   199
            yield [key, get(key)];
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   200
        }
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   201
    });
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   202
}
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   203
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   204
/*
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   205
module.exports = {Iterator, range, enumerate, zip: _zip(false), zipLongest: _zip(true), items};
32eaba9cf30e SVGHMI: many fixes on xy trend graph. WIP.
Edouard Tisserant
parents:
diff changeset
   206
*/