MCPcopy Index your code
hub / github.com/bqplot/bqplot / update_data

Method update_data

js/src/BarsModel.ts:96–172  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

94 }
95
96 update_data() {
97 let x_data = this.get('x');
98 let y_data = this.get('y');
99 y_data = y_data.length === 0 || !_.isNumber(y_data[0]) ? y_data : [y_data];
100
101 this.baseValue = this.get('base');
102 if (this.baseValue === undefined || this.baseValue === null) {
103 this.baseValue = 0;
104 }
105
106 if (x_data.length === 0 || y_data.length === 0) {
107 this.mark_data = [];
108 this.yIs2d = false;
109 } else {
110 x_data = x_data.slice(0, d3.min(y_data.map((d) => d.length)));
111
112 // since x_data may be a TypedArray, explicitly use Array.map
113 this.mark_data = Array.prototype.map.call(x_data, (x_elem, index) => {
114 const data: any = {};
115 data.key = x_elem;
116
117 // split bins into positive ( value > baseValue) and negative, and stack those separately
118 // accumulates size/height of histogram values for stacked histograms
119 let cumulativePos = this.baseValue;
120 let cumulativeNeg = this.baseValue;
121
122 // since y_data may be a TypedArray, explicitly use Array.map
123 data.values = Array.prototype.map.call(y_data, (y_elem, y_index) => {
124 // y0, y1 are the upper and lower bound of the bars and
125 // only relevant for a stacked bar chart. grouped
126 // bars only deal with baseValue and y.
127
128 let y0, y1;
129 const value = isNaN(y_elem[index])
130 ? 0
131 : y_elem[index] - this.baseValue;
132
133 if (value >= 0) {
134 y0 = cumulativePos;
135 if (!isNaN(y_elem[index])) {
136 cumulativePos += value;
137 }
138 y1 = cumulativePos;
139 } else {
140 // reverse y1 and y0 to not have negative heights
141 y1 = cumulativeNeg;
142 if (!isNaN(y_elem[index])) {
143 cumulativeNeg += value;
144 }
145 y0 = cumulativeNeg;
146 }
147
148 return {
149 index: index,
150 subIndex: y_index,
151 x: x_elem,
152 y0,
153 y1,

Callers 1

initializeMethod · 0.95

Calls 2

update_colorMethod · 0.95
update_domainsMethod · 0.95

Tested by

no test coverage detected