<commit_before>/*-
 * Copyright 2016 Diamond Light Source Ltd.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.eclipse.dawnsci.plotting.api.trace;

import java.util.Arrays;
import java.util.List;

import org.eclipse.dawnsci.plotting.api.IPlottingSystem;
import org.eclipse.january.DatasetException;
import org.eclipse.january.dataset.IDataset;
import org.eclipse.january.dataset.ILazyDataset;
import org.eclipse.january.dataset.Slice;
import org.eclipse.january.metadata.AxesMetadata;
import org.eclipse.january.metadata.MaskMetadata;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;

public class MetadataPlotUtils {

	
	public static void plotDataWithMetadata(IDataset data, final IPlottingSystem<?> system) {
		plotDataWithMetadata(data, system, true);
	}
	
	public static void plotDataWithMetadata(IDataset data, final IPlottingSystem<?> system, boolean clear) {
		
		IDataset x = null;
		IDataset y = null;
		IDataset mask = null;
		
		data = data.getSliceView().squeeze();
		
		IDataset[] axes = getAxesFromMetadata(data);
		
		MaskMetadata mmd = data.getFirstMetadata(MaskMetadata.class);
		
		if (mmd != null ) {
			mask = mmd.getMask().getSlice().squeeze();
		}
		
		if (data.getRank() == 2) {
			if (!system.is2D()) system.clear();
			x = axes == null ? null : axes[0];
			y = axes == null ? null : axes[1];
			
			if (x != null && x.getRank() == 2) {
				x = x.getSlice((Slice)null,new Slice(0,1)).squeeze();
			}
			if (y != null && y.getRank() == 2) {
				y = y.getSlice(new Slice(0,1),(Slice)null).squeeze();
			}
			
			
			final ITrace t = system.updatePlot2D(data, Arrays.asList(new IDataset[]{y,x}), null);
				
			final IDataset m = mask;

			Display.getDefault().syncExec(new Runnable() {

				@Override
				public void run() {
					if (t == null) return;
					((IImageTrace)t).setMask(m);
					if (!system.isDisposed())system.repaint();
				}
			});
				
			
		} else if (data.getRank() == 1) {
			x = axes == null ? null : axes[0];
			if (clear) system.clear();
			system.updatePlot1D(x,Arrays.asList(new IDataset[]{data}),null);
		}
		
	}<commit_msg>remove slice from axes names<commit_after>/*-
 * Copyright 2016 Diamond Light Source Ltd.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.eclipse.dawnsci.plotting.api.trace;

import java.util.Arrays;
import java.util.List;

import org.eclipse.dawnsci.plotting.api.IPlottingSystem;
import org.eclipse.january.DatasetException;
import org.eclipse.january.dataset.IDataset;
import org.eclipse.january.dataset.ILazyDataset;
import org.eclipse.january.dataset.Slice;
import org.eclipse.january.metadata.AxesMetadata;
import org.eclipse.january.metadata.MaskMetadata;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;

public class MetadataPlotUtils {

	
	public static void plotDataWithMetadata(IDataset data, final IPlottingSystem<?> system) {
		plotDataWithMetadata(data, system, true);
	}
	
	public static void plotDataWithMetadata(IDataset data, final IPlottingSystem<?> system, boolean clear) {
		
		IDataset x = null;
		IDataset y = null;
		IDataset mask = null;
		
		data = data.getSliceView().squeeze();
		
		IDataset[] axes = getAxesFromMetadata(data);
		
		MaskMetadata mmd = data.getFirstMetadata(MaskMetadata.class);
		
		if (mmd != null ) {
			mask = mmd.getMask().getSlice().squeeze();
		}
		
		if (data.getRank() == 2) {
			if (!system.is2D()) system.clear();
			x = axes == null ? null : axes[0];
			y = axes == null ? null : axes[1];
			
			if (x != null && x.getRank() == 2) {
				x = x.getSlice((Slice)null,new Slice(0,1)).squeeze();
			}
			if (y != null && y.getRank() == 2) {
				y = y.getSlice(new Slice(0,1),(Slice)null).squeeze();
			}
			
			if (x != null) x.setName(removeSquareBrackets(x.getName()));
			if (y != null) y.setName(removeSquareBrackets(y.getName()));
			
			final ITrace t = system.updatePlot2D(data, Arrays.asList(new IDataset[]{y,x}), null);
				
			final IDataset m = mask;

			Display.getDefault().syncExec(new Runnable() {

				@Override
				public void run() {
					if (t == null) return;
					((IImageTrace)t).setMask(m);
					if (!system.isDisposed())system.repaint();
				}
			});
				
			
		} else if (data.getRank() == 1) {
			x = axes == null ? null : axes[0];
			if (x != null) x.setName(removeSquareBrackets(x.getName()));
			if (clear) system.reset();
			system.updatePlot1D(x,Arrays.asList(new IDataset[]{data}),null);
		}
		
	}
{'fraction_non_alphanumeric': 0.1443872296601442, 'fraction_numerical': 0.00906282183316169, 'mean_word_length': 3.7375609756097563, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6445384', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1616, 'n_words': 370}