()
| 64 | } |
| 65 | |
| 66 | update_data() { |
| 67 | this.dirty = true; |
| 68 | // Handling data updates |
| 69 | const that = this; |
| 70 | this.x_data = this.get('x'); |
| 71 | this.y_data = this.get('y'); |
| 72 | this.color_data = this.get('color') || []; |
| 73 | |
| 74 | let curve_labels = this.get('labels'); |
| 75 | if (this.x_data.length === 0 || this.y_data.length === 0) { |
| 76 | this.mark_data = []; |
| 77 | } else { |
| 78 | this.x_data = utils.is_array(this.x_data[0]) |
| 79 | ? this.x_data |
| 80 | : [this.x_data]; |
| 81 | this.y_data = utils.is_array(this.y_data[0]) |
| 82 | ? this.y_data |
| 83 | : [this.y_data]; |
| 84 | curve_labels = this.get_labels(); |
| 85 | |
| 86 | const y_length = this.y_data.length; |
| 87 | |
| 88 | if (this.x_data.length == 1 && y_length > 1) { |
| 89 | // same x for all y |
| 90 | this.mark_data = curve_labels.map((name, i) => { |
| 91 | return { |
| 92 | name: name, |
| 93 | // since y_data may be a TypedArray, explicitly use Array.map |
| 94 | values: Array.prototype.map.call(that.y_data[i], (d, j) => { |
| 95 | return { |
| 96 | x: that.x_data[0][j], |
| 97 | y: d, |
| 98 | y0: that.y_data[Math.min(i + 1, y_length - 1)][j], |
| 99 | sub_index: j, |
| 100 | }; |
| 101 | }), |
| 102 | color: that.color_data[i], |
| 103 | index: i, |
| 104 | }; |
| 105 | }); |
| 106 | } else { |
| 107 | this.mark_data = curve_labels.map((name, i) => { |
| 108 | const xy_data = d3.zip(that.x_data[i], that.y_data[i]); |
| 109 | return { |
| 110 | name: name, |
| 111 | values: xy_data.map((d, j) => { |
| 112 | return { |
| 113 | x: d[0], |
| 114 | y: d[1], |
| 115 | y0: that.y_data[Math.min(i + 1, y_length - 1)][j], |
| 116 | sub_index: j, |
| 117 | }; |
| 118 | }), |
| 119 | color: that.color_data[i], |
| 120 | index: i, |
| 121 | }; |
| 122 | }); |
| 123 | } |
no test coverage detected