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

Method update_color

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

Source from the content-addressed store, hash-verified

176 }
177
178 update_color() {
179 //Function to update the color attribute for the data. In scatter,
180 //this is taken care of by the update_data itself. This is separate
181 //in bars because update data does a lot more complex calculations
182 //which should be avoided when possible
183 if (!this.mark_data) {
184 return;
185 }
186 const color = this.get('color') || [];
187 const color_scale = this.getScales().color;
188 const color_mode = this.get('color_mode');
189 const apply_color_to_groups =
190 color_mode === 'group' || (color_mode === 'auto' && !this.yIs2d);
191 const apply_color_to_group_element =
192 color_mode === 'element' || (color_mode === 'auto' && this.yIs2d);
193
194 const opacity_mode = this.get('opacity_mode');
195 const apply_opacity_to_groups =
196 opacity_mode === 'group' || (opacity_mode === 'auto' && !this.yIs2d);
197 const apply_opacity_to_group_element =
198 opacity_mode === 'element' || (opacity_mode === 'auto' && this.yIs2d);
199
200 let element_idx = 0;
201 this.mark_data.forEach((single_bar_d, bar_grp_index) => {
202 single_bar_d.values.forEach((bar_d, bar_index) => {
203 bar_d.colorIndex = apply_color_to_groups
204 ? bar_grp_index
205 : apply_color_to_group_element
206 ? bar_index
207 : element_idx;
208 bar_d.opacityIndex = apply_opacity_to_groups
209 ? bar_grp_index
210 : apply_opacity_to_group_element
211 ? bar_index
212 : element_idx;
213 bar_d.color = color[bar_d.colorIndex];
214
215 element_idx++;
216 });
217 });
218
219 if (color_scale && color.length > 0) {
220 if (!this.get('preserve_domain').color) {
221 color_scale.computeAndSetDomain(color, this.model_id + '_color');
222 } else {
223 color_scale.delDomain([], this.model_id + '_color');
224 }
225 }
226 }
227
228 update_domains() {
229 if (!this.mark_data) {

Callers 2

initializeMethod · 0.95
update_dataMethod · 0.95

Calls 1

getScalesMethod · 0.45

Tested by

no test coverage detected