<commit_before>'use strict';

var createSurface = require('gl-surface3d'),
    ndarray = require('ndarray'),
    homography = require('ndarray-homography'),
    fill = require('ndarray-fill'),
    ops  = require('ndarray-ops'),
    str2RgbaArray = require('../lib/str2rgbarray'),
    tinycolor = require('tinycolor2');

var MIN_RESOLUTION = 128;

function SurfaceTrace(scene, surface, uid) {
  this.scene    = scene;
  this.uid      = uid;
  this.surface  = surface;
  this.data     = null;
  this.showContour = [false,false,false];
  this.dataScale = 1.0;
}

var proto = SurfaceTrace.prototype;

proto.handlePick = function(selection) {
  if(selection.object === this.surface) {
    var selectIndex = [
      Math.min(Math.round(selection.data.index[0]/this.dataScale-1)|0, this.data.z[0].length-1),
      Math.min(Math.round(selection.data.index[1]/this.dataScale-1)|0, this.data.z.length-1) ];
    var traceCoordinate = [0,0,0];
    if(Array.isArray(this.data.x[0])) {
      traceCoordinate[0] = this.data.x[selectIndex[1]][selectIndex[0]];
    } else {
      traceCoordinate[0] = this.data.x[selectIndex[0]];
    }
    if(Array.isArray(this.data.y[0])) {
      traceCoordinate[1] = this.data.y[selectIndex[1]][selectIndex[0]];
    } else {
      traceCoordinate[1] = this.data.y[selectIndex[1]];
    }
    traceCoordinate[2] = this.data.z[selectIndex[1]][selectIndex[0]];
    selection.traceCoordinate = traceCoordinate;

    selection.dataCoordinate = [
      traceCoordinate[0]*this.scene.dataScale[0] - this.scene.dataCenter[0],
      traceCoordinate[1]*this.scene.dataScale[1] - this.scene.dataCenter[1],
      traceCoordinate[2]*this.scene.dataScale[2] - this.scene.dataCenter[2]
    ];

    selection.data.dataCoordinate = selection.dataCoordinate.slice();

    this.surface.highlight(selection.data);

    //Snap spikes to data coordinate
    this.scene.glplot.spikes.position = selection.dataCoordinate;

    return true;
  }<commit_msg>fix up surface plot highlight breaking with categorical axes<commit_after>'use strict';

var createSurface = require('gl-surface3d'),
    ndarray = require('ndarray'),
    homography = require('ndarray-homography'),
    fill = require('ndarray-fill'),
    ops  = require('ndarray-ops'),
    str2RgbaArray = require('../lib/str2rgbarray'),
    tinycolor = require('tinycolor2');

var MIN_RESOLUTION = 128;

function SurfaceTrace(scene, surface, uid) {
  this.scene    = scene;
  this.uid      = uid;
  this.surface  = surface;
  this.data     = null;
  this.showContour = [false,false,false];
  this.dataScale = 1.0;
}

var proto = SurfaceTrace.prototype;

proto.handlePick = function(selection) {
  if(selection.object === this.surface) {
    var selectIndex = [
      Math.min(Math.round(selection.data.index[0]/this.dataScale-1)|0, this.data.z[0].length-1),
      Math.min(Math.round(selection.data.index[1]/this.dataScale-1)|0, this.data.z.length-1) ];
    var traceCoordinate = [0,0,0];
    if(Array.isArray(this.data.x[0])) {
      traceCoordinate[0] = this.data.x[selectIndex[1]][selectIndex[0]];
    } else {
      traceCoordinate[0] = this.data.x[selectIndex[0]];
    }
    if(Array.isArray(this.data.y[0])) {
      traceCoordinate[1] = this.data.y[selectIndex[1]][selectIndex[0]];
    } else {
      traceCoordinate[1] = this.data.y[selectIndex[1]];
    }
    traceCoordinate[2] = this.data.z[selectIndex[1]][selectIndex[0]];
    selection.traceCoordinate = traceCoordinate;

    var sceneLayout = this.scene.fullSceneLayout;
    selection.dataCoordinate = [
      sceneLayout.xaxis.d2l(traceCoordinate[0])*this.scene.dataScale[0] - this.scene.dataCenter[0],
      sceneLayout.yaxis.d2l(traceCoordinate[1])*this.scene.dataScale[1] - this.scene.dataCenter[1],
      sceneLayout.zaxis.d2l(traceCoordinate[2])*this.scene.dataScale[2] - this.scene.dataCenter[2]
    ];

    selection.data.dataCoordinate = selection.dataCoordinate.slice();

    this.surface.highlight(selection.data);

    //Snap spikes to data coordinate
    this.scene.glplot.spikes.position = selection.dataCoordinate;

    return true;
  }
{'fraction_non_alphanumeric': 0.1579724409448819, 'fraction_numerical': 0.022883858267716536, 'mean_word_length': 3.8335315101070155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6985308', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1384, 'n_words': 185}