How to use the base/utils.warn function in base

To help you get started, we’ve selected a few base examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vizabi / vizabi / src / tools / bubblechart / bubblechart-panzoom.js View on Github external
expandCanvas(duration) {
    const _this = this.context;
    if (!duration) duration = _this.duration;

        //d3 extent returns min and max of the input array as [min, max]
    const mmX = d3.extent(utils.values(_this.frame.axis_x));
    const mmY = d3.extent(utils.values(_this.frame.axis_y));

        //protection agains unreasonable min-max results -- abort function
    if (!mmX[0] && mmX[0] !== 0 || !mmX[1] && mmX[1] !== 0 || !mmY[0] && mmY[0] !== 0 || !mmY[1] && mmY[1] !== 0) {
      return utils.warn("panZoom.expandCanvas: X or Y min/max are broken. Aborting with no action");
    }
        /*
         * Use a range bumped scale to correctly accommodate the range bump
         * gutter.
         */
    const suggestedFrame = {
      x1: _this.xScale(mmX[0]),
      y1: _this.yScale(mmY[0]),
      x2: _this.xScale(mmX[1]),
      y2: _this.yScale(mmY[1])
    };
    const xBounds = [0, _this.width];
    const yBounds = [_this.height, 0];

        // Get the current zoom frame based on the current dimensions.
    const frame = {
github vizabi / vizabi / src / models / time.js View on Github external
const tLimits = hook.getTimespan();
        if (tLimits && tLimits.min && tLimits.max) {

          if (!utils.isDate(tLimits.min) || !utils.isDate(tLimits.max))
            return utils.warn("checkTimeLimits(): min-max for hook " + hook._name + " look wrong: " + tLimits.min + " " + tLimits.max + ". Expecting Date objects. Ensure that time is properly parsed in the data from reader");

          minArray.push(tLimits.min);
          maxArray.push(tLimits.max);
        }
      });

      let min = d3.max(minArray);
      let max = d3.min(maxArray);

      if (min > max) {
        utils.warn("checkTimeLimits(): Availability of the indicator's data has no intersection. I give up and just return some valid time range where you'll find no data points. Enjoy!");
        min = d3.min(minArray);
        max = d3.max(maxArray);
      }

      // change start and end (but keep startOrigin and endOrigin for furhter requests)
      const newTime = {};
      if (this.start - min != 0 || !this.start && !this.startOrigin) newTime["start"] = min;
      if (this.end - max != 0 || !this.end && !this.endOrigin) newTime["end"] = max;

      if (this.startSelected == null) newTime["startSelected"] = min;
      if (this.endSelected == null) newTime["endSelected"] = max;

      // default to current date. Other option: newTime['start'] || newTime['end'] || time.start || time.end;
      if (this.value == null) newTime["value"] = this.parse(this.formatDate(new Date()));

      this.setTreeFreezer(true);
