Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vega-tooltip

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vega-tooltip - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

2

bower.json
{
"name": "vega-tooltip",
"version": "0.1.1",
"version": "0.1.2",
"description": "A tooltip plugin for vega-lite and vega visualizations.",

@@ -5,0 +5,0 @@ "main": [

{
"name": "vega-tooltip",
"version": "0.1.1",
"version": "0.1.2",
"description": "A tooltip plugin for vega-lite and vega visualizations.",

@@ -5,0 +5,0 @@ "main": "src/vg-tooltip.js",

@@ -161,3 +161,3 @@ "use strict";

// supplement the fieldOption with fieldDef and config
var supplementedFieldOption = supplementFieldOption(fieldOption, fieldDef, vlSpec.config);
var supplementedFieldOption = supplementFieldOption(fieldOption, fieldDef, vlSpec);

@@ -175,3 +175,3 @@ supplementedFields.push(supplementedFieldOption);

// supplement the fieldOption with fieldDef and config
var supplementedFieldOption = supplementFieldOption(fieldOption, fieldDef, vlSpec.config);
var supplementedFieldOption = supplementFieldOption(fieldOption, fieldDef, vlSpec);

@@ -277,5 +277,5 @@ supplementedFields.push(supplementedFieldOption);

*/
function supplementFieldOption(fieldOption, fieldDef, config) {
function supplementFieldOption(fieldOption, fieldDef, vlSpec) {
// many specs don't have config
if (!config) config = {};
var config = vlSpec.config ? vlSpec.config : {};

@@ -295,4 +295,6 @@ // at least one of fieldOption and fieldDef should exist

// supplement field name with underscore prefixes and suffixes to match the field names in item.datum
// for aggregation and timeUnit, this will add prefix "mean_", "yearmonth_"
// supplement a user-provided field name with underscore prefixes and suffixes to
// match the field names in item.datum
// for aggregation, this will add prefix "mean_" etc.
// for timeUnit, this will add prefix "yearmonth_" etc.
// for bin, this will add prefix "bin_" and suffix "_start". Later we will replace "_start" with "_range".

@@ -302,2 +304,25 @@ supplementedFieldOption.field = fieldDef.field ?

// If a fieldDef is a (TIMEUNIT)T, we check if the original T is present in the vlSpec.
// If only (TIMEUNIT)T is present in vlSpec, we set `removeOriginalTemporalField` to T,
// which will cause function removeDuplicateTimeFields() to remove T and only keep (TIMEUNIT)T
// in item data.
// If both (TIMEUNIT)T and T are in vlSpec, we set `removeOriginalTemporalField` to undefined,
// which will leave both T and (TIMEUNIT)T in item data.
// Note: user should never have to provide this boolean in options
if (fieldDef.type === "temporal" && fieldDef.timeUnit) {
// in most cases, if it's a (TIMEUNIT)T, we remove original T
var originalTemporalField = fieldDef.field;
supplementedFieldOption.removeOriginalTemporalField = originalTemporalField;
// handle corner case: if T is present in vlSpec, then we keep both T and (TIMEUNIT)T
var fieldDefs = vl.spec.fieldDefs(vlSpec);
for (var i = 0; i < fieldDefs.length; i++) {
if (fieldDefs[i].field === originalTemporalField && !fieldDefs[i].timeUnit) {
supplementedFieldOption.removeOriginalTemporalField = undefined;
break;
}
}
}
// supplement title

@@ -323,3 +348,3 @@ if (!config.countTitle) config.countTitle = vl.config.defaultConfig.countTitle; // use vl default countTitle

vl.timeUnit.template(fieldDef.timeUnit, "", false).match(/time:'[%-a-z]*'/i)[0].split("'")[1]
: config.timeFormat;
: config.timeFormat || vl.config.defaultConfig.timeFormat;
break;

@@ -334,3 +359,3 @@ case "number":

// supplement bin from fieldDef, user should never have to provide bin
// supplement bin from fieldDef, user should never have to provide bin in options
if (fieldDef.bin) {

@@ -429,2 +454,5 @@ supplementedFieldOption.field = supplementedFieldOption.field.replace("_start", "_range"); // replace suffix

// remove duplicate time fields (if any)
removeDuplicateTimeFields(itemData, options.fields);
// combine multiple rows of a binned field into a single row

@@ -573,2 +601,17 @@ combineBinFields(itemData, options.fields);

/**
* When a temporal field has timeUnit, itemData will give us duplicated fields
* (e.g., Year and YEAR(Year)). In tooltip want to display the field WITH the
* timeUnit and remove the field that doesn't have timeUnit.
*/
function removeDuplicateTimeFields(itemData, optFields) {
if (!optFields) return;
optFields.forEach(function(optField) {
if (optField.removeOriginalTemporalField) {
removeFields(itemData, [optField.removeOriginalTemporalField]);
}
});
}
/**
* Combine multiple binned fields in itemData into one field. The value of the field

@@ -575,0 +618,0 @@ * is a string that describes the bin range.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc