MCPcopy
hub / github.com/microsoft/SandDance / onDataChanged

Method onDataChanged

packages/sanddance/src/viewer.ts:202–265  ·  view source on GitHub ↗
(dataLayout: DataLayoutChange, filter?: Search)

Source from the content-addressed store, hash-verified

200 }
201
202 private async onDataChanged(dataLayout: DataLayoutChange, filter?: Search) {
203 switch (dataLayout) {
204 case DataLayoutChange.same: {
205 this.renderSameLayout();
206 break;
207 }
208 case DataLayoutChange.refine: {
209 //save cube colors
210 const oldColorContext = this.colorContexts[this.currentColorContext];
211 let colorMap: ColorMap;
212 await this.renderNewLayout({}, {
213 preStage: (stage: VegaDeckGl.types.Stage, deckProps: VegaDeckGl.DeckProps) => {
214 //save off the spec colors
215 colorMap = colorMapFromCubes(stage.cubeData);
216 applyColorMapToCubes([oldColorContext.colorMap], VegaDeckGl.util.getCubes(deckProps));
217 this.preStage(stage, deckProps);
218 },
219 onPresent: () => {
220 //save new legend
221 const newColorContext: ColorContext = {
222 colorMap,
223 legend: VegaDeckGl.util.clone(this.presenter.stage.legend),
224 legendElement: this.presenter.getElement(VegaDeckGl.PresenterElement.legend).children[0] as HTMLElement,
225 };
226 //apply old legend
227 this.applyLegendColorContext(oldColorContext);
228 this.changeColorContexts([oldColorContext, newColorContext]);
229 },
230 });
231
232 //narrow the filter only if it is different
233 if (!searchExpression.compare(this.insight.filter, filter)) {
234 this.insight.filter = searchExpression.narrow(this.insight.filter, filter);
235 }
236 if (this.options.onDataFilter) {
237 this.options.onDataFilter(this.insight.filter, this._dataScope.currentData());
238 }
239 break;
240 }
241 case DataLayoutChange.reset: {
242 const colorContext: ColorContext = {
243 colorMap: null,
244 legend: null,
245 legendElement: null,
246 };
247 this.changeColorContexts([colorContext]);
248 await this.renderNewLayout({}, {
249 onPresent: () => {
250 populateColorContext(colorContext, this.presenter);
251 },
252 });
253
254 delete this.insight.filter;
255 if (this.options.onDataFilter) {
256 this.options.onDataFilter(null, null);
257 }
258 break;
259 }

Callers 6

selectMethod · 0.45
deselectMethod · 0.45
filterMethod · 0.45
resetMethod · 0.45
activateMethod · 0.45
deactivateMethod · 0.45

Calls 12

renderSameLayoutMethod · 0.95
renderNewLayoutMethod · 0.95
preStageMethod · 0.95
changeColorContextsMethod · 0.95
getSelectionMethod · 0.95
colorMapFromCubesFunction · 0.90
applyColorMapToCubesFunction · 0.90
populateColorContextFunction · 0.90
cloneMethod · 0.45
getElementMethod · 0.45
currentDataMethod · 0.45

Tested by

no test coverage detected