github vizabi / vizabi / src / base / data.js View on Github external
return new Promise(function(resolve, reject) {

      //TODO: thses should come from state or from outside somehow
      // FramesArray in the input contains the array of keyframes in animatable dimension.
      // Example: array of years like [1800, 1801 … 2100]
      // these will be the points where we need data
      // (some of which might already exist in the set. in regular datasets all the points would exist!)

      // Check if query.where clause is missing a time field

      var indicatorsDB = _this.getConceptprops();

      if(!indicatorsDB) utils.warn("_getFrames in data.js is missing indicatorsDB, it's needed for gap filling");
      if(!framesArray) utils.warn("_getFrames in data.js is missing framesArray, it's needed so much");

      var KEY = _this._collection[queryId].query.select.key[0];
      var TIME = _this._collection[queryId].query.animatable;

      var filtered = {};
      var items, itemsIndex, oneFrame, method, use, next;

      // We _nest_ the flat dataset in two levels: first by “key” (example: geo), then by “animatable” (example: year)
      // See the _getNested function for more details
      var nested = _this.get(queryId, 'nested', [KEY, TIME]);
      keys = keys ? keys : Object.keys(nested);
      // Get the list of columns that are in the dataset, exclude key column and animatable column
      // Example: [“lex”, “gdp”, “u5mr"]
      var query = _this._collection[queryId].query;
      var columns = query.select.value.filter(function(f){return f !== "_default"});
github vizabi / vizabi / src / base / datastorage.js View on Github external
this.checkQueryResponse = function(query, response) {
            if (response.length == 0) utils.warn("Reader for data source '" + this._name + "' returned empty array for query:", JSON.stringify(query, null, 2));

            if (response.length > 0) {
              // search data for the entirely missing columns
              const columnsMissing = (query.select.key || []).concat(query.select.value || []);
              for (let i = response.length - 1; i >= 0; i--) {
                for (let c = columnsMissing.length - 1; c >= 0; c--) {
                  // if found value for column c in row i then remove that column name from the list of missing columns
                  if (response[i][columnsMissing[c]] || response[i][columnsMissing[c]] === 0) columnsMissing.splice(c, 1);
                }
                // all columns were found to have value in at least one of the rows then stop iterating
                if (!columnsMissing.length) break;
              }
              columnsMissing.forEach(d => {
                if (query.select.key.indexOf(d) == -1) {
                  utils.warn("Reader result: Column '" + d + "' is missing from '" + query.from + "' data, but it might be ok");
                } else {
github vizabi / vizabi / src / tools / bubblechart / bubblechart-component.js View on Github external
_this.model.marker.getFrame(trailStartTime, valuesTrailStart => {
            if (!valuesTrailStart) return utils.warn("redrawDataPointsOnlySize: empty data received from marker.getFrames(). doing nothing");

            const cache = {};
            if (!_this.model.ui.chart.trails || trailStartTime - _this.time == 0) {
              cache.scaledS0 = scaledS;
            } else {
              cache.scaledS0 = utils.areaToRadius(_this.sScale(valuesTrailStart.size[d[KEY]]));
            }

            _this._labels.updateLabelOnlyPosition(d, index, cache);

          });
        }
github vizabi / vizabi / src / tools / bubblechart / bubblechart-trail.js View on Github external
{
            utils.warn("Frame for trail missed: " + segment.t);
            return resolve();
          }
          segment.valueY = frame.axis_y[d[KEY]];
          segment.valueX = frame.axis_x[d[KEY]];
          segment.valueS = frame.size[d[KEY]];
          segment.valueC = frame.color[d[KEY]];

          segment.previous = previousSegment;
          segment.next = nextSegment;
          previousSegment.next = segment;
          nextSegment.previous = segment;

          if (segment.valueY == null || segment.valueX == null || segment.valueS == null) {
            utils.warn("Data for trail point missed: " + segment.t);
            return resolve();
          }

          const strokeColor = _context.model.marker.color.which == "geo.world_4region" ?
            //use predefined shades for color palette for "geo.world_4region" (hardcoded)
            _context.model.marker.color.getColorShade({
              colorID: segment.valueC,
              shadeID: "shade"
            })
            :
            //otherwise use color of the bubble with a fallback to bubble stroke color (blackish)
            (segment.valueC != null ? _context.cScale(segment.valueC) : _context.COLOR_BLACKISH);

          const firstLineLength = Math.sqrt(
            Math.pow(_context.xScale(previousSegment.valueX) - _context.xScale(segment.valueX), 2) +
            Math.pow(_context.yScale(previousSegment.valueY) - _context.yScale(segment.valueX), 2)
github vizabi / vizabi / src / base / data.js View on Github external
r.read(query).then(function() {

          //success reading
          var values = r.getData();
          var q = query;
          if(values.length == 0) utils.warn("Reader returned empty array for query:", JSON.stringify(q, null, 2))

          if(values.length > 0) {
            //search data for the entirely missing columns
            var columnsMissing = (q.select.key||[]).concat(q.select.value||[]);
            for(var i = values.length-1; i>=0; i--){
              for(var c = columnsMissing.length-1; c>=0; c--){
                //if found value for column c in row i then remove that column name from the list of missing columns
                if(values[i][columnsMissing[c]] || values[i][columnsMissing[c]]===0) columnsMissing.splice(c,1);
              }
              //all columns were found to have value in at least one of the rows then stop iterating
              if(!columnsMissing.length) break;
            }
            columnsMissing.forEach(function(d){
              if(q.select.key.indexOf(d)==-1){
                utils.warn('Reader result: Column "' + d + '" is missing from "' + q.from + '" data, but it might be ok');
              }else{
github vizabi / vizabi / src / tools / bubblemap / bubblemap-component.js View on Github external
redrawDataPoints(duration, reposition) {
    const _this = this;
    if (!duration) duration = this.duration;
    if (!reposition) reposition = true;
    if (!this.entityBubbles) return utils.warn("redrawDataPoints(): no entityBubbles defined. likely a premature call, fix it!");
    this.entityBubbles.each(function(d, index) {
      const view = d3.select(this);
      const geo = d3.select("#" + d[_this.KEY]);

      const valueX = _this.values.hook_lng[d[_this.KEY]];
      const valueY = _this.values.hook_lat[d[_this.KEY]];
      const valueS = _this.values.size[d[_this.KEY]];
      const valueC = _this.values.color[d[_this.KEY]];
      const valueL = _this.values.label[d[_this.KEY]];

      d.hidden_1 = d.hidden;
      d.hidden = (!valueS && valueS !== 0) || valueX == null || valueY == null;


      if (d.hidden !== d.hidden_1) {
        if (duration) {
github vizabi / vizabi / src / readers / csv-time_in_columns / csv-time_in_columns.js View on Github external
.then(({ rows, columns }) => {
        const missedIndicator = parsers[this.timeKey] && !!parsers[this.timeKey](columns[this.keySize]);
        if (missedIndicator) warn("Indicator column is missed.");
        const indicatorKey = missedIndicator ? this.MISSED_INDICATOR_NAME : columns[this.keySize];

        const concepts = columns.slice(0, this.keySize).concat(missedIndicator ? capitalize(this.MISSED_INDICATOR_NAME) : rows.reduce((result, row) => {
          const concept = row[indicatorKey];
          if (!result.includes(concept) && concept) {
            result.push(concept);
          }
          return result;
        }, []));
        concepts.splice(this.keySize, 0, this.timeKey);

        const indicators = concepts.slice(this.keySize + 1);
        const [entityDomain] = concepts;
        return {
          columns: concepts,
          rows: rows.reduce((result, row) => {
github vizabi / vizabi / src / models / locale.js View on Github external
getUIString(stringId) {
    if (this.strings && this.strings[this.id] && (this.strings[this.id][stringId] || this.strings[this.id][stringId] === "")) {
      return this.strings[this.id][stringId];
    }
    if (!this.strings || !this.strings[this.id]) utils.warn("Strings are not loaded for the " + this.id + " locale. Check if translation JSON is valid");
    return stringId;
  },