mascot-vis 3.0.0 → 3.0.2
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-esm.js +186 -0
- package/package.json +3 -6
- package/dist/mascot-es.js +0 -27745
- package/dist/mascot-min.js +0 -186
- package/dist/mascot-umd.js +0 -27781
- package/js/depGraphVis.js +0 -66
- package/src-new-ts/action/createElement.ts +0 -91
- package/src-new-ts/action/encode.js +0 -20
- package/src-new-ts/action/repeat.js +0 -128
- package/src-new-ts/action/traverseScene.js +0 -41
- package/src-new-ts/data/Network.js +0 -2
- package/src-new-ts/data/Scope.js +0 -135
- package/src-new-ts/data/Table.js +0 -263
- package/src-new-ts/data/Tree.js +0 -3
- package/src-new-ts/data/field.ts +0 -115
- package/src-new-ts/data/import.ts +0 -96
- package/src-new-ts/data/predicate.ts +0 -82
- package/src-new-ts/depgraph/DepGraph.js +0 -178
- package/src-new-ts/depgraph/Edge.js +0 -9
- package/src-new-ts/depgraph/SceneGraph2DepGraph.js +0 -110
- package/src-new-ts/depgraph/Signal.js +0 -12
- package/src-new-ts/depgraph/operator/BoundsEvaluator.js +0 -30
- package/src-new-ts/depgraph/operator/Dataflow.js +0 -41
- package/src-new-ts/depgraph/operator/DomainBuilder.js +0 -50
- package/src-new-ts/depgraph/updateDepGraph.js +0 -45
- package/src-new-ts/depgraph/variable/BoundsVar.js +0 -81
- package/src-new-ts/depgraph/variable/ChannelVar.js +0 -17
- package/src-new-ts/depgraph/variable/DataScopeVar.js +0 -12
- package/src-new-ts/depgraph/variable/DomainVar.js +0 -15
- package/src-new-ts/depgraph/variable/FieldVar.js +0 -17
- package/src-new-ts/depgraph/variable/LayoutParameter.js +0 -8
- package/src-new-ts/depgraph/variable/ScaleVar.js +0 -13
- package/src-new-ts/depgraph/variable/Variable.js +0 -39
- package/src-new-ts/element/gradient/LinearGradient.js +0 -37
- package/src-new-ts/element/group/Collection.js +0 -109
- package/src-new-ts/element/group/Group.js +0 -307
- package/src-new-ts/element/group/Scene.js +0 -98
- package/src-new-ts/element/mark/CircleMark.ts +0 -85
- package/src-new-ts/element/mark/Mark.ts +0 -233
- package/src-new-ts/element/mark/PathMark.js +0 -483
- package/src-new-ts/element/mark/Segment.js +0 -29
- package/src-new-ts/element/mark/Vertex.js +0 -118
- package/src-new-ts/encode/Scale.ts +0 -115
- package/src-new-ts/index.ts +0 -19
- package/src-new-ts/layout/Layout.ts +0 -3
- package/src-new-ts/render/CanvasRenderer.ts +0 -24
- package/src-new-ts/render/SVGRenderer.js +0 -316
- package/src-new-ts/util.ts +0 -3
- package/src-old/action/Classify.js +0 -53
- package/src-old/action/Densify.js +0 -199
- package/src-old/action/Partition.js +0 -531
- package/src-old/action/Repeat.js +0 -106
- package/src-old/action/Repopulate.js +0 -44
- package/src-old/action/Stratify.js +0 -156
- package/src-old/basic/Gradient.js +0 -37
- package/src-old/basic/Point.js +0 -51
- package/src-old/basic/Rectangle.js +0 -63
- package/src-old/bind/bindToAngle.js +0 -56
- package/src-old/bind/bindToAreaMark.js +0 -360
- package/src-old/bind/bindToColor.js +0 -114
- package/src-old/bind/bindToLink.js +0 -81
- package/src-old/bind/bindToPosition.js +0 -283
- package/src-old/bind/bindToRadialDistance.js +0 -62
- package/src-old/bind/bindToSize.js +0 -235
- package/src-old/bind/bindToText.js +0 -60
- package/src-old/bind/bindToThickness.js +0 -100
- package/src-old/constraint/AffixConstraint.js +0 -129
- package/src-old/constraint/AlignConstraint.js +0 -58
- package/src-old/core/Encoding.js +0 -336
- package/src-old/core/Scale.js +0 -322
- package/src-old/core/SceneLoader.js +0 -290
- package/src-old/core/SceneValidator.js +0 -232
- package/src-old/core/SpecExecutor.js +0 -113
- package/src-old/core/SpecGenerator.js +0 -350
- package/src-old/data/DataImporter.js +0 -64
- package/src-old/data/DataScope.js +0 -124
- package/src-old/data/DataTable.js +0 -338
- package/src-old/data/Network.js +0 -106
- package/src-old/data/Tree.js +0 -251
- package/src-old/data/transform/Bin.js +0 -46
- package/src-old/data/transform/Filter.js +0 -48
- package/src-old/data/transform/Groupby.js +0 -18
- package/src-old/data/transform/KDE.js +0 -58
- package/src-old/data/transform/Sort.js +0 -14
- package/src-old/data/transform/Split.js +0 -5
- package/src-old/data/transform/partition.js +0 -46
- package/src-old/history/UndoRedoStack +0 -0
- package/src-old/index.js +0 -271
- package/src-old/indexSVG.js +0 -259
- package/src-old/interaction/Interaction.js +0 -91
- package/src-old/interaction/MouseEvent.js +0 -8
- package/src-old/interaction/Selection.js +0 -9
- package/src-old/interaction/brush.js +0 -362
- package/src-old/item/Segment.js +0 -29
- package/src-old/item/Vertex.js +0 -118
- package/src-old/item/composite/Collection.js +0 -106
- package/src-old/item/composite/Glyph.js +0 -19
- package/src-old/item/composite/Group.js +0 -310
- package/src-old/item/composite/Scene.js +0 -1251
- package/src-old/item/mark/ArcPath.js +0 -181
- package/src-old/item/mark/AreaPath.js +0 -78
- package/src-old/item/mark/CirclePath.js +0 -102
- package/src-old/item/mark/EllipsePath.js +0 -5
- package/src-old/item/mark/Image.js +0 -101
- package/src-old/item/mark/LinkPath.js +0 -118
- package/src-old/item/mark/Mark.js +0 -163
- package/src-old/item/mark/Path.js +0 -494
- package/src-old/item/mark/PointText.js +0 -201
- package/src-old/item/mark/PolygonPath.js +0 -64
- package/src-old/item/mark/RectPath.js +0 -88
- package/src-old/item/mark/RingPath.js +0 -92
- package/src-old/item/refs/Axis.js +0 -362
- package/src-old/item/refs/EncodingAxis.js +0 -515
- package/src-old/item/refs/Gridlines.js +0 -144
- package/src-old/item/refs/LayoutAxis.js +0 -316
- package/src-old/item/refs/Legend.js +0 -273
- package/src-old/layout/Circular.js +0 -95
- package/src-old/layout/Force.js +0 -52
- package/src-old/layout/Grid.js +0 -423
- package/src-old/layout/Layout.js +0 -13
- package/src-old/layout/Packing.js +0 -56
- package/src-old/layout/Stack.js +0 -264
- package/src-old/layout/Strata.js +0 -88
- package/src-old/layout/Sugiyama.js +0 -59
- package/src-old/layout/TidyTree.js +0 -105
- package/src-old/layout/Treemap.js +0 -87
- package/src-old/renderer/SVGInteractionHandler.js +0 -241
- package/src-old/renderer/SVGRenderer.js +0 -325
- package/src-old/renderer/WebGLRenderer.js +0 -1097
- package/src-old/renderer/WebGLRenderer2.js +0 -249
- package/src-old/renderer/threejs/Line2.js +0 -18
- package/src-old/renderer/threejs/LineGeometry.js +0 -77
- package/src-old/renderer/threejs/LineMaterial.js +0 -605
- package/src-old/renderer/threejs/LineSegments2.js +0 -281
- package/src-old/renderer/threejs/LineSegmentsGeometry.js +0 -226
- package/src-old/renderer/threejs/Wireframe.js +0 -51
- package/src-old/renderer/threejs/WireframeGeometry2.js +0 -16
- package/src-old/scale/areaSize.js +0 -0
- package/src-old/scale/domain.js +0 -38
- package/src-old/util/Constants.js +0 -180
- package/src-old/util/DataUtil.js +0 -35
- package/src-old/util/ItemUtil.js +0 -586
- package/src-old/util/Numerical.js +0 -33
- package/tests/demo-tests/README.md +0 -80
- package/tests/demo-tests/SVG2PNG.js +0 -56
- package/tests/demo-tests/demos2CanvasPNGs.js +0 -69
- package/tests/demo-tests/demos2ScenesSVGs.js +0 -100
- package/tests/demo-tests/pathElementWorker.js +0 -91
- package/tests/demo-tests/pixelTest.js +0 -62
- package/tests/demo-tests/renderDemos.html +0 -132
- package/tests/demo-tests/serializationTest.js +0 -36
- package/tests/demo-tests/serializeDemos.html +0 -134
- package/tests/unit-tests/README.md +0 -4
- package/tests/unit-tests/jasmine-browser.json +0 -21
- package/tests/unit-tests/jasmine.json +0 -14
- package/tests/unit-tests/testSpec.js +0 -274
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export default class Segment {
|
|
2
|
-
|
|
3
|
-
constructor(v1, v2, parentMark, id) {
|
|
4
|
-
this.type = "segment";
|
|
5
|
-
this._id = id;
|
|
6
|
-
this.vertex1 = v1;
|
|
7
|
-
this.vertex2 = v2;
|
|
8
|
-
|
|
9
|
-
this.dataScope = undefined;
|
|
10
|
-
this.parent = parentMark;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
get id() {
|
|
14
|
-
return this.parent.id + "_s_" + this._id;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
_doTranslate(dx, dy) {
|
|
18
|
-
this.vertex1._doTranslate(dx, dy);
|
|
19
|
-
this.vertex2._doTranslate(dx, dy);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get x() {
|
|
23
|
-
return (this.vertex1.x + this.vertex2.x)/2;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get y() {
|
|
27
|
-
return (this.vertex1.y + this.vertex2.y)/2;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
// Based on path.Segment.js, as part of Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
|
2
|
-
// http://paperjs.org/
|
|
3
|
-
// Copyright (c) 2011 - 2019, Juerg Lehni & Jonathan Puckey
|
|
4
|
-
// http://scratchdisk.com/ & https://puckey.studio/
|
|
5
|
-
//
|
|
6
|
-
// Distributed under the MIT license. See LICENSE file for detail
|
|
7
|
-
//
|
|
8
|
-
// All rights reserved.
|
|
9
|
-
|
|
10
|
-
import { Rectangle } from "../../depgraph/variable/BoundsVar";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export default class Vertex {
|
|
14
|
-
|
|
15
|
-
//handles are relative to the point
|
|
16
|
-
constructor(x, y, parentMark, id) {
|
|
17
|
-
this.type = "vertex";
|
|
18
|
-
this._id = id;
|
|
19
|
-
this.x = x;
|
|
20
|
-
this.y = y;
|
|
21
|
-
this.dataScope = undefined;
|
|
22
|
-
this.parent = parentMark;
|
|
23
|
-
|
|
24
|
-
this.shape = undefined;
|
|
25
|
-
this.width = 0;
|
|
26
|
-
this.height = 0;
|
|
27
|
-
this.radius = 0;
|
|
28
|
-
this.fillColor = "#555";
|
|
29
|
-
this.opacity = 1;
|
|
30
|
-
this.strokeWidth = 0;
|
|
31
|
-
this.strokeColor = "#aaa";
|
|
32
|
-
this._polarAngle = undefined;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get bounds() {
|
|
36
|
-
switch(this.shape) {
|
|
37
|
-
case "rect":
|
|
38
|
-
return new Rectangle(this.x - this.width/2, this.y - this.height/2, this.width, this.height);
|
|
39
|
-
case "circle":
|
|
40
|
-
return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2);
|
|
41
|
-
default:
|
|
42
|
-
return new Rectangle(this.x - 0.5, this.y - 0.5, 1, 1);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get id() {
|
|
47
|
-
return this.parent.id + "_v_" + this._id;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
toJSON() {
|
|
51
|
-
let json = {};
|
|
52
|
-
json.type = this.type;
|
|
53
|
-
json.id = this._id;
|
|
54
|
-
json.x = this.x;
|
|
55
|
-
json.y = this.y;
|
|
56
|
-
if (this.dataScope)
|
|
57
|
-
json.dataScope = this.dataScope.toJSON();
|
|
58
|
-
if (this._polarAngle !== undefined)
|
|
59
|
-
json.polarAngle = this._polarAngle;
|
|
60
|
-
json.shape = this.shape;
|
|
61
|
-
json.width = this.width;
|
|
62
|
-
json.height = this.height;
|
|
63
|
-
json.radius = this.radius;
|
|
64
|
-
json.fillColor = this.fillColor;
|
|
65
|
-
json.opacity = this.opacity;
|
|
66
|
-
json.strokeWidth = this.strokeWidth;
|
|
67
|
-
json.strokeColor = this.strokeColor;
|
|
68
|
-
return json;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
static fromJSON(json, parent) {
|
|
72
|
-
let v = new Vertex(json, parent, json.id);
|
|
73
|
-
if (json.dataScope)
|
|
74
|
-
v.dataScope = json.dataScope;
|
|
75
|
-
if ("polarAngle" in json)
|
|
76
|
-
v.polarAngle = json.polarAngle;
|
|
77
|
-
v.shape = json.shape;
|
|
78
|
-
v.width = json.width;
|
|
79
|
-
v.height = json.height;
|
|
80
|
-
v.radius = json.radius;
|
|
81
|
-
v.fillColor = json.fillColor;
|
|
82
|
-
v.opacity = json.opacity;
|
|
83
|
-
v.strokeWidth = json.strokeWidth;
|
|
84
|
-
v.strokeColor = json.strokeColor;
|
|
85
|
-
return v;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
_doTranslate(dx, dy) {
|
|
89
|
-
this.x += dx;
|
|
90
|
-
this.y += dy;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
_clone(parent) {
|
|
94
|
-
let v = new Vertex(this.x, this.y, parent, this._id);
|
|
95
|
-
if (this.dataScope) {
|
|
96
|
-
v.dataScope = this.dataScope.clone();
|
|
97
|
-
}
|
|
98
|
-
v.shape = this.shape;
|
|
99
|
-
v.width = this.width;
|
|
100
|
-
v.height = this.height;
|
|
101
|
-
v.radius = this.radius;
|
|
102
|
-
v.fillColor = this.fillColor;
|
|
103
|
-
v.opacity = this.opacity;
|
|
104
|
-
v.strokeWidth = this.strokeWidth;
|
|
105
|
-
v.strokeColor = this.strokeColor;
|
|
106
|
-
return v;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
set polarAngle(a) {
|
|
110
|
-
this._polarAngle = a;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
get polarAngle() {
|
|
114
|
-
return this._polarAngle;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
Vertex.styles = ["vxShape", "vxWidth", "vxHeight", "vxRadius", "vxFillColor", "vxStrokeColor", "vxStrokeWidth", "vxOpacity"];
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
// Assuming args has this possible structure based on the provided usage
|
|
3
|
-
interface ScaleArgs {
|
|
4
|
-
scheme?: string;
|
|
5
|
-
size?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
import { FieldType } from "../data/field"; // FieldType is an enum
|
|
9
|
-
import { generateUniqueID } from "../util";
|
|
10
|
-
import * as d3 from 'd3';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/*
|
|
14
|
-
|
|
15
|
-
// Example usage:
|
|
16
|
-
// If your domain elements are strings:
|
|
17
|
-
const scaleForStrings = new Scale<string>("point");
|
|
18
|
-
// If your domain elements are dates (for example, with a time scale):
|
|
19
|
-
// const scaleForDates = new Scale<Date>("time");
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
export default class Scale<Domain extends { toString(): string } = string> {
|
|
23
|
-
private _id: string;
|
|
24
|
-
private _type: string;
|
|
25
|
-
// Adjusting the type of _scale to accommodate the generic type for ScalePoint
|
|
26
|
-
private _scale: d3.ScaleLinear<number, number> | d3.ScalePoint<Domain> | d3.ScaleOrdinal<Domain, any> | d3.ScalePower<number, number> | d3.ScaleLogarithmic<number, number> | d3.ScaleTime<any, any> | d3.ScaleSequential<number> | any;
|
|
27
|
-
|
|
28
|
-
constructor(type: string, args?: ScaleArgs) {
|
|
29
|
-
this._id = "scale_" + generateUniqueID();
|
|
30
|
-
this._type = type;
|
|
31
|
-
switch (type) {
|
|
32
|
-
case "linear":
|
|
33
|
-
this._scale = d3.scaleLinear();
|
|
34
|
-
break;
|
|
35
|
-
case "point":
|
|
36
|
-
// Specifying the type argument for ScalePoint as Domain
|
|
37
|
-
this._scale = d3.scalePoint<Domain>();
|
|
38
|
-
break;
|
|
39
|
-
case "ordinal":
|
|
40
|
-
this._scale = d3.scaleOrdinal<Domain, any>();
|
|
41
|
-
break;
|
|
42
|
-
// Additional cases...
|
|
43
|
-
default:
|
|
44
|
-
this._scale = d3.scaleLinear(); // Fallback to a linear scale
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get id(): string {
|
|
50
|
-
return this._id;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
get domain(): [number, number] | string[] {
|
|
54
|
-
return this._scale.domain();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
set domain(d: [number, number] | string[]) {
|
|
58
|
-
this._scale.domain(d);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
get range(): [number, number] | string[] {
|
|
62
|
-
return this._scale.range();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
set range(r: [number, number] | string[]) {
|
|
66
|
-
this._scale.range(r);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
map(d: number | string): number | string {
|
|
70
|
-
return this._scale(d);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
interface DataScope {
|
|
75
|
-
dataTable: {
|
|
76
|
-
getFieldType: (field: string) => FieldType;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function createScale(field: string, channel: string, elem: { dataScope: DataScope }): Scale {
|
|
81
|
-
let fType = elem.dataScope.dataTable.getFieldType(field);
|
|
82
|
-
switch (fType) {
|
|
83
|
-
case FieldType.Boolean:
|
|
84
|
-
break;
|
|
85
|
-
case FieldType.Date:
|
|
86
|
-
return new Scale("time");
|
|
87
|
-
case FieldType.String:
|
|
88
|
-
return new Scale("point");
|
|
89
|
-
default: // integer or number
|
|
90
|
-
return new Scale("linear");
|
|
91
|
-
}
|
|
92
|
-
return new Scale("linear"); // Default return for Boolean case or any other unhandled FieldType
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// export function computeDomain(field, table, elems) {
|
|
97
|
-
// let dataScopes = elems.map(d => d.dataScope);
|
|
98
|
-
// switch (table.getFieldType(field)) {
|
|
99
|
-
// case FieldType.Boolean:
|
|
100
|
-
// break;
|
|
101
|
-
|
|
102
|
-
// case FieldType.Date:
|
|
103
|
-
// return dataScopes.map(d => d.getFieldValue(field));
|
|
104
|
-
|
|
105
|
-
// case FieldType.String:
|
|
106
|
-
// try {
|
|
107
|
-
// return dataScopes.map(d => d.getFieldValue(field));
|
|
108
|
-
// } catch (error) {
|
|
109
|
-
// throw new Error("Cannot bind " + this.channel + " to " + field + " : " + error);
|
|
110
|
-
// }
|
|
111
|
-
|
|
112
|
-
// default: //integer or number
|
|
113
|
-
// return dataScopes.map(d => d.aggregateNumericalField(field, this.aggregator));
|
|
114
|
-
// }
|
|
115
|
-
// }
|
package/src-new-ts/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { importCSV } from "./data/import.js";
|
|
2
|
-
import Scene from "./element/group/Scene.js";
|
|
3
|
-
import SVGRenderer from "./render/SVGRenderer.js";
|
|
4
|
-
|
|
5
|
-
export function scene(args) {
|
|
6
|
-
return new Scene(args);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function csv(url) {
|
|
10
|
-
return importCSV(url);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function renderer(type, id) {
|
|
14
|
-
switch (type) {
|
|
15
|
-
case "svg":
|
|
16
|
-
default:
|
|
17
|
-
return new SVGRenderer(id);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
interface CanvasProviderType {
|
|
2
|
-
canvas: HTMLCanvasElement | undefined;
|
|
3
|
-
|
|
4
|
-
getCanvas: () => HTMLCanvasElement | null;
|
|
5
|
-
getContext: () => CanvasRenderingContext2D | null;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const CanvasProvider: CanvasProviderType = {
|
|
9
|
-
canvas: undefined,
|
|
10
|
-
|
|
11
|
-
getCanvas: function() {
|
|
12
|
-
if (typeof window === 'undefined')
|
|
13
|
-
return null;
|
|
14
|
-
if (this.canvas === undefined) {
|
|
15
|
-
this.canvas = document.createElement('canvas');
|
|
16
|
-
}
|
|
17
|
-
return this.canvas;
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
getContext: function() {
|
|
21
|
-
const canvas = this.getCanvas();
|
|
22
|
-
return canvas ? canvas.getContext('2d') : null;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import * as d3 from 'd3';
|
|
2
|
-
import { ElementType } from "../action/createElement.js";
|
|
3
|
-
|
|
4
|
-
export default class SVGRenderer {
|
|
5
|
-
|
|
6
|
-
constructor(svgId) {
|
|
7
|
-
this._svgId = svgId;
|
|
8
|
-
this._compMap = {};
|
|
9
|
-
this._decoMap = {};
|
|
10
|
-
//this._interactionHandler = new SVGInteractionHandler(this);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
render(scene, params) {
|
|
14
|
-
let args = params ? params : {};
|
|
15
|
-
for (let k in this._decoMap) {
|
|
16
|
-
this._decoMap[k].remove();
|
|
17
|
-
delete this._decoMap[k];
|
|
18
|
-
}
|
|
19
|
-
this._removed = {};
|
|
20
|
-
for (let k in this._compMap) {
|
|
21
|
-
this._removed[k] = 1;
|
|
22
|
-
}
|
|
23
|
-
this._renderItem(scene, args);
|
|
24
|
-
for (let k in this._removed) {
|
|
25
|
-
this._compMap[k].remove();
|
|
26
|
-
delete this._compMap[k];
|
|
27
|
-
}
|
|
28
|
-
// if (!("visualOnly" in args)) {
|
|
29
|
-
// for (let i of scene._interactions)
|
|
30
|
-
// this._interactionHandler.processInteraction(i, scene);
|
|
31
|
-
// }
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
clear() {
|
|
35
|
-
let svg = document.getElementById(this._svgId);
|
|
36
|
-
while (svg.firstChild) {
|
|
37
|
-
svg.firstChild.remove();
|
|
38
|
-
}
|
|
39
|
-
this._compMap = {};
|
|
40
|
-
this._decoMap = {};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
_renderItem(c, args) {
|
|
44
|
-
let cid = c.id,
|
|
45
|
-
parent = c.parent;
|
|
46
|
-
|
|
47
|
-
let svgParent;
|
|
48
|
-
if (parent && parent.id && parent.id in this._compMap) {
|
|
49
|
-
svgParent = d3.select("#" + this._svgId).select("#" + parent.id);
|
|
50
|
-
} else {
|
|
51
|
-
svgParent = d3.select("#" + this._svgId);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (!(cid in this._compMap)) {
|
|
55
|
-
//TODO: what if the parent is not rendered? What if the hierarchy has changed?
|
|
56
|
-
this._compMap[cid] = svgParent.append(this._getSVGElementType(c));
|
|
57
|
-
} else {
|
|
58
|
-
delete this._removed[cid];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (c.type == ElementType.Gridlines) {
|
|
62
|
-
this._compMap[cid].lower();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
let el = this._compMap[cid];
|
|
66
|
-
|
|
67
|
-
el.attr("id", cid);
|
|
68
|
-
if (c.classId)
|
|
69
|
-
el.attr("class", c.classId);
|
|
70
|
-
|
|
71
|
-
if (c.type == ElementType.Scene) {
|
|
72
|
-
d3.select("#" + this._svgId).style("background", c.fillColor ? c.fillColor : "#fff");
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (c.type == "vertex") {
|
|
76
|
-
//TODO: render vertices
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let pathTypes = [ElementType.Path, ElementType.Polygon, ElementType.Link, ElementType.Pie, ElementType.Line, ElementType.Area, ElementType.Ring, ElementType.Arc];
|
|
81
|
-
if (pathTypes.indexOf(c.type) >= 0) {
|
|
82
|
-
el.attr("d", c.getSVGPathData());
|
|
83
|
-
if (!c.closed)
|
|
84
|
-
el.style("fill", "none");
|
|
85
|
-
if (cid.indexOf("axis") == 0) {
|
|
86
|
-
el.style("shape-rendering", "crispEdges");
|
|
87
|
-
}
|
|
88
|
-
} else if (c.type == ElementType.Circle) {
|
|
89
|
-
el.attr("cx", c.x);
|
|
90
|
-
el.attr("cy", c.y);
|
|
91
|
-
el.attr("r", c.radius);
|
|
92
|
-
} else if (c.type == ElementType.Rect) {
|
|
93
|
-
//do not use c.left, c.top, c.width, c.height as the rectangle may be flipped
|
|
94
|
-
//use c.bounds
|
|
95
|
-
let b = c.bounds;
|
|
96
|
-
el.attr("x", b.left).attr("y", b.top).attr("width", b.width).attr("height", b.height);
|
|
97
|
-
} else if (c.type == ElementType.PointText) {
|
|
98
|
-
el.attr("text-anchor", this._getTextAnchor(c.anchor[0]))
|
|
99
|
-
.attr("alignment-baseline", this._getTextAnchor(c.anchor[1]))
|
|
100
|
-
.attr("dominant-baseline", this._getTextAnchor(c.anchor[1]))
|
|
101
|
-
.text(c.text)
|
|
102
|
-
.attr("x", c.x).attr("y", c.y);
|
|
103
|
-
} else if (c.type == ElementType.Image) {
|
|
104
|
-
el.attr("href", c.src).attr("x", c.x).attr("y", c.y).attr("width", c.width).attr("height", c.height);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
for (let s in c.styles) {
|
|
108
|
-
if (c.styles[s] === undefined)
|
|
109
|
-
continue;
|
|
110
|
-
if (s.indexOf("Color") > 0 && c.styles[s].type == ElementType.LinearGradient) {
|
|
111
|
-
if (d3.select("#" + this._svgId).select("defs").empty())
|
|
112
|
-
d3.select("#" + this._svgId).append("defs");
|
|
113
|
-
let defs = d3.select("defs"), gradient = c.styles[s];
|
|
114
|
-
if (defs.select("#" + gradient.id).empty()) {
|
|
115
|
-
let grad = defs.append("linearGradient").attr("id", gradient.id);
|
|
116
|
-
grad.attr("x1", gradient.x1 + "%").attr("x2", gradient.x2 + "%").attr("y1", gradient.y1 + "%").attr("y2", gradient.y2 + "%");
|
|
117
|
-
for (let stop of gradient.stops)
|
|
118
|
-
grad.append("stop").attr("offset", stop.offset + "%").style("stop-color", stop.color).style("stop-opacity", stop.opacity);
|
|
119
|
-
}
|
|
120
|
-
el.style(Style2SVG[s], "url(#" + gradient.id + ")");
|
|
121
|
-
} else {
|
|
122
|
-
el.style(Style2SVG[s], c.styles[s]);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (c._rotate)
|
|
128
|
-
el.attr("transform", "rotate(" + c._rotate.join(" ") + ")");
|
|
129
|
-
|
|
130
|
-
// render vertices if shape is defined
|
|
131
|
-
if (c.vertices) {
|
|
132
|
-
// let shapes = c.vertices.map(d => d.shape).filter(d => d !== undefined);
|
|
133
|
-
// if (shapes.length > 0)
|
|
134
|
-
this._renderVertices(c);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// render scene bound
|
|
138
|
-
if (c.type == ElementType.Collection && args && args["collectionBounds"]) {
|
|
139
|
-
let b = c.bounds;
|
|
140
|
-
if (c.layout && c.layout.type == "grid") {
|
|
141
|
-
this._renderLayout(c);
|
|
142
|
-
} else {
|
|
143
|
-
if (!(c.id in this._decoMap)) {
|
|
144
|
-
this._decoMap[c.id] = d3.select("#" + this._svgId).append("rect").attr("class", "deco");
|
|
145
|
-
}
|
|
146
|
-
this._decoMap[c.id].attr("x", b.left).attr("y", b.top)
|
|
147
|
-
.attr("width", b.width).attr("height", b.height).attr("fill", "none")
|
|
148
|
-
.attr("stroke", "#1ecb40").attr("stroke-width", "2px")
|
|
149
|
-
.attr("stroke-dasharray", "5,5");
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
//render text/axis bound
|
|
154
|
-
// if (c.type == ElementType.PointText || c.type == ElementType.Axis) {
|
|
155
|
-
// let id = c.id + "-box";
|
|
156
|
-
// let b = c.bounds;
|
|
157
|
-
// if (!(id in this._decoMap)) {
|
|
158
|
-
// this._decoMap[id] = d3.select("#"+this._svgId).append("rect");
|
|
159
|
-
// }
|
|
160
|
-
// this._decoMap[id].attr("x", b.left).attr("y", b.top)
|
|
161
|
-
// .attr("width", b.width).attr("height", b.height).attr("fill", "none")
|
|
162
|
-
// .attr("stroke", "#1ecb40").attr("stroke-width", "1px")
|
|
163
|
-
// .attr("stroke-dasharray", "5,5");
|
|
164
|
-
// }
|
|
165
|
-
|
|
166
|
-
if (c.children) {
|
|
167
|
-
for (let child of c.children) {
|
|
168
|
-
this._renderItem(child, args);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
_renderVertices(c) {
|
|
175
|
-
let id = c.id + "-vertices";
|
|
176
|
-
if (!(id in this._compMap)) {
|
|
177
|
-
let parent = c.parent,
|
|
178
|
-
pid = parent ? parent.id : this._svgId;
|
|
179
|
-
this._compMap[id] = d3.select("#" + pid).append("g").attr("id", id);
|
|
180
|
-
} else {
|
|
181
|
-
delete this._removed[id];
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
let shapes = c.vertices.map(d => d.shape).filter(d => d !== undefined);
|
|
185
|
-
if (shapes.length === 0) {
|
|
186
|
-
this._compMap[id].style("visible", "hidden");
|
|
187
|
-
return;
|
|
188
|
-
} else {
|
|
189
|
-
this._compMap[id].style("visible", "visible");
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
let vertices = c.vertices.filter(d => d.shape !== undefined);
|
|
193
|
-
for (let v of vertices) {
|
|
194
|
-
let vid = id + "-" + v.id;
|
|
195
|
-
if (!(vid in this._compMap)) {
|
|
196
|
-
this._compMap[vid] = d3.select("#" + id).append(v.shape).attr("id", vid);
|
|
197
|
-
} else if (v.shape !== this._compMap[vid].node().tagName) {
|
|
198
|
-
this._compMap[vid].remove();
|
|
199
|
-
this._compMap[vid] = d3.select("#" + id).append(v.shape).attr("id", vid);
|
|
200
|
-
delete this._removed[vid];
|
|
201
|
-
} else {
|
|
202
|
-
delete this._removed[vid];
|
|
203
|
-
}
|
|
204
|
-
if (v.shape == "rect") {
|
|
205
|
-
d3.select("#" + vid).attr("x", v.x - v.width / 2).attr("y", v.y - v.height / 2)
|
|
206
|
-
.attr("width", v.width).attr("height", v.height);
|
|
207
|
-
} else if (v.shape == "circle") {
|
|
208
|
-
d3.select("#" + vid).attr("cx", v.x).attr("cy", v.y).attr("r", v.radius);
|
|
209
|
-
}
|
|
210
|
-
d3.select("#" + vid).style("fill", v.fillColor).style("opacity", v.opacity)
|
|
211
|
-
.style("stroke-width", v.strokeWidth).style("stroke", v.strokeColor);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
_renderLayout(c) {
|
|
216
|
-
let gridId = c.id + "-grid";
|
|
217
|
-
if (!(gridId in this._decoMap)) {
|
|
218
|
-
this._decoMap[gridId] = d3.select("#" + this._svgId).append("g")
|
|
219
|
-
.attr("id", gridId).attr("class", "deco");
|
|
220
|
-
}
|
|
221
|
-
let cellBounds = c.layout.cellBounds, rowGap = c.layout.rowGap;
|
|
222
|
-
this._decoMap[gridId].selectAll("rect").remove();
|
|
223
|
-
this._decoMap[gridId].selectAll("rect").data(cellBounds.slice(0, cellBounds.length - 1))
|
|
224
|
-
.enter().append("rect").attr("x", d => d.left).attr("y", d => d.bottom)
|
|
225
|
-
.attr("width", d => d.width).attr("height", rowGap)
|
|
226
|
-
.style("fill", "pink").style("opacity", 0.5)
|
|
227
|
-
;
|
|
228
|
-
for (let cb of cellBounds) {
|
|
229
|
-
this._decoMap[gridId].append("rect").attr("x", cb.left).attr("y", cb.top)
|
|
230
|
-
.attr("width", cb.width).attr("height", cb.height)
|
|
231
|
-
.attr("stroke", "blue").attr("stroke-width", "1px")
|
|
232
|
-
.attr("stroke-dasharray", "5,5").attr("fill", "none");
|
|
233
|
-
}
|
|
234
|
-
// let left = Math.min(...cellBounds.map(d => d.left)),
|
|
235
|
-
// top = Math.min(...cellBounds.map(d => d.top))
|
|
236
|
-
// this._decoMap[gridId].append("rect").attr("x", left).attr("y", top)
|
|
237
|
-
// .attr("width", c.bounds.width).attr("height", c.bounds.height)
|
|
238
|
-
// .attr("stroke", "blue").attr("stroke-width", "1px")
|
|
239
|
-
// .attr("stroke-dasharray", "5,5").attr("fill", "none");
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
_getTextAnchor(anchor) {
|
|
244
|
-
switch (anchor) {
|
|
245
|
-
case "top":
|
|
246
|
-
return "text-before-edge";
|
|
247
|
-
//return "hanging";
|
|
248
|
-
case "bottom":
|
|
249
|
-
//return "text-after-edge";
|
|
250
|
-
return "auto";
|
|
251
|
-
case "left":
|
|
252
|
-
return "start";
|
|
253
|
-
case "right":
|
|
254
|
-
return "end";
|
|
255
|
-
case "center":
|
|
256
|
-
return "middle";
|
|
257
|
-
case "middle":
|
|
258
|
-
return "middle";
|
|
259
|
-
default:
|
|
260
|
-
return anchor;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
_getSVGElementType(cpnt) {
|
|
265
|
-
switch (cpnt.type) {
|
|
266
|
-
case ElementType.Rect:
|
|
267
|
-
return "rect";
|
|
268
|
-
case ElementType.Collection:
|
|
269
|
-
case ElementType.Group:
|
|
270
|
-
case ElementType.Glyph:
|
|
271
|
-
case ElementType.Scene:
|
|
272
|
-
case ElementType.Axis:
|
|
273
|
-
case ElementType.Legend:
|
|
274
|
-
case ElementType.Gridlines:
|
|
275
|
-
return "g";
|
|
276
|
-
case ElementType.Area:
|
|
277
|
-
case ElementType.Path:
|
|
278
|
-
case ElementType.Polygon:
|
|
279
|
-
case ElementType.Ring:
|
|
280
|
-
case ElementType.Pie:
|
|
281
|
-
case ElementType.Arc:
|
|
282
|
-
case ElementType.Link:
|
|
283
|
-
case ElementType.Line:
|
|
284
|
-
return "path";
|
|
285
|
-
case ElementType.Circle:
|
|
286
|
-
return "circle";
|
|
287
|
-
//return "line";
|
|
288
|
-
case ElementType.PointText:
|
|
289
|
-
return "text";
|
|
290
|
-
case "vertex":
|
|
291
|
-
if (cpnt.shape == "circle")
|
|
292
|
-
return "circle";
|
|
293
|
-
else if (cpnt.shape == "rect")
|
|
294
|
-
return "rect";
|
|
295
|
-
else throw "argument exception";
|
|
296
|
-
case "image":
|
|
297
|
-
return "image";
|
|
298
|
-
default:
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
export const Style2SVG = Object.freeze({
|
|
305
|
-
"fillColor": "fill",
|
|
306
|
-
"strokeColor": "stroke",
|
|
307
|
-
"strokeWidth": "stroke-width",
|
|
308
|
-
"fillOpacity": "fill-opacity",
|
|
309
|
-
"strokeOpacity": "stroke-opacity",
|
|
310
|
-
"strokeDash": "stroke-dasharray",
|
|
311
|
-
"opacity": "opacity",
|
|
312
|
-
"fontSize": "font-size",
|
|
313
|
-
"fontFamily": "font-family",
|
|
314
|
-
"fontWeight": "font-weight",
|
|
315
|
-
"visibility": "visibility"
|
|
316
|
-
});
|
package/src-new-ts/util.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import DataScope from "../data/DataScope";
|
|
2
|
-
import { ItemType } from "../util/Constants";
|
|
3
|
-
import { getPeers } from "../util/ItemUtil";
|
|
4
|
-
|
|
5
|
-
export function classifiable(item) {
|
|
6
|
-
if (item.type !== ItemType.Collection) return false;
|
|
7
|
-
if (item.children.length < 2) return false;
|
|
8
|
-
// if (!Array.isArray(items)) return false;
|
|
9
|
-
// if (items.length < 1) return false;
|
|
10
|
-
// for (let i of items) {
|
|
11
|
-
// if (!i.dataScope)
|
|
12
|
-
// return false;
|
|
13
|
-
// }
|
|
14
|
-
// let tbls = uniqueStrings(items.map(d => d.dataScope.dataTable.name));
|
|
15
|
-
// if (tbls.length > 1) return false;
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function classifyCollectionChildren(scene, c, field, layout) {
|
|
20
|
-
let peers = getPeers(c, scene);
|
|
21
|
-
for (let p of peers) {
|
|
22
|
-
let collections = {}, cid, items = p.children;
|
|
23
|
-
for (let item of items) {
|
|
24
|
-
let v = item.dataScope.getFieldValue(field);
|
|
25
|
-
if (!(v in collections)) {
|
|
26
|
-
collections[v] = [];
|
|
27
|
-
}
|
|
28
|
-
collections[v].push(item);
|
|
29
|
-
}
|
|
30
|
-
let tbl = items[0].dataScope._dt; //results = []; //,
|
|
31
|
-
for (let v in collections) {
|
|
32
|
-
let coll = scene.collection();
|
|
33
|
-
p.addChild(coll);
|
|
34
|
-
if (cid === undefined)
|
|
35
|
-
cid = coll.id;
|
|
36
|
-
coll.classId = cid;
|
|
37
|
-
coll.dataScope = p.dataScope ? p.dataScope.cross(field, v) : new DataScope(tbl).cross(field, v);
|
|
38
|
-
for (let c of collections[v]) {
|
|
39
|
-
coll.addChild(c);
|
|
40
|
-
}
|
|
41
|
-
// if (layout)
|
|
42
|
-
// coll.layout = layout;
|
|
43
|
-
//results.push(coll);
|
|
44
|
-
}
|
|
45
|
-
// if (oldParent.children.length === 0) {
|
|
46
|
-
// oldParent.parent.removeChild(oldParent);
|
|
47
|
-
// }
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (layout)
|
|
51
|
-
scene.setProperties(c.firstChild, {layout: layout});
|
|
52
|
-
//return results;
|
|
53
|
-
}
|