Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
01363576
Commit
01363576
authored
Nov 23, 2014
by
Mathieu Rodic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TEST] reached a functionnal level with "dygraph"
parent
b8c46253
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
114 additions
and
62 deletions
+114
-62
graph-it.js
static/js/graph-it.js
+113
-60
graph-it.html
templates/graph-it.html
+1
-2
No files found.
static/js/graph-it.js
View file @
01363576
...
...
@@ -7,7 +7,7 @@
var
container2
=
$
(
'<div>'
).
addClass
(
'graphit-container-2'
).
appendTo
(
this
.
first
()
);
var
data
;
var
method
;
var
dcChart
,
dcVolumeChar
t
;
var
_chartObjec
t
;
var
width
,
height
;
...
...
@@ -33,17 +33,12 @@
container
.
css
(
'background'
,
'#FFF'
);
// http://dygraphs.com/tutorial.html
// http://dygraphs.com/data.html
// http://dygraphs.com/tests/callback.html
// http://dygraphs.com/legal.html
var
corpusId
=
13410
;
var
series
=
[];
var
keywordsList
=
[
'bee,bees'
,
'brain,virus'
];
var
dimensions
;
// create the series for future plotting
// generate data
for
(
var
i
=
0
;
i
<
keywordsList
.
length
;
i
++
)
{
keywords
=
keywordsList
[
i
];
// get data from server
...
...
@@ -59,25 +54,6 @@
},
});
dimensions
=
data
.
dimensions
;
// format all data
for
(
var
j
=
0
;
j
<
data
.
dimensions
.
length
;
j
++
)
{
var
dimension
=
data
.
dimensions
[
j
];
var
key
=
dimension
.
key
;
var
n
=
data
.
collection
.
length
;
for
(
k
=
0
;
k
<
n
;
k
++
)
{
var
value
=
data
.
list
[
k
][
j
];
switch
(
dimension
.
type
)
{
case
'datetime'
:
value
=
Date
(
value
.
replace
(
' '
,
'T'
));
break
;
case
'numeric'
:
value
=
+
value
;
break
;
}
data
.
list
[
k
][
j
]
=
value
;
data
.
collection
[
k
][
key
]
=
value
;
}
}
// add to the series
series
.
push
({
name
:
keywords
,
...
...
@@ -85,43 +61,120 @@
});
}
// debugging only
dbg
=
series
;
console
.
log
(
series
);
container
.
highcharts
({
chart
:
{
type
:
'spline'
},
title
:
{
text
:
'Evolution of documents count over time'
// different types of grouping
var
groupings
=
{
datetime
:
{
century
:
{
truncate
:
function
(
x
)
{
return
x
.
substr
(
0
,
2
)},
next
:
function
(
x
)
{
x
=
new
Date
(
x
);
x
.
setFullYear
(
x
.
getFullYear
()
+
100
);
return
x
;},
},
subtitle
:
{
text
:
'the results are filtered by ngrams'
decade
:
{
truncate
:
function
(
x
)
{
return
x
.
substr
(
0
,
3
)},
next
:
function
(
x
)
{
x
=
new
Date
(
x
);
x
.
setFullYear
(
x
.
getFullYear
()
+
10
);
return
x
;},
},
xAxis
:
{
type
:
dimensions
[
0
].
type
,
// dateTimeLabelFormats: { // don't display the dummy year
// month: '%e. %b',
// year: '%b'
// },
title
:
{
text
:
'Date'
}
year
:
{
truncate
:
function
(
x
)
{
return
x
.
substr
(
0
,
4
)},
next
:
function
(
x
)
{
x
=
new
Date
(
x
);
x
.
setFullYear
(
x
.
getFullYear
()
+
1
);
return
x
;},
},
yAxis
:
{
title
:
{
text
:
'Documents count'
month
:
{
truncate
:
function
(
x
)
{
return
x
.
substr
(
0
,
7
)},
next
:
function
(
x
)
{
x
=
new
Date
(
x
);
x
.
setMonth
(
x
.
getMonth
()
+
1
);
return
x
;},
},
min
:
0
day
:
{
truncate
:
function
(
x
)
{
return
x
.
substr
(
0
,
10
)},
next
:
function
(
x
)
{
x
=
new
Date
(
x
);
x
.
setDate
(
x
.
getDate
()
+
1
);
return
x
;},
},
tooltip
:
{
headerFormat
:
'<b>{series.name}</b><br>'
,
pointFormat
:
'{point.x:%e. %b}: {point.y:%d} m'
},
series
:
series
};
var
grouping
=
groupings
.
datetime
.
year
;
// generate associative data
var
associativeData
=
{};
for
(
var
s
=
0
;
s
<
series
.
length
;
s
++
)
{
var
data
=
series
[
s
].
data
;
for
(
var
d
=
0
;
d
<
data
.
length
;
d
++
)
{
var
row
=
data
[
d
];
var
x
=
grouping
.
truncate
(
row
[
0
]);
var
y
=
row
[
1
];
if
(
!
associativeData
[
x
])
{
associativeData
[
x
]
=
new
Array
(
series
.
length
);
for
(
var
i
=
0
;
i
<
series
.
length
;
i
++
)
{
associativeData
[
x
][
i
]
=
0
;
}
}
associativeData
[
x
][
s
]
+=
y
;
}
};
// now, flatten this
var
linearData
=
[];
for
(
var
x
in
associativeData
)
{
var
row
=
associativeData
[
x
];
row
.
unshift
(
x
);
linearData
.
push
(
row
);
}
// extrema retrieval & scalar data formatting
for
(
var
d
=
0
;
d
<
dimensions
.
length
;
d
++
)
{
dimensions
[
d
].
extrema
=
{};
}
var
keys
=
{};
for
(
var
r
=
0
;
r
<
linearData
.
length
;
r
++
)
{
var
row
=
linearData
[
r
];
for
(
var
d
=
0
;
d
<
dimensions
.
length
;
d
++
)
{
var
value
=
row
[
d
];
var
dimension
=
dimensions
[
d
];
switch
(
dimension
.
type
)
{
case
'datetime'
:
value
+=
'2000-01-01 00:00:00'
.
substr
(
value
.
length
);
value
=
new
Date
(
value
.
replace
(
' '
,
'T'
)
+
'.000Z'
);
break
;
case
'numeric'
:
value
=
+
value
;
break
;
}
if
(
dimension
.
extrema
.
min
==
undefined
||
value
<
dimension
.
extrema
.
min
)
{
dimension
.
extrema
.
min
=
value
;
}
if
(
dimension
.
extrema
.
max
==
undefined
||
value
>
dimension
.
extrema
.
max
)
{
dimension
.
extrema
.
max
=
value
;
}
row
[
d
]
=
value
;
}
keys
[
row
[
0
]]
=
true
;
}
// interpolation
var
xMin
=
dimensions
[
0
].
extrema
.
min
;
var
xMax
=
dimensions
[
0
].
extrema
.
max
;
for
(
var
x
=
xMin
;
x
<
xMax
;
x
=
grouping
.
next
(
x
))
{
if
(
!
keys
[
x
])
{
// TODO: this below is just WRONG
var
row
=
[
x
,
0
,
0
];
linearData
.
push
(
row
);
}
}
linearData
.
sort
(
function
(
row1
,
row2
)
{
return
row1
[
0
]
>
row2
[
0
];
});
// do the graph!
var
labels
=
[
dimensions
[
0
].
key
];
for
(
var
k
=
0
;
k
<
keywordsList
.
length
;
k
++
)
{
labels
.
push
(
dimensions
[
1
].
key
+
' ('
+
keywordsList
[
k
]
+
')'
);
}
// var _chartObject = new Dygraph(container[0], linearData);
var
_chartObject
=
new
Dygraph
(
container
[
0
],
linearData
,
{
labels
:
labels
,
});
// console.log(associativeData);
console
.
log
(
linearData
);
console
.
log
(
dimensions
);
return
container
;
};
...
...
templates/graph-it.html
View file @
01363576
...
...
@@ -21,8 +21,7 @@
<script
type=
"text/javascript"
src=
"{% static "
js
/
jquery
/
jquery
.
min
.
js
"
%}"
></script>
<script
src=
"http://code.highcharts.com/highcharts.js"
></script>
<script
src=
"http://code.highcharts.com/modules/exporting.js"
></script>
<script
type=
"text/javascript"
src=
"http://dygraphs.com/dygraph-combined.js"
></script>
<script
type=
"text/javascript"
src=
"{% static "
js
/
graph-it
.
js
"
%}"
></script>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment