Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/establishment #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 97 additions & 58 deletions src/spec/barchart.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,64 @@
{
"data": {
"url": "http://localhost:3000/spreadsheets/sales.csv",
"url": "https://narchart.github.io/editor/spreadsheets/deadstartup.csv",
"schema": [
{
"field": "Year",
"type": "temporal"
"field": "industry",
"type": "categorical"
},
{
"field": "Brand",
"field": "funded status",
"type": "categorical"
},
{
"field": "Category",
"field": "cause of failure",
"type": "categorical"
},
{
"field": "Sales",
"field": "broken year",
"type": "temporal"
},
{
"field": "survival time",
"type": "numerical"
},
{
"field": "location",
"type": "categorical"
}
]
},

"actions": [
{
"add": "config",
"mode": "light",
"emotion": "exciting"
"mode": "dark",
"emotion": "disturbing"
},
{
"select": [
{
"field": "Sales",
"aggregate": "min"
"field": "survival time",
"aggregate": "average"
},
{
"field": "location"
},
{
"field": "Brand"
"field": "funded status"
},
{
"field": "broken year"
},
{
"field": "industry"
},
{
"field": "cause of failure"
}
],
"groupby": [
{
"field": "Brand"
"field": "funded status"
}
],
"filter": []
Expand All @@ -49,88 +68,108 @@
"mark": {
"type": "bar",
"style": {
"corner-radius": 8,
"bin-spacing": 0.5,
"stroke": "#FFBE32",
"stroke-width": 3,
"stroke-opacity": 1,
"fill-opacity": 1
"bin-spacing": 0.3,
"corner-radius": 3,
"stroke-width": 1,
"stroke": "white"
}
},
"style": {
"background-image": {
"url": "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"
},
"background-color": {
"color": "gray"
}
}
},
{
"add": "title",
"text": "Dead startups in China",
"style": {
"font-color": "#FE5C34",
"font-size": 37,
"font-family": "Georgia",
"font-style": "italic",
"position": "top-left"
},
"animation": {
"duration": 1000
}
},
{
"add": "caption",
"text": "We collected data from itjuzi.com and analyzed the startups in China died between 2010 and 2019. Companies that go public have the longest mean survival time.",
"style": {
"font-color": "#FE5C34",
"font-size": 15,
"position": "top-left",
"top-padding": 5
},
"animation": {
"duration": 1000
}
},
{
"add": "group",
"actions": [
{
"add": "encoding",
"channel": "x",
"field": "Brand"
"field": "funded status"
},
{
"add": "encoding",
"channel": "y",
"field": "Sales"
}
]
},
{
"add": "annotation",
"method": "label",
"target": [
{
"field": "Brand",
"value": "Ford"
"field": "survival time"
}
],
"style": {
"font-size": 20,
"font-family": "sans-serif",
"font-color": "red",
"font-weight": 300,
"font-style": "italic"
"animation": {
"duration": 1000
}
},
{
"add": "annotation",
"method": "symbol",
"target": [
{
"field": "Brand",
"value": "Ford"
}
],
"style": {
"icon-url": "http://localhost:3000/icon/rank-1.png",
"width": 20
"method": "fade",
"target": [],
"animation": {
"duration": 1000
}
},
{
"add": "annotation",
"method": "circle",
"method": "fill",
"target": [
{
"field": "Brand",
"value": "Hyundai"
"field": "funded status",
"value": "Public"
}
],
"style": {
"width": 30,
"height": 20,
"color": "red"
"color": "#ABABAB"
},
"animation": {
"duration": 1000
}
},
{
"add": "annotation",
"method": "texture",
"method": "label",
"target": [
{
"field": "Brand",
"value": "Hyundai"
"field": "funded status",
"value": "Public"
}

],
"style": {
"background-image": "http://localhost:3000/texture/circle.png"
"text": "3409",
"font-color": "#FF4B19",
"font-size": 20,
"font-weight": "bold",
"font-style": "italic"
},
"animation": {
"duration": 1000
}
}
]
Expand Down
3 changes: 2 additions & 1 deletion src/vis/actions/addimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AddImage extends Action {
let y = 'y' in this._style ? this._style['y'] : 0;
let height = 'height' in this._style ? this._style['height'] : 100;
let width = 'width' in this._style ? this._style['width'] : 100;
let opacity = 'opacity' in this._style ? this._style['opacity'] : 1;
svg.append("svg:image")
.attr('x', x)
.attr('y', y)
Expand All @@ -38,7 +39,7 @@ class AddImage extends Action {
.attr("opacity", 0)
.transition()
.duration('duration' in this._animation ? this._animation['duration']: 0)
.attr("opacity", 1);
.attr("opacity", opacity);
}
}

Expand Down
60 changes: 48 additions & 12 deletions src/vis/charts/areachart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,64 @@ class AreaChart extends Chart {
d3.select("#svgBackGrnd").remove()
}

if (this.style()['background-color']) {
d3.select("#chartBackGrnd").attr("fill", this.style()['background-color'].color ?? "white").attr("fill-opacity", this.style()['background-color'].opacity ?? 1)
}
else if (this.style()['background-image']) {
if (this.style()['background-image'] || this.style()['background-color']) {
let defs = d3.select(container).select("svg").append('svg:defs');
defs.append("svg:pattern")
.attr("id", "chart-backgroundimage")
.attr("width", chartbackgroundsize.width)
.attr("height", margin.top === 130 * this.Hscaleratio ? 500 * this.Hscaleratio : chartbackgroundsize.height)
let pattern = defs.append("svg:pattern")
.attr("id", "chart-backgroundimage")
.attr("width", chartbackgroundsize.width)
.attr("height", margin.top === 130 * this.Hscaleratio ? 500 * this.Hscaleratio : chartbackgroundsize.height)
.attr("patternUnits", "userSpaceOnUse")
.append("svg:image")

if (this.style()['background-color']) {
pattern.append("svg:rect")
.attr("width",chartbackgroundsize.width)
.attr("height",margin.top === 130 * this.Hscaleratio ? 500 * this.Hscaleratio : chartbackgroundsize.height)
.attr("fill", this.style()['background-color'].color ?? "white")
.attr("fill-opacity", this.style()['background-color'].opacity ?? 1)
}

if (this.style()['background-image']) {
let preserveAspectRatio = "xMidYMid slice"
if (this.style()["background-image"].fit) {
switch (this.style()["background-image"].fit) {
case "fitMid":
preserveAspectRatio = "xMidYMid slice"
break;
case "fitLeft":
preserveAspectRatio = "xMinYMin slice"
break;
case "fitRight":
preserveAspectRatio = "xMaxYMax slice"
break;
case "fitUp":
preserveAspectRatio = "xMinYMin slice"
break;
case "fitDown":
preserveAspectRatio = "xMaxYMax slice"
break;
case "origin":
preserveAspectRatio = "xMidYMid meet"
break;
case "stretch":
preserveAspectRatio = "none"
break;
default:
break
}
}
pattern.append("svg:image")
.attr("xlink:href", this.style()["background-image"].url)
.attr("preserveAspectRatio", "xMidYMid slice")
.attr("preserveAspectRatio", preserveAspectRatio)
.attr("opacity", this.style()["background-image"].opacity ?? 1)
.attr("filter", this.style()["background-image"].grayscale ? "grayscale(" + this.style()["background-image"].grayscale + "%)" : "grayscale(0%)")
.attr("width", chartbackgroundsize.width)
.attr("height", margin.top === 130 * this.Hscaleratio ? 500 * this.Hscaleratio : chartbackgroundsize.height)
.attr("x", 0)
.attr("y", 0);
}

d3.select("#chartBackGrnd").attr("fill", "url(#chart-backgroundimage)")
}
else {
} else {
d3.select("#chartBackGrnd").attr("fill-opacity", 0)
}

Expand Down
Loading