mascot-vis 1.7.4 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mascot-min.js +21 -21
- package/dist/mascot.js +101 -53
- package/package.json +1 -1
package/dist/mascot.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
|
-
// version: 1.
|
|
2
|
+
// version: 1.8.0
|
|
3
3
|
(function (global, factory) {
|
|
4
4
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3'), require('pixi.js')) :
|
|
5
5
|
typeof define === 'function' && define.amd ? define(['exports', 'd3', 'pixi.js'], factory) :
|
|
@@ -1980,12 +1980,36 @@
|
|
|
1980
1980
|
}
|
|
1981
1981
|
|
|
1982
1982
|
contains(x, y) {
|
|
1983
|
+
let svgData = this.getSVGPathData();
|
|
1984
|
+
if (svgData !== "") {
|
|
1985
|
+
let ctx = CanvasProvider.getContext(),
|
|
1986
|
+
p = new Path2D(svgData);
|
|
1987
|
+
ctx.lineWidth = Math.max(this.strokeWidth, 2.5);
|
|
1988
|
+
ctx.stroke(p);
|
|
1989
|
+
return ctx.isPointInPath(p, x, y);
|
|
1990
|
+
}
|
|
1983
1991
|
if (!this._bounds) {
|
|
1984
1992
|
this._updateBounds();
|
|
1985
1993
|
}
|
|
1986
1994
|
return this._bounds.contains(x, y);
|
|
1987
1995
|
}
|
|
1988
1996
|
|
|
1997
|
+
getSVGPathData() {
|
|
1998
|
+
let d = "";
|
|
1999
|
+
for (let i of this.children) {
|
|
2000
|
+
if (i.getSVGPathData)
|
|
2001
|
+
d += i.getSVGPathData();
|
|
2002
|
+
else if (i.bounds) {
|
|
2003
|
+
let b = i.bounds;
|
|
2004
|
+
d += ["M", b.left, b.top].join(" ");
|
|
2005
|
+
d += ["L", b.right, b.top].join(" ");
|
|
2006
|
+
d += ["L", b.right, b.bottom].join(" ");
|
|
2007
|
+
d += ["L", b.left, b.bottom, "Z"].join(" ");
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
return d;
|
|
2011
|
+
}
|
|
2012
|
+
|
|
1989
2013
|
toJSON() {
|
|
1990
2014
|
let json = {};
|
|
1991
2015
|
json.type = this.type;
|
|
@@ -2738,7 +2762,8 @@
|
|
|
2738
2762
|
case ItemType.Ring:
|
|
2739
2763
|
return _doRingDivide(scene, compnt, orientation, f, datatable);
|
|
2740
2764
|
case ItemType.Pie:
|
|
2741
|
-
|
|
2765
|
+
case ItemType.Arc:
|
|
2766
|
+
return _doArcDivide(scene, compnt, orientation, f, datatable);
|
|
2742
2767
|
}
|
|
2743
2768
|
|
|
2744
2769
|
}
|
|
@@ -2936,7 +2961,7 @@
|
|
|
2936
2961
|
return toReturn;
|
|
2937
2962
|
}
|
|
2938
2963
|
|
|
2939
|
-
function
|
|
2964
|
+
function _doArcDivide(scene, compnt, o, field, datatable) {
|
|
2940
2965
|
let toReturn, orientation = o ? o : Orientation.Radial;
|
|
2941
2966
|
let peers = getPeers(compnt, scene);
|
|
2942
2967
|
let collClassId;
|
|
@@ -3819,7 +3844,8 @@
|
|
|
3819
3844
|
for (let enc of this.scale.encodings)
|
|
3820
3845
|
items = items.concat(enc.items);
|
|
3821
3846
|
if (channel == "x") {
|
|
3822
|
-
let layout = getClosestLayout(this.anyItem);
|
|
3847
|
+
//let layout = getClosestLayout(this.anyItem);
|
|
3848
|
+
let layout = getTopLevelCollection(this.anyItem) ? getTopLevelCollection(this.anyItem).layout : getClosestLayout(this.anyItem);
|
|
3823
3849
|
if (layout && layout.type == LayoutType.Grid){
|
|
3824
3850
|
//do not use scale.offset, use cell bounds
|
|
3825
3851
|
for (let i = 0; i < this.items.length; i++) {
|
|
@@ -3855,7 +3881,8 @@
|
|
|
3855
3881
|
}
|
|
3856
3882
|
|
|
3857
3883
|
} else {//channel y
|
|
3858
|
-
let layout = getClosestLayout(this.anyItem);
|
|
3884
|
+
//let layout = getClosestLayout(this.anyItem);
|
|
3885
|
+
let layout = getTopLevelCollection(this.anyItem) ? getTopLevelCollection(this.anyItem).layout : getClosestLayout(this.anyItem);
|
|
3859
3886
|
if (layout && layout.type == LayoutType.Grid){
|
|
3860
3887
|
let cellBounds = this.items.map(d => getCellBoundsInLayout(d));
|
|
3861
3888
|
for (let i = 0; i < this.items.length; i++) {
|
|
@@ -3986,9 +4013,6 @@
|
|
|
3986
4013
|
|
|
3987
4014
|
encoding._map = function() {
|
|
3988
4015
|
switch (this.datatable.getFieldType(this.field)) {
|
|
3989
|
-
case DataType.Date:
|
|
3990
|
-
break;
|
|
3991
|
-
|
|
3992
4016
|
case DataType.Boolean:
|
|
3993
4017
|
if (!this.scale) {
|
|
3994
4018
|
this.scale = createScale("ordinalColor");
|
|
@@ -4012,7 +4036,7 @@
|
|
|
4012
4036
|
}
|
|
4013
4037
|
break;
|
|
4014
4038
|
|
|
4015
|
-
default: //
|
|
4039
|
+
default: //number or date
|
|
4016
4040
|
if (this.scale) {
|
|
4017
4041
|
if (!this._mapping) {
|
|
4018
4042
|
let values = this.scale.domain.concat(this.data);
|
|
@@ -4110,7 +4134,7 @@
|
|
|
4110
4134
|
return encoding;
|
|
4111
4135
|
}
|
|
4112
4136
|
|
|
4113
|
-
function
|
|
4137
|
+
function bindToAreaMark(encoding){
|
|
4114
4138
|
|
|
4115
4139
|
encoding._query = function() {
|
|
4116
4140
|
this.data = [];
|
|
@@ -4241,10 +4265,11 @@
|
|
|
4241
4265
|
if (channel === "width" || channel === "height") {
|
|
4242
4266
|
let closestLayout = getClosestLayout(this.areas[0]);
|
|
4243
4267
|
if (closestLayout) {
|
|
4244
|
-
let vidx = 0;
|
|
4245
|
-
for (let area of this.areas) {
|
|
4246
|
-
let cb =
|
|
4247
|
-
|
|
4268
|
+
let vidx = 0, cellBounds = this.areas.map(d => getCellBoundsInLayout(d)), layouts = this.areas.map(d => getClosestLayout(d));
|
|
4269
|
+
for (let [aidx, area] of this.areas.entries()) {
|
|
4270
|
+
let cb = cellBounds[aidx], layout = layouts[aidx];
|
|
4271
|
+
// let cb = getCellBoundsInLayout(area),
|
|
4272
|
+
// layout = getClosestLayout(area);
|
|
4248
4273
|
for (let i = 0; i < area.vertices.length; i++) {
|
|
4249
4274
|
let v = this._vertices[i + vidx],
|
|
4250
4275
|
dx, dy;
|
|
@@ -4585,9 +4610,10 @@
|
|
|
4585
4610
|
//optional itm specifies which scale range to get in the case of small multiples
|
|
4586
4611
|
getScaleRange(itm) {
|
|
4587
4612
|
let item = itm ? itm : this.anyItem;
|
|
4588
|
-
if (item.type == ItemType.Area) {
|
|
4589
|
-
let
|
|
4590
|
-
let
|
|
4613
|
+
if (item.type == ItemType.Area || (item.type == "vertex" && item.parent.type == ItemType.Area)) {
|
|
4614
|
+
let area = item.type == ItemType.Area ? item : item.parent;
|
|
4615
|
+
let AreaOrientation = CheckAreaOrien(area);
|
|
4616
|
+
let layout = getClosestLayout(area);
|
|
4591
4617
|
let alignment;
|
|
4592
4618
|
if (layout) {
|
|
4593
4619
|
if (AreaOrientation == Orientation.Vertical) {
|
|
@@ -4601,10 +4627,10 @@
|
|
|
4601
4627
|
// : (layout.type == LayoutType.Stack ? layout._vertCellAlignment == Alignment.Bottom : layout._cellVertAlignment == Alignment.Bottom)
|
|
4602
4628
|
}
|
|
4603
4629
|
else {
|
|
4604
|
-
alignment = AreaOrientation == Orientation.Vertical ?
|
|
4630
|
+
alignment = AreaOrientation == Orientation.Vertical ? area.baseline == Alignment.Left : area.baseline == Alignment.Bottom;
|
|
4605
4631
|
}
|
|
4606
4632
|
// let DomainToBaseline = this.scale.domain[1] > this.scale.domain[0] ? "default" : "opposite"; // controlling the alignment for the axis and the chart
|
|
4607
|
-
let cb = getCellBoundsInGridLayout(
|
|
4633
|
+
let cb = getCellBoundsInGridLayout(area);
|
|
4608
4634
|
if (cb) {
|
|
4609
4635
|
switch (this.channel) {
|
|
4610
4636
|
case "x":
|
|
@@ -4633,13 +4659,13 @@
|
|
|
4633
4659
|
switch (this.channel) {
|
|
4634
4660
|
case "width":
|
|
4635
4661
|
case "height": {
|
|
4636
|
-
let vertices = getPeers(item.firstVertex, this.scene);
|
|
4662
|
+
let vertices = this._vertices; // getPeers(item.firstVertex, this.scene);
|
|
4637
4663
|
let offset = alignment ? Math.max(...vertices.map(d => d["y"])) : Math.min(...vertices.map(d => d["y"]));
|
|
4638
4664
|
return alignment ? [offset, offset - this.scale.rangeExtent] : [offset + this.scale.rangeExtent, offset];
|
|
4639
4665
|
}
|
|
4640
4666
|
case "x":
|
|
4641
4667
|
case "y": {
|
|
4642
|
-
let vertices = getPeers(
|
|
4668
|
+
let vertices = getPeers(area.firstVertex, this.scene);
|
|
4643
4669
|
let offset = Math.min(...vertices.map(d => d["x"]));
|
|
4644
4670
|
return [offset, offset + this.scale.rangeExtent];
|
|
4645
4671
|
}
|
|
@@ -4648,13 +4674,13 @@
|
|
|
4648
4674
|
switch (this.channel) {
|
|
4649
4675
|
case "x":
|
|
4650
4676
|
case "y": {
|
|
4651
|
-
let vertices = getPeers(
|
|
4677
|
+
let vertices = getPeers(area.firstVertex, this.scene);
|
|
4652
4678
|
let offset = Math.max(...vertices.map(d => d["y"]));
|
|
4653
4679
|
return [offset, offset - this.scale.rangeExtent];
|
|
4654
4680
|
}
|
|
4655
4681
|
case "height":
|
|
4656
4682
|
case "width": {
|
|
4657
|
-
let vertices = getPeers(
|
|
4683
|
+
let vertices = getPeers(area.firstVertex, this.scene);
|
|
4658
4684
|
let offset = alignment ? Math.min(...vertices.map(d => d["x"])) : Math.max(...vertices.map(d => d["x"]));
|
|
4659
4685
|
return alignment ? [offset, offset + this.scale.rangeExtent] : [offset - this.scale.rangeExtent, offset];
|
|
4660
4686
|
}
|
|
@@ -6608,6 +6634,7 @@
|
|
|
6608
6634
|
case DataType.String:
|
|
6609
6635
|
this._createCategoricalColorLegend(scene, f);
|
|
6610
6636
|
break;
|
|
6637
|
+
case DataType.Date:
|
|
6611
6638
|
case DataType.Number:
|
|
6612
6639
|
case DataType.Integer:
|
|
6613
6640
|
this._createNumericalColorLegend(scene, f);
|
|
@@ -6662,21 +6689,27 @@
|
|
|
6662
6689
|
});
|
|
6663
6690
|
}
|
|
6664
6691
|
} else {
|
|
6665
|
-
let domain = this.encoding.scale.domain;
|
|
6666
|
-
let stops = [], uniqueVals = uniqueNumbers(this.encoding.data);
|
|
6692
|
+
let domain = this.encoding.scale.domain, dt = this.encoding.datatable, ft = dt.getFieldType(f);
|
|
6693
|
+
let stops = [], uniqueVals = ft === DataType.Date? dt.getUniqueFieldValues(f) : uniqueNumbers(this.encoding.data);
|
|
6667
6694
|
if (uniqueVals.length <= 10){
|
|
6668
6695
|
stops = uniqueVals;
|
|
6669
6696
|
stops.sort((a, b) => a - b);
|
|
6670
6697
|
} else {
|
|
6671
|
-
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
interval
|
|
6677
|
-
|
|
6698
|
+
if (ft === DataType.Date) {
|
|
6699
|
+
uniqueVals.sort((a, b) => a - b);
|
|
6700
|
+
for (let i = 0; i < uniqueVals.length; i+= Math.ceil(uniqueVals.length/10))
|
|
6701
|
+
stops.push(uniqueVals[i]);
|
|
6702
|
+
} else {
|
|
6703
|
+
let interval = (domain[1] - domain[0])/9;
|
|
6704
|
+
for (let i = 0; i < 10; i++)
|
|
6705
|
+
stops.push(domain[0] + i * interval);
|
|
6706
|
+
let decimalPlaces = 0;
|
|
6707
|
+
while (interval < 1) {
|
|
6708
|
+
interval *= 10;
|
|
6709
|
+
decimalPlaces++;
|
|
6710
|
+
}
|
|
6711
|
+
stops = stops.map(d => d.toFixed(decimalPlaces));
|
|
6678
6712
|
}
|
|
6679
|
-
stops = stops.map(d => d.toFixed(decimalPlaces));
|
|
6680
6713
|
}
|
|
6681
6714
|
if (this._orientation == Orientation.Vertical) {
|
|
6682
6715
|
gradient = new LinearGradient({x1: 0, y1: 100, x2: 0, y2: 0});
|
|
@@ -6685,7 +6718,7 @@
|
|
|
6685
6718
|
gradient.addStop(p*100, this.encoding.scale.map(d), 1.0);
|
|
6686
6719
|
let tk = scene.mark("line", {"x1": this._x + wd, "x2": this._x + wd + tickSize, "y1": this._y + ht - p * ht + titleSize, "y2": this._y + ht - p * ht + titleSize, "strokeColor": this._strokeColor});
|
|
6687
6720
|
ticks.push(tk);
|
|
6688
|
-
let t = scene.mark("text", {fillColor: this._textColor, "text": d, x: this._x + wd + offset + tickSize, y: this._y + ht - p * ht + titleSize, "anchor": ["left", "middle"]});
|
|
6721
|
+
let t = scene.mark("text", {fillColor: this._textColor, "text": ft === DataType.Date? dt.getRawValue(f, d) : d, x: this._x + wd + offset + tickSize, y: this._y + ht - p * ht + titleSize, "anchor": ["left", "middle"]});
|
|
6689
6722
|
texts.push(t);
|
|
6690
6723
|
});
|
|
6691
6724
|
} else {
|
|
@@ -6695,7 +6728,7 @@
|
|
|
6695
6728
|
gradient.addStop(p*100, this.encoding.scale.map(d), 1.0);
|
|
6696
6729
|
let tk = scene.mark("line", {"x1": this._x + p * wd, "x2": this._x + p * wd, "y1": this._y + ht + titleSize, "y2": this._y + ht + tickSize + titleSize, "strokeColor": this._strokeColor});
|
|
6697
6730
|
ticks.push(tk);
|
|
6698
|
-
let t = scene.mark("text", {fillColor: this._textColor, "text": d, x: this._x + p * wd, y: this._y + ht + offset + titleSize, "anchor": ["center", "top"]});
|
|
6731
|
+
let t = scene.mark("text", {fillColor: this._textColor, "text": ft === DataType.Date? dt.getRawValue(f, d) : d, x: this._x + p * wd, y: this._y + ht + offset + titleSize, "anchor": ["center", "top"]});
|
|
6699
6732
|
texts.push(t);
|
|
6700
6733
|
});
|
|
6701
6734
|
}
|
|
@@ -8912,20 +8945,33 @@
|
|
|
8912
8945
|
//todo: validate channel
|
|
8913
8946
|
}
|
|
8914
8947
|
|
|
8915
|
-
|
|
8916
|
-
|
|
8917
|
-
let
|
|
8918
|
-
|
|
8919
|
-
|
|
8920
|
-
|
|
8921
|
-
let
|
|
8922
|
-
|
|
8923
|
-
|
|
8948
|
+
//supports encoding one single item or an array of items (which will use the same scale)
|
|
8949
|
+
encode(itm, args) {
|
|
8950
|
+
let arr = Array.isArray(itm) ? itm : [itm];
|
|
8951
|
+
let encs = [], scale;
|
|
8952
|
+
for (let item of arr) {
|
|
8953
|
+
this._validateEncodeArgs(item, args);
|
|
8954
|
+
let items;
|
|
8955
|
+
if (item.type == "vertex" && item.parent.type == ItemType.Area){
|
|
8956
|
+
let areas = getPeers(item.parent, this);
|
|
8957
|
+
items = [];
|
|
8958
|
+
let firstHalf = item.parent.vertices.indexOf(item) < item.parent.vertices.length/2;
|
|
8959
|
+
for (let area of areas){
|
|
8960
|
+
items = firstHalf ? items.concat(area.vertices.slice(0, area.vertices.length/2)) : items.concat(area.vertices.slice(area.vertices.length/2));
|
|
8961
|
+
}
|
|
8962
|
+
} else {
|
|
8963
|
+
items = getPeers(item, this);
|
|
8924
8964
|
}
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
|
|
8965
|
+
if (!args.scale && scale) {
|
|
8966
|
+
args.scale = scale;
|
|
8967
|
+
}
|
|
8968
|
+
let enc = this._doEncode(items, args);
|
|
8969
|
+
if (!scale)
|
|
8970
|
+
scale = enc.scale;
|
|
8971
|
+
encs.push(enc);
|
|
8972
|
+
}
|
|
8973
|
+
|
|
8974
|
+
return encs.length > 1 ? encs : encs[0];
|
|
8929
8975
|
}
|
|
8930
8976
|
|
|
8931
8977
|
_doEncode(items, args) {
|
|
@@ -8954,7 +9000,7 @@
|
|
|
8954
9000
|
case "area":
|
|
8955
9001
|
case "fontSize":
|
|
8956
9002
|
if (item.type == ItemType.Area)
|
|
8957
|
-
|
|
9003
|
+
bindToAreaMark(encoding);
|
|
8958
9004
|
else
|
|
8959
9005
|
bindToSize(encoding);
|
|
8960
9006
|
break;
|
|
@@ -8966,10 +9012,11 @@
|
|
|
8966
9012
|
break;
|
|
8967
9013
|
case "x":
|
|
8968
9014
|
case "y":
|
|
8969
|
-
|
|
8970
|
-
|
|
8971
|
-
|
|
8972
|
-
|
|
9015
|
+
bindToPosition(encoding);
|
|
9016
|
+
// if (item.type == ItemType.Area)
|
|
9017
|
+
// bindToAreaMark(encoding);
|
|
9018
|
+
// else
|
|
9019
|
+
// bindToPosition(encoding);
|
|
8973
9020
|
break;
|
|
8974
9021
|
case "fillColor":
|
|
8975
9022
|
case "strokeColor":
|
|
@@ -9084,6 +9131,7 @@
|
|
|
9084
9131
|
}
|
|
9085
9132
|
|
|
9086
9133
|
let layout = getClosestLayout(item);
|
|
9134
|
+
if (!layout || (layout.type !== LayoutType.Grid && layout.type !== LayoutType.Stack)) return;
|
|
9087
9135
|
|
|
9088
9136
|
if (layout && (channel == "x" || channel == "y")) {
|
|
9089
9137
|
let group = layout.group,
|